MemObject.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_MEMOBJECT_H
10 #define SQUID_SRC_MEMOBJECT_H
11 
12 #include "base/DelayedAsyncCalls.h"
13 #include "dlink.h"
14 #include "http/RequestMethod.h"
15 #include "HttpReply.h"
16 #include "RemovalPolicy.h"
17 #include "sbuf/SBuf.h"
18 #include "stmem.h"
19 #include "store/forward.h"
20 #include "StoreIOBuffer.h"
21 #include "StoreIOState.h"
22 #include "typedefs.h" //for IRCB
23 
24 #if USE_DELAY_POOLS
25 #include "DelayId.h"
26 #endif
27 
28 typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
29 
30 class store_client;
31 class PeerSelector;
32 
33 class MemObject
34 {
36 
37 public:
38  static size_t inUseCount();
39 
40  void dump() const;
41  MemObject();
42  ~MemObject();
43 
50  void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod);
51 
53  bool hasUris() const;
54 
55  void write(const StoreIOBuffer &buf);
56  void unlinkRequest() { request = nullptr; }
57 
60  const HttpReply &baseReply() const { return *reply_; }
61 
64  const HttpReplyPointer &updatedReply() const { return updatedReply_; }
65 
68  const HttpReply &freshestReply() const {
69  if (updatedReply_)
70  return *updatedReply_;
71  else
72  return baseReply();
73  }
74 
79 
82  void replaceBaseReply(const HttpReplyPointer &r);
83 
85  void updateReply(const HttpReply &r) { updatedReply_ = &r; }
86 
90  bool appliedUpdates = false;
91 
92  void stat (MemBuf * mb) const;
93 
102  int64_t endOffset () const;
103 
105  void markEndOfReplyHeaders();
106 
109  int64_t expectedReplySize() const;
110  int64_t size() const;
111  void reset();
112  int64_t lowestMemReaderOffset() const;
113  bool readAheadPolicyCanRead() const;
114  void addClient(store_client *);
115  /* XXX belongs in MemObject::swapout, once swaphdrsz is managed
116  * better
117  */
118  int64_t objectBytesOnDisk() const;
119  int64_t policyLowestOffsetToKeep(bool swap) const;
120  int64_t availableForSwapOut() const;
121  void trimSwappable();
122  void trimUnSwappable();
123  bool isContiguous() const;
124  int mostBytesWanted(int max, bool ignoreDelayPools) const;
125  void setNoDelay(bool const newValue);
126 #if USE_DELAY_POOLS
127  DelayId mostBytesAllowed() const;
128 #endif
129 
130 #if URL_CHECKSUM_DEBUG
131 
132  void checkUrlChecksum() const;
133 #endif
134 
138  const char *urlXXX() const { return storeId(); }
139 
142  const char *storeId() const;
143 
145  const char *logUri() const;
146 
149  int64_t inmem_lo = 0;
151 
152  size_t clientCount() const {return nclients;}
153 
154  bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);}
155 
156  int nclients = 0;
157 
158  class SwapOut
159  {
160  public:
161  int64_t queue_offset = 0;
163 
165  typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
167  };
168 
170 
172  class XitTable
173  {
174  public:
176  void open(const int32_t anIndex, const Store::IoStatus anIo)
177  {
178  index = anIndex;
179  io = anIo;
180  }
181 
183  void close()
184  {
185  index = -1;
186  io = Store::ioDone;
187  }
188 
189  int32_t index = -1;
191  };
193 
195  class MemCache
196  {
197  public:
198  int32_t index = -1;
199  int64_t offset = 0;
200 
202  };
204 
206 
207  struct timeval start_ping;
210 
214  int id = 0;
215  int64_t object_sz = -1;
216  size_t swap_hdr_sz = 0;
217 #if URL_CHECKSUM_DEBUG
218  unsigned int chksum = 0;
219 #endif
220 
222 
223  void delayRead(const AsyncCallPointer &);
224  void kickReads();
225 
226 private:
229 
230  mutable SBuf storeId_;
231  mutable SBuf logUri_;
232 
234 };
235 
237 extern RemovalPolicy *mem_policy;
238 
239 #endif /* SQUID_SRC_MEMOBJECT_H */
240 
int64_t queue_offset
number of bytes sent to SwapDir for writing
Definition: MemObject.h:161
Store::IoStatus io
current I/O state
Definition: MemObject.h:190
HttpReply & adjustableBaseReply()
Definition: MemObject.cc:121
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:288
IoStatus
cache "I/O" direction and status
Definition: forward.h:40
const char * storeId() const
Definition: MemObject.cc:53
mem_hdr data_hdr
Definition: MemObject.h:148
int mostBytesWanted(int max, bool ignoreDelayPools) const
Definition: MemObject.cc:415
void trimUnSwappable()
Definition: MemObject.cc:396
struct timeval start_ping
Definition: MemObject.h:207
DelayedAsyncCalls deferredReads
Definition: MemObject.h:233
int64_t offset
bytes written/read to/from the memory cache so far
Definition: MemObject.h:199
State of an entry with regards to the [shared] in-transit table.
Definition: MemObject.h:172
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:203
Definition: SBuf.h:93
StoreIOState::Pointer sio
Definition: MemObject.h:162
void setNoDelay(bool const newValue)
Definition: MemObject.cc:431
int64_t expectedReplySize() const
Definition: MemObject.cc:238
DelayId mostBytesAllowed() const
Definition: MemObject.cc:466
bool isContiguous() const
Definition: MemObject.cc:406
const A & max(A const &lhs, A const &rhs)
MEMPROXY_CLASS(MemObject)
int64_t endOffset() const
Definition: MemObject.cc:214
int64_t availableForSwapOut() const
buffered bytes we have not swapped out yet
Definition: MemObject.cc:489
bool clientIsFirst(void *sc) const
Definition: MemObject.h:154
int64_t inmem_lo
Definition: MemObject.h:149
RemovalPolicy * mem_policy
Definition: MemObject.cc:44
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition: typedefs.h:22
void replaceBaseReply(const HttpReplyPointer &r)
Definition: MemObject.cc:128
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:64
HttpReplyPointer reply_
Definition: MemObject.h:227
Decision decision
current decision state
Definition: MemObject.h:166
PeerSelector * ircb_data
Definition: MemObject.h:209
SBuf vary_headers
Definition: MemObject.h:221
const HttpReply & baseReply() const
Definition: MemObject.h:60
SBuf storeId_
StoreId for our entry (usually request URI)
Definition: MemObject.h:230
void STMCB(void *data, StoreIOBuffer wroteBuffer)
Definition: MemObject.h:28
Definition: MemBuf.h:23
int64_t policyLowestOffsetToKeep(bool swap) const
Definition: MemObject.cc:348
AsyncCallPointer abortCallback
used for notifying StoreEntry writers about 3rd-party initiated aborts
Definition: MemObject.h:212
int32_t index
entry position inside the in-transit table
Definition: MemObject.h:189
void write(const StoreIOBuffer &buf)
Definition: MemObject.cc:136
@ ioDone
Definition: forward.h:40
XitTable xitTable
current [shared] memory caching state for the entry
Definition: MemObject.h:192
Definition: stmem.h:19
HttpRequestMethod method
Definition: MemObject.h:147
void dump() const
Definition: MemObject.cc:149
void close()
stop associating our StoreEntry with a Transients entry
Definition: MemObject.h:183
SBuf logUri_
URI used for logging (usually request URI)
Definition: MemObject.h:231
Store::IoStatus io
current I/O state
Definition: MemObject.h:201
int64_t size() const
Definition: MemObject.cc:229
static size_t inUseCount()
Definition: MemObject.cc:47
static int sc[16]
Definition: smbdes.c:121
void delayRead(const AsyncCallPointer &)
Definition: MemObject.cc:445
bool appliedUpdates
Definition: MemObject.h:90
void markEndOfReplyHeaders()
sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset()
Definition: MemObject.cc:220
int32_t index
entry position inside the memory cache
Definition: MemObject.h:198
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition: MemObject.h:165
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:70
@ ioUndecided
Definition: forward.h:40
int64_t object_sz
Definition: MemObject.h:215
State of an entry with regards to the [shared] memory caching.
Definition: MemObject.h:195
void trimSwappable()
Definition: MemObject.cc:371
void unlinkRequest()
Definition: MemObject.h:56
size_t clientCount() const
Definition: MemObject.h:152
void addClient(store_client *)
Definition: MemObject.cc:303
HttpReplyPointer updatedReply_
Definition: MemObject.h:228
const HttpReply & freshestReply() const
Definition: MemObject.h:68
void open(const int32_t anIndex, const Store::IoStatus anIo)
associate our StoreEntry with a Transients entry at the given index
Definition: MemObject.h:176
void kickReads()
Definition: MemObject.cc:459
int64_t lowestMemReaderOffset() const
Definition: MemObject.cc:277
const char * urlXXX() const
Definition: MemObject.h:138
IRCB * ping_reply_callback
Definition: MemObject.h:208
RemovalPolicyNode repl
Definition: MemObject.h:213
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition: MemObject.h:85
void reset()
Definition: MemObject.cc:264
int64_t objectBytesOnDisk() const
Definition: MemObject.cc:322
void stat(MemBuf *mb) const
Definition: MemObject.cc:189
const HttpReplyPointer & updatedReply() const
Definition: MemObject.h:64
HttpRequestPointer request
Definition: MemObject.h:205
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition: MemObject.cc:76
size_t swap_hdr_sz
Definition: MemObject.h:216
int nclients
Definition: MemObject.h:156
dlink_list clients
Definition: MemObject.h:150
SwapOut swapout
Definition: MemObject.h:169

 

Introduction

Documentation

Support

Miscellaneous