]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 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 FC |
17 | #include "stmem.h" |
18 | #include "StoreIOBuffer.h" | |
19 | #include "StoreIOState.h" | |
e1ba42a4 | 20 | #include "typedefs.h" //for IRCB |
528b2c61 | 21 | |
43ca19e0 FC |
22 | #if USE_DELAY_POOLS |
23 | #include "DelayId.h" | |
24 | #endif | |
25 | ||
528b2c61 | 26 | typedef void STMCB (void *data, StoreIOBuffer wroteBuffer); |
95beee34 | 27 | typedef void STABH(void *); |
528b2c61 | 28 | |
29 | class store_client; | |
30 | ||
62e76326 | 31 | class MemObject |
32 | { | |
741c2986 | 33 | MEMPROXY_CLASS(MemObject); |
62e76326 | 34 | |
528b2c61 | 35 | public: |
36 | static size_t inUseCount(); | |
62e76326 | 37 | |
528b2c61 | 38 | void dump() const; |
c877c0bc | 39 | MemObject(); |
528b2c61 | 40 | ~MemObject(); |
41 | ||
76d61119 EB |
42 | /// Sets store ID, log URI, and request method (unless already set). Does |
43 | /// not clobber the method so that, say, a HEAD hit for a GET entry keeps | |
44 | /// the GET method that matches the entry key. Same for the other parts of | |
45 | /// the trio because the entry filling code may expect them to be constant. | |
46 | /// XXX: Avoid this method. We plan to remove it and make the trio constant | |
47 | /// after addressing the XXX in MemStore::get(). | |
c877c0bc | 48 | void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod); |
9487bae9 | 49 | |
c877c0bc AR |
50 | /// whether setUris() has been called |
51 | bool hasUris() const; | |
9487bae9 | 52 | |
55759ffb | 53 | void write(const StoreIOBuffer &buf); |
c43405e7 | 54 | void unlinkRequest() { request = nullptr; } |
a0c227a9 AJ |
55 | const HttpReplyPointer &getReply() const { return reply_; } |
56 | void replaceReply(const HttpReplyPointer &r) { reply_ = r; } | |
fcc35180 | 57 | void stat (MemBuf * mb) const; |
47f6e231 | 58 | int64_t endOffset () const; |
a0c227a9 | 59 | void markEndOfReplyHeaders(); ///< sets reply_->hdr_sz to endOffset() |
aa1a691e AR |
60 | /// negative if unknown; otherwise, expected object_sz, expected endOffset |
61 | /// maximum, and stored reply headers+body size (all three are the same) | |
62 | int64_t expectedReplySize() const; | |
47f6e231 | 63 | int64_t size() const; |
528b2c61 | 64 | void reset(); |
47f6e231 | 65 | int64_t lowestMemReaderOffset() const; |
528b2c61 | 66 | bool readAheadPolicyCanRead() const; |
67 | void addClient(store_client *); | |
62e76326 | 68 | /* XXX belongs in MemObject::swapout, once swaphdrsz is managed |
528b2c61 | 69 | * better |
70 | */ | |
47f6e231 | 71 | int64_t objectBytesOnDisk() const; |
10aeba1d | 72 | int64_t policyLowestOffsetToKeep(bool swap) const; |
5b55f1f1 | 73 | int64_t availableForSwapOut() const; ///< buffered bytes we have not swapped out yet |
528b2c61 | 74 | void trimSwappable(); |
75 | void trimUnSwappable(); | |
76 | bool isContiguous() const; | |
384a7590 | 77 | int mostBytesWanted(int max, bool ignoreDelayPools) const; |
a46d2c0e | 78 | void setNoDelay(bool const newValue); |
9a0a18de | 79 | #if USE_DELAY_POOLS |
b67e2c8c | 80 | DelayId mostBytesAllowed() const; |
81 | #endif | |
528b2c61 | 82 | |
528b2c61 | 83 | #if URL_CHECKSUM_DEBUG |
62e76326 | 84 | |
528b2c61 | 85 | void checkUrlChecksum() const; |
86 | #endif | |
87 | ||
c877c0bc AR |
88 | /// Before StoreID, code assumed that MemObject stores Request URI. |
89 | /// After StoreID, some old code still incorrectly assumes that. | |
90 | /// Use this method to mark that incorrect assumption. | |
91 | const char *urlXXX() const { return storeId(); } | |
92 | ||
93 | /// Entry StoreID (usually just Request URI); if a buggy code requests this | |
94 | /// before the information is available, returns an "[unknown_URI]" string. | |
95 | const char *storeId() const; | |
96 | ||
97 | /// client request URI used for logging; storeId() by default | |
98 | const char *logUri() const; | |
99 | ||
60745f24 | 100 | HttpRequestMethod method; |
528b2c61 | 101 | mem_hdr data_hdr; |
47f6e231 | 102 | int64_t inmem_lo; |
528b2c61 | 103 | dlink_list clients; |
63be0a78 | 104 | |
0e3f3e0d | 105 | size_t clientCount() const {return nclients;} |
106 | ||
107 | bool clientIsFirst(void *sc) const {return (clients.head && sc == clients.head->data);} | |
108 | ||
528b2c61 | 109 | int nclients; |
62e76326 | 110 | |
ecf22804 | 111 | class SwapOut |
62e76326 | 112 | { |
ecf22804 | 113 | public: |
cc8c4af2 AJ |
114 | SwapOut() : queue_offset(0), decision(swNeedsCheck) {} |
115 | ||
aa1a691e | 116 | int64_t queue_offset; ///< number of bytes sent to SwapDir for writing |
62e76326 | 117 | StoreIOState::Pointer sio; |
ddc9b32c AR |
118 | |
119 | /// Decision states for StoreEntry::swapoutPossible() and related code. | |
0e3b2ff0 | 120 | typedef enum { swNeedsCheck = 0, swImpossible = -1, swPossible = +1, swStarted } Decision; |
ddc9b32c | 121 | Decision decision; ///< current decision state |
ecf22804 | 122 | }; |
62e76326 | 123 | |
ecf22804 | 124 | SwapOut swapout; |
63be0a78 | 125 | |
99921d9d AR |
126 | /// cache "I/O" direction and status |
127 | typedef enum { ioUndecided, ioWriting, ioReading, ioDone } Io; | |
128 | ||
4475555f | 129 | /// State of an entry with regards to the [shared] in-transit table. |
9d4e9cfb AR |
130 | class XitTable |
131 | { | |
4475555f | 132 | public: |
99921d9d | 133 | XitTable(): index(-1), io(ioUndecided) {} |
4475555f AR |
134 | |
135 | int32_t index; ///< entry position inside the in-transit table | |
99921d9d | 136 | Io io; ///< current I/O state |
4475555f AR |
137 | }; |
138 | XitTable xitTable; ///< current [shared] memory caching state for the entry | |
139 | ||
140 | /// State of an entry with regards to the [shared] memory caching. | |
9d4e9cfb AR |
141 | class MemCache |
142 | { | |
4475555f AR |
143 | public: |
144 | MemCache(): index(-1), offset(0), io(ioUndecided) {} | |
145 | ||
146 | int32_t index; ///< entry position inside the memory cache | |
147 | int64_t offset; ///< bytes written/read to/from the memory cache so far | |
9d4e9cfb | 148 | |
4475555f AR |
149 | Io io; ///< current I/O state |
150 | }; | |
151 | MemCache memCache; ///< current [shared] memory caching state for the entry | |
152 | ||
153 | bool smpCollapsed; ///< whether this entry gets data from another worker | |
154 | ||
528b2c61 | 155 | /* Read only - this reply must be preserved by store clients */ |
156 | /* The original reply. possibly with updated metadata. */ | |
c43405e7 | 157 | HttpRequestPointer request; |
62e76326 | 158 | |
528b2c61 | 159 | struct timeval start_ping; |
160 | IRCB *ping_reply_callback; | |
161 | void *ircb_data; | |
62e76326 | 162 | |
26ac0430 | 163 | struct { |
528b2c61 | 164 | STABH *callback; |
165 | void *data; | |
2fadd50d | 166 | } abort; |
528b2c61 | 167 | RemovalPolicyNode repl; |
168 | int id; | |
47f6e231 | 169 | int64_t object_sz; |
528b2c61 | 170 | size_t swap_hdr_sz; |
171 | #if URL_CHECKSUM_DEBUG | |
62e76326 | 172 | |
528b2c61 | 173 | unsigned int chksum; |
174 | #endif | |
62e76326 | 175 | |
90ab8f20 | 176 | SBuf vary_headers; |
62e76326 | 177 | |
a46d2c0e | 178 | void delayRead(DeferredRead const &); |
179 | void kickReads(); | |
180 | ||
528b2c61 | 181 | private: |
a0c227a9 | 182 | HttpReplyPointer reply_; |
4a56ee8d | 183 | |
c877c0bc AR |
184 | mutable String storeId_; ///< StoreId for our entry (usually request URI) |
185 | mutable String logUri_; ///< URI used for logging (usually request URI) | |
186 | ||
a46d2c0e | 187 | DeferredReadManager deferredReads; |
528b2c61 | 188 | }; |
189 | ||
63be0a78 | 190 | /** global current memory removal policy */ |
aa839030 | 191 | extern RemovalPolicy *mem_policy; |
192 | ||
528b2c61 | 193 | #endif /* SQUID_MEMOBJECT_H */ |
f53969cc | 194 |