]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 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 | ||
a46d2c0e | 12 | #include "CommRead.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; |
47f6e231 | 92 | int64_t endOffset () const; |
66d51f4f AR |
93 | |
94 | /// sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset() | |
95 | void markEndOfReplyHeaders(); | |
96 | ||
aa1a691e AR |
97 | /// negative if unknown; otherwise, expected object_sz, expected endOffset |
98 | /// maximum, and stored reply headers+body size (all three are the same) | |
99 | int64_t expectedReplySize() const; | |
47f6e231 | 100 | int64_t size() const; |
528b2c61 | 101 | void reset(); |
47f6e231 | 102 | int64_t lowestMemReaderOffset() const; |
528b2c61 | 103 | bool readAheadPolicyCanRead() const; |
104 | void addClient(store_client *); | |
62e76326 | 105 | /* XXX belongs in MemObject::swapout, once swaphdrsz is managed |
528b2c61 | 106 | * better |
107 | */ | |
47f6e231 | 108 | int64_t objectBytesOnDisk() const; |
10aeba1d | 109 | int64_t policyLowestOffsetToKeep(bool swap) const; |
5b55f1f1 | 110 | int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet |
528b2c61 | 111 | void trimSwappable(); |
112 | void trimUnSwappable(); | |
113 | bool isContiguous() const; | |
384a7590 | 114 | int mostBytesWanted(int max, bool ignoreDelayPools) const; |
a46d2c0e | 115 | void setNoDelay(bool const newValue); |
9a0a18de | 116 | #if USE_DELAY_POOLS |
b67e2c8c | 117 | DelayId mostBytesAllowed() const; |
118 | #endif | |
528b2c61 | 119 | |
528b2c61 | 120 | #if URL_CHECKSUM_DEBUG |
62e76326 | 121 | |
528b2c61 | 122 | void checkUrlChecksum() const; |
123 | #endif | |
124 | ||
c877c0bc AR |
125 | /// Before StoreID, code assumed that MemObject stores Request URI. |
126 | /// After StoreID, some old code still incorrectly assumes that. | |
127 | /// Use this method to mark that incorrect assumption. | |
128 | const char *urlXXX() const { return storeId(); } | |
129 | ||
130 | /// Entry StoreID (usually just Request URI); if a buggy code requests this | |
131 | /// before the information is available, returns an "[unknown_URI]" string. | |
132 | const char *storeId() const; | |
133 | ||
134 | /// client request URI used for logging; storeId() by default | |
135 | const char *logUri() const; | |
136 | ||
60745f24 | 137 | HttpRequestMethod method; |
528b2c61 | 138 | mem_hdr data_hdr; |
b56b37cf | 139 | int64_t inmem_lo = 0; |
528b2c61 | 140 | dlink_list clients; |
63be0a78 | 141 | |
0e3f3e0d | 142 | size_t clientCount() const {return nclients;} |
143 | ||
144 | bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);} | |
145 | ||
b56b37cf | 146 | int nclients = 0; |
62e76326 | 147 | |
ecf22804 | 148 | class SwapOut |
62e76326 | 149 | { |
ecf22804 | 150 | public: |
b56b37cf | 151 | int64_t queue_offset = 0; ///< number of bytes sent to SwapDir for writing |
62e76326 | 152 | StoreIOState::Pointer sio; |
ddc9b32c AR |
153 | |
154 | /// Decision states for StoreEntry::swapoutPossible() and related code. | |
0e3b2ff0 | 155 | typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision; |
b56b37cf | 156 | Decision decision = swNeedsCheck; ///< current decision state |
ecf22804 | 157 | }; |
62e76326 | 158 | |
ecf22804 | 159 | SwapOut swapout; |
63be0a78 | 160 | |
4310f8b0 EB |
161 | /* TODO: Remove this change-minimizing hack */ |
162 | using Io = Store::IoStatus; | |
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; | |
99921d9d | 167 | |
4475555f | 168 | /// State of an entry with regards to the [shared] in-transit table. |
9d4e9cfb AR |
169 | class XitTable |
170 | { | |
4475555f | 171 | public: |
b56b37cf AJ |
172 | int32_t index = -1; ///< entry position inside the in-transit table |
173 | Io io = ioUndecided; ///< current I/O state | |
4475555f AR |
174 | }; |
175 | XitTable xitTable; ///< current [shared] memory caching state for the entry | |
176 | ||
177 | /// State of an entry with regards to the [shared] memory caching. | |
9d4e9cfb AR |
178 | class MemCache |
179 | { | |
4475555f | 180 | public: |
b56b37cf AJ |
181 | int32_t index = -1; ///< entry position inside the memory cache |
182 | int64_t offset = 0; ///< bytes written/read to/from the memory cache so far | |
4475555f | 183 | |
b56b37cf | 184 | Io io = ioUndecided; ///< current I/O state |
4475555f AR |
185 | }; |
186 | MemCache memCache; ///< current [shared] memory caching state for the entry | |
187 | ||
c43405e7 | 188 | HttpRequestPointer request; |
62e76326 | 189 | |
528b2c61 | 190 | struct timeval start_ping; |
191 | IRCB *ping_reply_callback; | |
b56b37cf | 192 | PeerSelector *ircb_data = nullptr; |
62e76326 | 193 | |
7e9f330d EB |
194 | /// used for notifying StoreEntry writers about 3rd-party initiated aborts |
195 | AsyncCall::Pointer abortCallback; | |
528b2c61 | 196 | RemovalPolicyNode repl; |
b56b37cf AJ |
197 | int id = 0; |
198 | int64_t object_sz = -1; | |
199 | size_t swap_hdr_sz = 0; | |
528b2c61 | 200 | #if URL_CHECKSUM_DEBUG |
b56b37cf | 201 | unsigned int chksum = 0; |
528b2c61 | 202 | #endif |
62e76326 | 203 | |
90ab8f20 | 204 | SBuf vary_headers; |
62e76326 | 205 | |
a46d2c0e | 206 | void delayRead(DeferredRead const &); |
207 | void kickReads(); | |
208 | ||
528b2c61 | 209 | private: |
66d51f4f AR |
210 | HttpReplyPointer reply_; ///< \see baseReply() |
211 | HttpReplyPointer updatedReply_; ///< \see updatedReply() | |
4a56ee8d | 212 | |
c877c0bc AR |
213 | mutable String storeId_; ///< StoreId for our entry (usually request URI) |
214 | mutable String logUri_; ///< URI used for logging (usually request URI) | |
215 | ||
a46d2c0e | 216 | DeferredReadManager deferredReads; |
528b2c61 | 217 | }; |
218 | ||
63be0a78 | 219 | /** global current memory removal policy */ |
aa839030 | 220 | extern RemovalPolicy *mem_policy; |
221 | ||
528b2c61 | 222 | #endif /* SQUID_MEMOBJECT_H */ |
f53969cc | 223 |