Squid Web Cache master
Loading...
Searching...
No Matches
MemObject.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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
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
28typedef void STMCB (void *data, StoreIOBuffer wroteBuffer);
29
30class store_client;
31class PeerSelector;
32
34{
36
37public:
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
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
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
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
159 {
160 public:
161 int64_t queue_offset = 0;
163
165 typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision;
167 };
168
170
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;
187 }
188
189 int32_t index = -1;
191 };
193
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
226private:
229
230 mutable SBuf storeId_;
231 mutable SBuf logUri_;
232
234};
235
238
239#endif /* SQUID_SRC_MEMOBJECT_H */
240
RemovalPolicy * mem_policy
Definition MemObject.cc:44
void STMCB(void *data, StoreIOBuffer wroteBuffer)
Definition MemObject.h:28
State of an entry with regards to the [shared] memory caching.
Definition MemObject.h:196
int32_t index
entry position inside the memory cache
Definition MemObject.h:198
Store::IoStatus io
current I/O state
Definition MemObject.h:201
int64_t offset
bytes written/read to/from the memory cache so far
Definition MemObject.h:199
int64_t queue_offset
number of bytes sent to SwapDir for writing
Definition MemObject.h:161
Decision decision
current decision state
Definition MemObject.h:166
StoreIOState::Pointer sio
Definition MemObject.h:162
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition MemObject.h:165
State of an entry with regards to the [shared] in-transit table.
Definition MemObject.h:173
void close()
stop associating our StoreEntry with a Transients entry
Definition MemObject.h:183
int32_t index
entry position inside the in-transit table
Definition MemObject.h:189
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
Store::IoStatus io
current I/O state
Definition MemObject.h:190
void replaceBaseReply(const HttpReplyPointer &r)
Definition MemObject.cc:128
bool appliedUpdates
Definition MemObject.h:90
RemovalPolicyNode repl
Definition MemObject.h:213
int64_t lowestMemReaderOffset() const
Definition MemObject.cc:277
DelayId mostBytesAllowed() const
Definition MemObject.cc:466
SBuf logUri_
URI used for logging (usually request URI)
Definition MemObject.h:231
IRCB * ping_reply_callback
Definition MemObject.h:208
int64_t size() const
Definition MemObject.cc:229
size_t clientCount() const
Definition MemObject.h:152
const char * urlXXX() const
Definition MemObject.h:138
int nclients
Definition MemObject.h:156
static size_t inUseCount()
Definition MemObject.cc:47
SwapOut swapout
Definition MemObject.h:169
HttpRequestMethod method
Definition MemObject.h:147
int64_t availableForSwapOut() const
buffered bytes we have not swapped out yet
Definition MemObject.cc:489
HttpRequestPointer request
Definition MemObject.h:205
void trimSwappable()
Definition MemObject.cc:371
int64_t policyLowestOffsetToKeep(bool swap) const
Definition MemObject.cc:348
int64_t objectBytesOnDisk() const
Definition MemObject.cc:322
HttpReplyPointer reply_
Definition MemObject.h:227
void setNoDelay(bool const newValue)
Definition MemObject.cc:431
void reset()
Definition MemObject.cc:264
void trimUnSwappable()
Definition MemObject.cc:396
void addClient(store_client *)
Definition MemObject.cc:303
XitTable xitTable
current [shared] memory caching state for the entry
Definition MemObject.h:192
int64_t expectedReplySize() const
Definition MemObject.cc:238
SBuf vary_headers
Definition MemObject.h:221
dlink_list clients
Definition MemObject.h:150
const HttpReplyPointer & updatedReply() const
Definition MemObject.h:64
mem_hdr data_hdr
Definition MemObject.h:148
AsyncCallPointer abortCallback
used for notifying StoreEntry writers about 3rd-party initiated aborts
Definition MemObject.h:212
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition MemObject.h:85
void dump() const
Definition MemObject.cc:149
const HttpReply & freshestReply() const
Definition MemObject.h:68
struct timeval start_ping
Definition MemObject.h:207
void markEndOfReplyHeaders()
sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset()
Definition MemObject.cc:220
bool clientIsFirst(void *sc) const
Definition MemObject.h:154
MEMPROXY_CLASS(MemObject)
SBuf storeId_
StoreId for our entry (usually request URI)
Definition MemObject.h:230
void delayRead(const AsyncCallPointer &)
Definition MemObject.cc:445
void write(const StoreIOBuffer &buf)
Definition MemObject.cc:136
int64_t inmem_lo
Definition MemObject.h:149
size_t swap_hdr_sz
Definition MemObject.h:216
int mostBytesWanted(int max, bool ignoreDelayPools) const
Definition MemObject.cc:415
MemCache memCache
current [shared] memory caching state for the entry
Definition MemObject.h:203
int64_t endOffset() const
Definition MemObject.cc:214
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition MemObject.cc:76
const char * storeId() const
Definition MemObject.cc:53
const HttpReply & baseReply() const
Definition MemObject.h:60
HttpReply & adjustableBaseReply()
Definition MemObject.cc:121
void unlinkRequest()
Definition MemObject.h:56
bool hasUris() const
whether setUris() has been called
Definition MemObject.cc:70
const char * logUri() const
client request URI used for logging; storeId() by default
Definition MemObject.cc:64
DelayedAsyncCalls deferredReads
Definition MemObject.h:233
HttpReplyPointer updatedReply_
Definition MemObject.h:228
void kickReads()
Definition MemObject.cc:459
PeerSelector * ircb_data
Definition MemObject.h:209
bool readAheadPolicyCanRead() const
Definition MemObject.cc:288
bool isContiguous() const
Definition MemObject.cc:406
void stat(MemBuf *mb) const
Definition MemObject.cc:189
int64_t object_sz
Definition MemObject.h:215
Definition SBuf.h:94
A const & max(A const &lhs, A const &rhs)
IoStatus
cache "I/O" direction and status
Definition forward.h:40
@ ioUndecided
Definition forward.h:40
@ ioDone
Definition forward.h:40
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition typedefs.h:22