MemObject.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_MEMOBJECT_H
10 #define SQUID_MEMOBJECT_H
11 
12 #include "CommRead.h"
13 #include "dlink.h"
14 #include "http/RequestMethod.h"
15 #include "RemovalPolicy.h"
16 #include "SquidString.h"
17 #include "stmem.h"
18 #include "store/forward.h"
19 #include "StoreIOBuffer.h"
20 #include "StoreIOState.h"
21 #include "typedefs.h" //for IRCB
22 
23 #if USE_DELAY_POOLS
24 #include "DelayId.h"
25 #endif
26 
27 typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
28 
29 class store_client;
30 class PeerSelector;
31 
32 class MemObject
33 {
35 
36 public:
37  static size_t inUseCount();
38 
39  void dump() const;
40  MemObject();
41  ~MemObject();
42 
49  void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
50 
52  bool hasUris() const;
53 
54  void write(const StoreIOBuffer &buf);
55  void unlinkRequest() { request = nullptr; }
56 
59  const HttpReply &baseReply() const { return *reply_; }
60 
63  const HttpReplyPointer &updatedReply() const { return updatedReply_; }
64 
67  const HttpReply &freshestReply() const {
68  if (updatedReply_)
69  return *updatedReply_;
70  else
71  return baseReply();
72  }
73 
78 
81  void replaceBaseReply(const HttpReplyPointer &r);
82 
84  void updateReply(const HttpReply &r) { updatedReply_ = &r; }
85 
89  bool appliedUpdates = false;
90 
91  void stat (MemBuf * mb) const;
92  int64_t endOffset () const;
93 
95  void markEndOfReplyHeaders();
96 
99  int64_t expectedReplySize() const;
100  int64_t size() const;
101  void reset();
102  int64_t lowestMemReaderOffset() const;
103  bool readAheadPolicyCanRead() const;
104  void addClient(store_client *);
105  /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
106  * better
107  */
108  int64_t objectBytesOnDisk() const;
109  int64_t policyLowestOffsetToKeep(bool swap) const;
110  int64_t availableForSwapOut() const;
111  void trimSwappable();
112  void trimUnSwappable();
113  bool isContiguous() const;
114  int mostBytesWanted(int max, bool ignoreDelayPools) const;
115  void setNoDelay(bool const newValue);
116 #if USE_DELAY_POOLS
117  DelayId mostBytesAllowed() const;
118 #endif
119 
120 #if URL_CHECKSUM_DEBUG
121 
122  void checkUrlChecksum() const;
123 #endif
124 
128  const char *urlXXX() const { return storeId(); }
129 
132  const char *storeId() const;
133 
135  const char *logUri() const;
136 
139  int64_t inmem_lo = 0;
141 
142  size_t clientCount() const {return nclients;}
143 
144  bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
145 
146  int nclients = 0;
147 
148  class SwapOut
149  {
150  public:
151  int64_t queue_offset = 0;
153 
155  typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
157  };
158 
160 
161  /* TODO: Remove this change-minimizing hack */
163  static constexpr Io ioUndecided = Store::ioUndecided;
164  static constexpr Io ioReading = Store::ioReading;
165  static constexpr Io ioWriting = Store::ioWriting;
166  static constexpr Io ioDone = Store::ioDone;
167 
169  class XitTable
170  {
171  public:
172  int32_t index = -1;
174  };
176 
178  class MemCache
179  {
180  public:
181  int32_t index = -1;
182  int64_t offset = 0;
183 
185  };
187 
189 
190  struct timeval start_ping;
193 
197  int id = 0;
198  int64_t object_sz = -1;
199  size_t swap_hdr_sz = 0;
200 #if URL_CHECKSUM_DEBUG
201  unsigned int chksum = 0;
202 #endif
203 
205 
206  void delayRead(DeferredRead const &);
207  void kickReads();
208 
209 private:
212 
213  mutable String storeId_;
214  mutable String logUri_;
215 
217 };
218 
220 extern RemovalPolicy *mem_policy;
221 
222 #endif /* SQUID_MEMOBJECT_H */
223 
int64_t queue_offset
number of bytes sent to SwapDir for writing
Definition: MemObject.h:151
HttpReply & adjustableBaseReply()
Definition: MemObject.cc:127
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:296
IoStatus
cache "I/O" direction and status
Definition: forward.h:40
const char * storeId() const
Definition: MemObject.cc:54
String storeId_
StoreId for our entry (usually request URI)
Definition: MemObject.h:213
mem_hdr data_hdr
Definition: MemObject.h:138
int mostBytesWanted(int max, bool ignoreDelayPools) const
Definition: MemObject.cc:417
void trimUnSwappable()
Definition: MemObject.cc:398
struct timeval start_ping
Definition: MemObject.h:190
DeferredReadManager deferredReads
Definition: MemObject.h:216
int64_t offset
bytes written/read to/from the memory cache so far
Definition: MemObject.h:182
State of an entry with regards to the [shared] in-transit table.
Definition: MemObject.h:170
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:186
Definition: SBuf.h:87
StoreIOState::Pointer sio
Definition: MemObject.h:152
void setNoDelay(bool const newValue)
Definition: MemObject.cc:431
Io io
current I/O state
Definition: MemObject.h:173
int64_t expectedReplySize() const
Definition: MemObject.cc:246
DelayId mostBytesAllowed() const
Definition: MemObject.cc:465
bool isContiguous() const
Definition: MemObject.cc:408
static constexpr Io ioUndecided
Definition: MemObject.h:163
Io io
current I/O state
Definition: MemObject.h:184
int64_t endOffset() const
Definition: MemObject.cc:222
int64_t availableForSwapOut() const
buffered bytes we have not swapped out yet
Definition: MemObject.cc:488
bool clientIsFirst(void *sc) const
Definition: MemObject.h:144
int64_t inmem_lo
Definition: MemObject.h:139
A const & max(A const &lhs, A const &rhs)
RemovalPolicy * mem_policy
Definition: MemObject.cc:45
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition: typedefs.h:22
void replaceBaseReply(const HttpReplyPointer &r)
Definition: MemObject.cc:134
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:65
HttpReplyPointer reply_
Definition: MemObject.h:210
Decision decision
current decision state
Definition: MemObject.h:156
PeerSelector * ircb_data
Definition: MemObject.h:192
SBuf vary_headers
Definition: MemObject.h:204
const HttpReply & baseReply() const
Definition: MemObject.h:59
void STMCB(void *data, StoreIOBuffer wroteBuffer)
Definition: MemObject.h:27
Definition: MemBuf.h:24
int64_t policyLowestOffsetToKeep(bool swap) const
Definition: MemObject.cc:356
int32_t index
entry position inside the in-transit table
Definition: MemObject.h:172
void write(const StoreIOBuffer &buf)
Definition: MemObject.cc:142
@ ioDone
Definition: forward.h:40
void const char HLPCB void * data
Definition: stub_helper.cc:16
XitTable xitTable
current [shared] memory caching state for the entry
Definition: MemObject.h:175
Definition: stmem.h:20
HttpRequestMethod method
Definition: MemObject.h:137
void dump() const
Definition: MemObject.cc:157
int64_t size() const
Definition: MemObject.cc:237
static size_t inUseCount()
Definition: MemObject.cc:48
static int sc[16]
Definition: smbdes.c:121
String logUri_
URI used for logging (usually request URI)
Definition: MemObject.h:214
static constexpr Io ioDone
Definition: MemObject.h:166
bool appliedUpdates
Definition: MemObject.h:89
void markEndOfReplyHeaders()
sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset()
Definition: MemObject.cc:228
int32_t index
entry position inside the memory cache
Definition: MemObject.h:181
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition: MemObject.h:155
void delayRead(DeferredRead const &)
Definition: MemObject.cc:444
#define MEMPROXY_CLASS(CLASS)
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:71
@ ioUndecided
Definition: forward.h:40
int64_t object_sz
Definition: MemObject.h:198
State of an entry with regards to the [shared] memory caching.
Definition: MemObject.h:179
void trimSwappable()
Definition: MemObject.cc:373
void unlinkRequest()
Definition: MemObject.h:55
size_t clientCount() const
Definition: MemObject.h:142
void addClient(store_client *)
Definition: MemObject.cc:311
HttpReplyPointer updatedReply_
Definition: MemObject.h:211
const HttpReply & freshestReply() const
Definition: MemObject.h:67
void kickReads()
Definition: MemObject.cc:458
static constexpr Io ioReading
Definition: MemObject.h:164
int64_t lowestMemReaderOffset() const
Definition: MemObject.cc:285
const char * urlXXX() const
Definition: MemObject.h:128
@ ioWriting
Definition: forward.h:40
IRCB * ping_reply_callback
Definition: MemObject.h:191
RemovalPolicyNode repl
Definition: MemObject.h:196
static constexpr Io ioWriting
Definition: MemObject.h:165
AsyncCall::Pointer abortCallback
used for notifying StoreEntry writers about 3rd-party initiated aborts
Definition: MemObject.h:195
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition: MemObject.h:84
void reset()
Definition: MemObject.cc:272
int64_t objectBytesOnDisk() const
Definition: MemObject.cc:330
@ ioReading
Definition: forward.h:40
void stat(MemBuf *mb) const
Definition: MemObject.cc:197
const HttpReplyPointer & updatedReply() const
Definition: MemObject.h:63
HttpRequestPointer request
Definition: MemObject.h:188
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition: MemObject.cc:77
size_t swap_hdr_sz
Definition: MemObject.h:199
int nclients
Definition: MemObject.h:146
void const char * buf
Definition: stub_helper.cc:16
dlink_list clients
Definition: MemObject.h:140
SwapOut swapout
Definition: MemObject.h:159

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors