]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
528b2c61 | 3 | * |
bbc27441 AJ |
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. | |
528b2c61 | 7 | */ |
8 | ||
9 | #ifndef SQUID_MEMOBJECT_H | |
10 | #define SQUID_MEMOBJECT_H | |
11 | ||
a928fdfd | 12 | #include "base/DelayedAsyncCalls.h" |
c6983ec7 | 13 | #include "dlink.h" |
f35c0145 | 14 | #include "http/RequestMethod.h" |
c6983ec7 | 15 | #include "RemovalPolicy.h" |
0d1c9fe8 | 16 | #include "SquidString.h" |
c6983ec7 | 17 | #include "stmem.h" |
4310f8b0 | 18 | #include "store/forward.h" |
c6983ec7 FC |
19 | #include "StoreIOBuffer.h" |
20 | #include "StoreIOState.h" | |
e1ba42a4 | 21 | #include "typedefs.h" //for IRCB |
528b2c61 | 22 | |
43ca19e0 FC |
23 | #if USE_DELAY_POOLS |
24 | #include "DelayId.h" | |
25 | #endif | |
26 | ||
528b2c61 | 27 | typedef void STMCB (void *data, StoreIOBuffer wroteBuffer); |
28 | ||
29 | class store_client; | |
cb365059 | 30 | class PeerSelector; |
528b2c61 | 31 | |
62e76326 | 32 | class MemObject |
33 | { | |
741c2986 | 34 | MEMPROXY_CLASS(MemObject); |
62e76326 | 35 | |
528b2c61 | 36 | public: |
37 | static size_t inUseCount(); | |
62e76326 | 38 | |
528b2c61 | 39 | void dump() const; |
c877c0bc | 40 | MemObject(); |
528b2c61 | 41 | ~MemObject(); |
42 | ||
76d61119 EB |
43 | /// Sets store ID, log URI, and request method (unless already set). Does |
44 | /// not clobber the method so that, say, a HEAD hit for a GET entry keeps | |
45 | /// the GET method that matches the entry key. Same for the other parts of | |
46 | /// the trio because the entry filling code may expect them to be constant. | |
47 | /// XXX: Avoid this method. We plan to remove it and make the trio constant | |
48 | /// after addressing the XXX in MemStore::get(). | |
c877c0bc | 49 | void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod); |
9487bae9 | 50 | |
c877c0bc AR |
51 | /// whether setUris() has been called |
52 | bool hasUris() const; | |
9487bae9 | 53 | |
55759ffb | 54 | void write(const StoreIOBuffer &buf); |
c43405e7 | 55 | void unlinkRequest() { request = nullptr; } |
66d51f4f AR |
56 | |
57 | /// HTTP response before 304 (Not Modified) updates | |
58 | /// starts "empty"; modified via replaceBaseReply() or adjustableBaseReply() | |
59 | const HttpReply &baseReply() const { return *reply_; } | |
60 | ||
61 | /// \returns nil -- if no 304 updates since replaceBaseReply() | |
62 | /// \returns combination of baseReply() and 304 updates -- after updates | |
63 | const HttpReplyPointer &updatedReply() const { return updatedReply_; } | |
64 | ||
65 | /// \returns the updated-by-304(s) response (if it exists) | |
66 | /// \returns baseReply() (otherwise) | |
67 | const HttpReply &freshestReply() const { | |
68 | if (updatedReply_) | |
69 | return *updatedReply_; | |
70 | else | |
71 | return baseReply(); | |
72 | } | |
73 | ||
74 | /// \returns writable base reply for parsing and other initial modifications | |
75 | /// Base modifications can only be done when forming/loading the entry. | |
76 | /// After that, use replaceBaseReply() to reset all of the replies. | |
77 | HttpReply &adjustableBaseReply(); | |
78 | ||
79 | /// (re)sets base reply, usually just replacing the initial/empty object | |
80 | /// also forgets the updated reply (if any) | |
81 | void replaceBaseReply(const HttpReplyPointer &r); | |
82 | ||
83 | /// (re)sets updated reply; \see updatedReply() | |
84 | void updateReply(const HttpReply &r) { updatedReply_ = &r; } | |
85 | ||
86 | /// reflects past Controller::updateOnNotModified(old, e304) calls: | |
87 | /// for HTTP 304 entries: whether our entry was used as "e304" | |
88 | /// for other entries: whether our entry was updated as "old" | |
89 | bool appliedUpdates = false; | |
90 | ||
fcc35180 | 91 | void stat (MemBuf * mb) const; |
122a6e3c AR |
92 | |
93 | /// The offset of the last memory-stored HTTP response byte plus one. | |
94 | /// * HTTP response headers (if any) are stored at offset zero. | |
95 | /// * HTTP response body byte[n] usually has offset (hdr_sz + n), where | |
96 | /// hdr_sz is the size of stored HTTP response headers (zero if none); and | |
97 | /// n is the corresponding byte offset in the whole resource body. | |
98 | /// However, some 206 (Partial Content) response bodies are stored (and | |
99 | /// retrieved) as regular 200 response bodies, disregarding offsets of | |
100 | /// their body parts. \sa HttpStateData::decideIfWeDoRanges(). | |
47f6e231 | 101 | int64_t endOffset () const; |
66d51f4f AR |
102 | |
103 | /// sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset() | |
104 | void markEndOfReplyHeaders(); | |
105 | ||
aa1a691e AR |
106 | /// negative if unknown; otherwise, expected object_sz, expected endOffset |
107 | /// maximum, and stored reply headers+body size (all three are the same) | |
108 | int64_t expectedReplySize() const; | |
47f6e231 | 109 | int64_t size() const; |
528b2c61 | 110 | void reset(); |
47f6e231 | 111 | int64_t lowestMemReaderOffset() const; |
528b2c61 | 112 | bool readAheadPolicyCanRead() const; |
113 | void addClient(store_client *); | |
62e76326 | 114 | /* XXX belongs in MemObject::swapout, once swaphdrsz is managed |
528b2c61 | 115 | * better |
116 | */ | |
47f6e231 | 117 | int64_t objectBytesOnDisk() const; |
10aeba1d | 118 | int64_t policyLowestOffsetToKeep(bool swap) const; |
5b55f1f1 | 119 | int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet |
528b2c61 | 120 | void trimSwappable(); |
121 | void trimUnSwappable(); | |
122 | bool isContiguous() const; | |
384a7590 | 123 | int mostBytesWanted(int max, bool ignoreDelayPools) const; |
a46d2c0e | 124 | void setNoDelay(bool const newValue); |
9a0a18de | 125 | #if USE_DELAY_POOLS |
b67e2c8c | 126 | DelayId mostBytesAllowed() const; |
127 | #endif | |
528b2c61 | 128 | |
528b2c61 | 129 | #if URL_CHECKSUM_DEBUG |
62e76326 | 130 | |
528b2c61 | 131 | void checkUrlChecksum() const; |
132 | #endif | |
133 | ||
c877c0bc AR |
134 | /// Before StoreID, code assumed that MemObject stores Request URI. |
135 | /// After StoreID, some old code still incorrectly assumes that. | |
136 | /// Use this method to mark that incorrect assumption. | |
137 | const char *urlXXX() const { return storeId(); } | |
138 | ||
139 | /// Entry StoreID (usually just Request URI); if a buggy code requests this | |
140 | /// before the information is available, returns an "[unknown_URI]" string. | |
141 | const char *storeId() const; | |
142 | ||
143 | /// client request URI used for logging; storeId() by default | |
144 | const char *logUri() const; | |
145 | ||
60745f24 | 146 | HttpRequestMethod method; |
528b2c61 | 147 | mem_hdr data_hdr; |
b56b37cf | 148 | int64_t inmem_lo = 0; |
528b2c61 | 149 | dlink_list clients; |
63be0a78 | 150 | |
0e3f3e0d | 151 | size_t clientCount() const {return nclients;} |
152 | ||
153 | bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);} | |
154 | ||
b56b37cf | 155 | int nclients = 0; |
62e76326 | 156 | |
ecf22804 | 157 | class SwapOut |
62e76326 | 158 | { |
ecf22804 | 159 | public: |
b56b37cf | 160 | int64_t queue_offset = 0; ///< number of bytes sent to SwapDir for writing |
62e76326 | 161 | StoreIOState::Pointer sio; |
ddc9b32c AR |
162 | |
163 | /// Decision states for StoreEntry::swapoutPossible() and related code. | |
0e3b2ff0 | 164 | typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision; |
b56b37cf | 165 | Decision decision = swNeedsCheck; ///< current decision state |
ecf22804 | 166 | }; |
62e76326 | 167 | |
ecf22804 | 168 | SwapOut swapout; |
63be0a78 | 169 | |
4310f8b0 EB |
170 | /* TODO: Remove this change-minimizing hack */ |
171 | using Io = Store::IoStatus; | |
172 | static constexpr Io ioUndecided = Store::ioUndecided; | |
173 | static constexpr Io ioReading = Store::ioReading; | |
174 | static constexpr Io ioWriting = Store::ioWriting; | |
175 | static constexpr Io ioDone = Store::ioDone; | |
99921d9d | 176 | |
4475555f | 177 | /// State of an entry with regards to the [shared] in-transit table. |
9d4e9cfb AR |
178 | class XitTable |
179 | { | |
4475555f | 180 | public: |
dbedb5b9 AR |
181 | /// associate our StoreEntry with a Transients entry at the given index |
182 | void open(const int32_t anIndex, const Io anIo) | |
183 | { | |
184 | index = anIndex; | |
185 | io = anIo; | |
186 | } | |
187 | ||
188 | /// stop associating our StoreEntry with a Transients entry | |
189 | void close() | |
190 | { | |
191 | index = -1; | |
192 | io = Store::ioDone; | |
193 | } | |
194 | ||
b56b37cf AJ |
195 | int32_t index = -1; ///< entry position inside the in-transit table |
196 | Io io = ioUndecided; ///< current I/O state | |
4475555f AR |
197 | }; |
198 | XitTable xitTable; ///< current [shared] memory caching state for the entry | |
199 | ||
200 | /// State of an entry with regards to the [shared] memory caching. | |
9d4e9cfb AR |
201 | class MemCache |
202 | { | |
4475555f | 203 | public: |
b56b37cf AJ |
204 | int32_t index = -1; ///< entry position inside the memory cache |
205 | int64_t offset = 0; ///< bytes written/read to/from the memory cache so far | |
4475555f | 206 | |
b56b37cf | 207 | Io io = ioUndecided; ///< current I/O state |
4475555f AR |
208 | }; |
209 | MemCache memCache; ///< current [shared] memory caching state for the entry | |
210 | ||
c43405e7 | 211 | HttpRequestPointer request; |
62e76326 | 212 | |
528b2c61 | 213 | struct timeval start_ping; |
214 | IRCB *ping_reply_callback; | |
b56b37cf | 215 | PeerSelector *ircb_data = nullptr; |
62e76326 | 216 | |
7e9f330d | 217 | /// used for notifying StoreEntry writers about 3rd-party initiated aborts |
a928fdfd | 218 | AsyncCallPointer abortCallback; |
528b2c61 | 219 | RemovalPolicyNode repl; |
b56b37cf AJ |
220 | int id = 0; |
221 | int64_t object_sz = -1; | |
222 | size_t swap_hdr_sz = 0; | |
528b2c61 | 223 | #if URL_CHECKSUM_DEBUG |
b56b37cf | 224 | unsigned int chksum = 0; |
528b2c61 | 225 | #endif |
62e76326 | 226 | |
90ab8f20 | 227 | SBuf vary_headers; |
62e76326 | 228 | |
a928fdfd | 229 | void delayRead(const AsyncCallPointer &); |
a46d2c0e | 230 | void kickReads(); |
231 | ||
528b2c61 | 232 | private: |
66d51f4f AR |
233 | HttpReplyPointer reply_; ///< \see baseReply() |
234 | HttpReplyPointer updatedReply_; ///< \see updatedReply() | |
4a56ee8d | 235 | |
c877c0bc AR |
236 | mutable String storeId_; ///< StoreId for our entry (usually request URI) |
237 | mutable String logUri_; ///< URI used for logging (usually request URI) | |
238 | ||
a928fdfd | 239 | DelayedAsyncCalls deferredReads; |
528b2c61 | 240 | }; |
241 | ||
63be0a78 | 242 | /** global current memory removal policy */ |
aa839030 | 243 | extern RemovalPolicy *mem_policy; |
244 | ||
528b2c61 | 245 | #endif /* SQUID_MEMOBJECT_H */ |
f53969cc | 246 |