]>
Commit | Line | Data |
---|---|---|
e6ccf245 | 1 | /* |
e6ccf245 | 2 | * |
3 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
4 | * ---------------------------------------------------------- | |
5 | * | |
6 | * Squid is the result of efforts by numerous individuals from | |
7 | * the Internet community; see the CONTRIBUTORS file for full | |
8 | * details. Many organizations have provided support for Squid's | |
9 | * development; see the SPONSORS file for full details. Squid is | |
10 | * Copyrighted (C) 2001 by the Regents of the University of | |
11 | * California; see the COPYRIGHT file for full details. Squid | |
12 | * incorporates software developed and/or copyrighted by other | |
13 | * sources; see the CREDITS file for full details. | |
14 | * | |
15 | * This program is free software; you can redistribute it and/or modify | |
16 | * it under the terms of the GNU General Public License as published by | |
17 | * the Free Software Foundation; either version 2 of the License, or | |
18 | * (at your option) any later version. | |
26ac0430 | 19 | * |
e6ccf245 | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | * GNU General Public License for more details. | |
26ac0430 | 24 | * |
e6ccf245 | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program; if not, write to the Free Software | |
27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
28 | * | |
29 | */ | |
e6ccf245 | 30 | #ifndef SQUID_STORE_H |
31 | #define SQUID_STORE_H | |
32 | ||
63be0a78 | 33 | /** |
34 | \defgroup StoreAPI Store API | |
35 | \ingroup FileSystems | |
36 | */ | |
37 | ||
3e4bebf8 | 38 | #include "comm/forward.h" |
582c2af2 | 39 | #include "CommRead.h" |
43ca19e0 | 40 | #include "HttpReply.h" |
582c2af2 | 41 | #include "HttpRequestMethod.h" |
582c2af2 FC |
42 | #include "Range.h" |
43 | #include "RefCount.h" | |
aa839030 | 44 | #include "RemovalPolicy.h" |
71b673d4 | 45 | //#include "RequestFlags.h" |
582c2af2 | 46 | #include "StoreIOBuffer.h" |
93bc1434 | 47 | #include "StoreStats.h" |
528b2c61 | 48 | |
f41735ea | 49 | #if USE_SQUID_ESI |
f99c2cfe | 50 | #include "esi/Element.h" |
43ae1d95 | 51 | #endif |
52 | ||
27e059d4 AJ |
53 | #if HAVE_OSTREAM |
54 | #include <ostream> | |
55 | #endif | |
56 | ||
65517dc8 | 57 | class AsyncCall; |
582c2af2 | 58 | class HttpRequest; |
528b2c61 | 59 | class MemObject; |
71b673d4 FC |
60 | class Packer; |
61 | class RequestFlags; | |
582c2af2 | 62 | class StoreClient; |
c8f4eac4 | 63 | class StoreSearch; |
7d3c4ca1 | 64 | class SwapDir; |
c8f4eac4 | 65 | |
8822ebee AR |
66 | extern StoreIoStats store_io_stats; |
67 | ||
051dedf9 AR |
68 | /// maximum number of entries per cache_dir |
69 | enum { SwapFilenMax = 0xFFFFFF }; // keep in sync with StoreEntry::swap_filen | |
70 | ||
63be0a78 | 71 | /** |
72 | \ingroup StoreAPI | |
73 | */ | |
62e76326 | 74 | class StoreEntry : public hash_link |
75 | { | |
76 | ||
332dafa2 | 77 | public: |
a46d2c0e | 78 | static DeferredRead::DeferrableRead DeferReader; |
79 | bool checkDeferRead(int fd) const; | |
62e76326 | 80 | |
528b2c61 | 81 | virtual const char *getMD5Text() const; |
c8f4eac4 | 82 | StoreEntry(); |
83 | StoreEntry(const char *url, const char *log_url); | |
6d8d05b5 | 84 | virtual ~StoreEntry(); |
43ae1d95 | 85 | |
528b2c61 | 86 | virtual HttpReply const *getReply() const; |
87 | virtual void write (StoreIOBuffer); | |
88 | virtual _SQUID_INLINE_ bool isEmpty() const; | |
aa18a4ca | 89 | virtual bool isAccepting() const; |
384a7590 | 90 | virtual size_t bytesWanted(Range<size_t> const aRange, bool ignoreDelayPool = false) const; |
528b2c61 | 91 | virtual void complete(); |
92 | virtual store_client_t storeClientType() const; | |
93 | virtual char const *getSerialisedMetaData(); | |
3756e5c0 AR |
94 | void replaceHttpReply(HttpReply *, bool andStartWriting = true); |
95 | void startWriting(); ///< pack and write reply headers and, maybe, body | |
5b55f1f1 CT |
96 | /// whether we may start writing to disk (now or in the future) |
97 | virtual bool mayStartSwapOut(); | |
98 | virtual void trimMemory(const bool preserveSwappable); | |
bfb55b6f | 99 | void abort(); |
c8f4eac4 | 100 | void unlink(); |
5ed72359 | 101 | void makePublic(); |
102 | void makePrivate(); | |
d88e3c49 | 103 | void setPublicKey(); |
104 | void setPrivateKey(); | |
105 | void expireNow(); | |
106 | void releaseRequest(); | |
107 | void negativeCache(); | |
63be0a78 | 108 | void cacheNegatively(); /** \todo argh, why both? */ |
d88e3c49 | 109 | void invokeHandlers(); |
110 | void purgeMem(); | |
9487bae9 | 111 | void cacheInMemory(); ///< start or continue storing in memory cache |
c07cbbf4 | 112 | void swapOut(); |
5b55f1f1 CT |
113 | /// whether we are in the process of writing this entry to disk |
114 | bool swappingOut() const { return swap_status == SWAPOUT_WRITING; } | |
aa1a691e | 115 | void swapOutFileClose(int how); |
3900307b | 116 | const char *url() const; |
117 | int checkCachable(); | |
118 | int checkNegativeHit() const; | |
119 | int locked() const; | |
120 | int validToSend() const; | |
9487bae9 | 121 | bool memoryCachable() const; ///< may be cached in memory |
3900307b | 122 | void createMemObject(const char *, const char *); |
9487bae9 | 123 | void hideMemObject(); ///< no mem_obj for callers until createMemObject |
3900307b | 124 | void dump(int debug_lvl) const; |
125 | void hashDelete(); | |
126 | void hashInsert(const cache_key *); | |
127 | void registerAbort(STABH * cb, void *); | |
128 | void reset(); | |
129 | void setMemStatus(mem_status_t); | |
130 | void timestampsSet(); | |
131 | void unregisterAbort(); | |
132 | void destroyMemObject(); | |
133 | int checkTooSmall(); | |
528b2c61 | 134 | |
3e4bebf8 | 135 | void delayAwareRead(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer callback); |
43ae1d95 | 136 | |
a46d2c0e | 137 | void setNoDelay (bool const); |
190154cf | 138 | bool modifiedSince(HttpRequest * request) const; |
79c8035e AR |
139 | /// has ETag matching at least one of the If-Match etags |
140 | bool hasIfMatchEtag(const HttpRequest &request) const; | |
141 | /// has ETag matching at least one of the If-None-Match etags | |
142 | bool hasIfNoneMatchEtag(const HttpRequest &request) const; | |
63be0a78 | 143 | |
144 | /** What store does this entry belong too ? */ | |
7d3c4ca1 | 145 | virtual RefCount<SwapDir> store() const; |
a46d2c0e | 146 | |
e6ccf245 | 147 | MemObject *mem_obj; |
9487bae9 | 148 | MemObject *hidden_mem_obj; ///< mem_obj created before URLs were known |
e6ccf245 | 149 | RemovalPolicyNode repl; |
150 | /* START OF ON-DISK STORE_META_STD TLV field */ | |
151 | time_t timestamp; | |
152 | time_t lastref; | |
153 | time_t expires; | |
154 | time_t lastmod; | |
47f6e231 | 155 | uint64_t swap_file_sz; |
f45dd259 AJ |
156 | uint16_t refcount; |
157 | uint16_t flags; | |
e6ccf245 | 158 | /* END OF ON-DISK STORE_META_STD */ |
62e76326 | 159 | |
051dedf9 AR |
160 | /// unique ID inside a cache_dir for swapped out entries; -1 for others |
161 | sfileno swap_filen:25; // keep in sync with SwapFilenMax | |
d1398b75 HN |
162 | |
163 | sdirno swap_dirn:7; | |
62e76326 | 164 | |
f45dd259 | 165 | unsigned short lock_count; /* Assume < 65536! */ |
62e76326 | 166 | |
d1398b75 | 167 | mem_status_t mem_status:3; |
62e76326 | 168 | |
d1398b75 | 169 | ping_status_t ping_status:3; |
62e76326 | 170 | |
d1398b75 | 171 | store_status_t store_status:3; |
62e76326 | 172 | |
d1398b75 | 173 | swap_status_t swap_status:3; |
62e76326 | 174 | |
e6ccf245 | 175 | public: |
176 | static size_t inUseCount(); | |
60745f24 | 177 | static void getPublicByRequestMethod(StoreClient * aClient, HttpRequest * request, const HttpRequestMethod& method); |
190154cf | 178 | static void getPublicByRequest(StoreClient * aClient, HttpRequest * request); |
60745f24 | 179 | static void getPublic(StoreClient * aClient, const char *uri, const HttpRequestMethod& method); |
528b2c61 | 180 | |
26ac0430 | 181 | virtual bool isNull() { |
62e76326 | 182 | return false; |
63be0a78 | 183 | }; |
62e76326 | 184 | |
35db0b4e | 185 | void *operator new(size_t byteCount); |
e6ccf245 | 186 | void operator delete(void *address); |
43ae1d95 | 187 | void setReleaseFlag(); |
f41735ea | 188 | #if USE_SQUID_ESI |
43ae1d95 | 189 | |
190 | ESIElement::Pointer cachedESITree; | |
191 | #endif | |
63be0a78 | 192 | /** append bytes to the buffer */ |
c21ad0f5 | 193 | virtual void append(char const *, int len); |
63be0a78 | 194 | /** disable sending content to the clients */ |
c21ad0f5 | 195 | virtual void buffer(); |
63be0a78 | 196 | /** flush any buffered content */ |
c21ad0f5 | 197 | virtual void flush(); |
63be0a78 | 198 | /** reduce the memory lock count on the entry */ |
c21ad0f5 | 199 | virtual int unlock(); |
63be0a78 | 200 | /** increate the memory lock count on the entry */ |
47f6e231 | 201 | virtual int64_t objectLen() const; |
202 | virtual int64_t contentLen() const; | |
c21ad0f5 | 203 | |
63be0a78 | 204 | virtual void lock(); |
5f33b71d | 205 | virtual void release(); |
62e76326 | 206 | |
0ad2b63b CT |
207 | #if USE_ADAPTATION |
208 | /// call back producer when more buffer space is available | |
209 | void deferProducer(const AsyncCall::Pointer &producer); | |
210 | /// calls back producer registered with deferProducer | |
211 | void kickProducer(); | |
212 | #endif | |
213 | ||
e6ccf245 | 214 | private: |
04eb0689 | 215 | static MemAllocator *pool; |
528b2c61 | 216 | |
0ad2b63b CT |
217 | #if USE_ADAPTATION |
218 | /// producer callback registered with deferProducer | |
219 | AsyncCall::Pointer deferredProducer; | |
220 | #endif | |
221 | ||
528b2c61 | 222 | bool validLength() const; |
79c8035e | 223 | bool hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const; |
e6ccf245 | 224 | }; |
225 | ||
2c4cd1ad AR |
226 | std::ostream &operator <<(std::ostream &os, const StoreEntry &e); |
227 | ||
63be0a78 | 228 | /// \ingroup StoreAPI |
3b13a8fd | 229 | class NullStoreEntry:public StoreEntry |
e6ccf245 | 230 | { |
62e76326 | 231 | |
e6ccf245 | 232 | public: |
233 | static NullStoreEntry *getInstance(); | |
26ac0430 | 234 | bool isNull() { |
62e76326 | 235 | return true; |
e6ccf245 | 236 | } |
62e76326 | 237 | |
332dafa2 | 238 | const char *getMD5Text() const; |
528b2c61 | 239 | _SQUID_INLINE_ HttpReply const *getReply() const; |
26ac0430 | 240 | void write (StoreIOBuffer) {} |
62e76326 | 241 | |
528b2c61 | 242 | bool isEmpty () const {return true;} |
62e76326 | 243 | |
384a7590 | 244 | virtual size_t bytesWanted(Range<size_t> const aRange, bool ignoreDelayPool = false) const { return aRange.end; } |
62e76326 | 245 | |
e6ccf245 | 246 | void operator delete(void *address); |
26ac0430 | 247 | void complete() {} |
62e76326 | 248 | |
249 | private: | |
26ac0430 | 250 | store_client_t storeClientType() const {return STORE_MEM_CLIENT;} |
62e76326 | 251 | |
528b2c61 | 252 | char const *getSerialisedMetaData(); |
5b55f1f1 | 253 | bool mayStartSwapout() {return false;} |
62e76326 | 254 | |
74b9c248 | 255 | void trimMemory(const bool preserveSwappable) {} |
528b2c61 | 256 | |
e6ccf245 | 257 | static NullStoreEntry _instance; |
258 | }; | |
259 | ||
63be0a78 | 260 | /// \ingroup StoreAPI |
c8f4eac4 | 261 | typedef void (*STOREGETCLIENT) (StoreEntry *, void *cbdata); |
262 | ||
63be0a78 | 263 | /** |
264 | \ingroup StoreAPI | |
265 | * Abstract base class that will replace the whole store and swapdir interface. | |
266 | */ | |
c8f4eac4 | 267 | class Store : public RefCountable |
268 | { | |
269 | ||
270 | public: | |
63be0a78 | 271 | /** The root store */ |
88e13392 | 272 | static _SQUID_INLINE_ Store &Root(); |
c8f4eac4 | 273 | static void Root(Store *); |
274 | static void Root(RefCount<Store>); | |
275 | static void Stats(StoreEntry * output); | |
276 | static void Maintain(void *unused); | |
277 | ||
278 | virtual ~Store() {} | |
279 | ||
63be0a78 | 280 | /** Handle pending callbacks - called by the event loop. */ |
c8f4eac4 | 281 | virtual int callback() = 0; |
63be0a78 | 282 | |
283 | /** create the resources needed for this store to operate */ | |
c8f4eac4 | 284 | virtual void create(); |
63be0a78 | 285 | |
286 | /** | |
287 | * Notify this store that its disk is full. | |
288 | \todo XXX move into a protected api call between store files and their stores, rather than a top level api call | |
c8f4eac4 | 289 | */ |
290 | virtual void diskFull(); | |
c8f4eac4 | 291 | |
63be0a78 | 292 | /** Retrieve a store entry from the store */ |
b21767da | 293 | virtual StoreEntry * get(const cache_key *) = 0; |
c8f4eac4 | 294 | |
63be0a78 | 295 | /** \todo imeplement the async version */ |
b21767da | 296 | virtual void get(String const key , STOREGETCLIENT callback, void *cbdata) = 0; |
c8f4eac4 | 297 | |
298 | /* prepare the store for use. The store need not be usable immediately, | |
299 | * it should respond to readable() and writable() with true as soon | |
300 | * as it can provide those services | |
301 | */ | |
302 | virtual void init() = 0; | |
303 | ||
63be0a78 | 304 | /** |
305 | * The maximum size the store will support in normal use. Inaccuracy is permitted, | |
306 | * but may throw estimates for memory etc out of whack. | |
307 | */ | |
12e11a5c | 308 | virtual uint64_t maxSize() const = 0; |
c8f4eac4 | 309 | |
63be0a78 | 310 | /** The minimum size the store will shrink to via normal housekeeping */ |
12e11a5c | 311 | virtual uint64_t minSize() const = 0; |
c8f4eac4 | 312 | |
57f583f1 DK |
313 | /** current store size */ |
314 | virtual uint64_t currentSize() const = 0; | |
39c1e1d9 DK |
315 | |
316 | /** the total number of objects stored */ | |
317 | virtual uint64_t currentCount() const = 0; | |
318 | ||
af2fda07 DK |
319 | /** the maximum object size that can be stored, -1 if unlimited */ |
320 | virtual int64_t maxObjectSize() const = 0; | |
321 | ||
93bc1434 AR |
322 | /// collect cache storage-related statistics |
323 | virtual void getStats(StoreInfoStats &stats) const = 0; | |
324 | ||
63be0a78 | 325 | /** |
326 | * Output stats to the provided store entry. | |
327 | \todo make these calls asynchronous | |
328 | */ | |
329 | virtual void stat(StoreEntry &) const = 0; | |
c8f4eac4 | 330 | |
63be0a78 | 331 | /** Sync the store prior to shutdown */ |
332 | virtual void sync(); | |
c8f4eac4 | 333 | |
63be0a78 | 334 | /** remove a Store entry from the store */ |
c8f4eac4 | 335 | virtual void unlink (StoreEntry &); |
336 | ||
337 | /* search in the store */ | |
30abd221 | 338 | virtual StoreSearch *search(String const url, HttpRequest *) = 0; |
c8f4eac4 | 339 | |
340 | /* pulled up from SwapDir for migration.... probably do not belong here */ | |
341 | virtual void reference(StoreEntry &) = 0; /* Reference this object */ | |
342 | ||
4c973beb AR |
343 | /// Undo reference(), returning false iff idle e should be destroyed |
344 | virtual bool dereference(StoreEntry &e) = 0; | |
c8f4eac4 | 345 | |
346 | virtual void maintain() = 0; /* perform regular maintenance should be private and self registered ... */ | |
347 | ||
9487bae9 AR |
348 | // XXX: This method belongs to Store::Root/StoreController, but it is here |
349 | // because test cases use non-StoreController derivatives as Root | |
350 | /// called when the entry is no longer needed by any transaction | |
351 | virtual void handleIdleEntry(StoreEntry &e) {} | |
352 | ||
96a7de88 DK |
353 | // XXX: This method belongs to Store::Root/StoreController, but it is here |
354 | // because test cases use non-StoreController derivatives as Root | |
355 | /// called to get rid of no longer needed entry data in RAM, if any | |
356 | virtual void maybeTrimMemory(StoreEntry &e, const bool preserveSwappable) {} | |
357 | ||
c8f4eac4 | 358 | private: |
359 | static RefCount<Store> CurrentRoot; | |
360 | }; | |
361 | ||
63be0a78 | 362 | /// \ingroup StoreAPI |
c8f4eac4 | 363 | typedef RefCount<Store> StorePointer; |
364 | ||
63be0a78 | 365 | /// \ingroup StoreAPI |
71b673d4 | 366 | size_t storeEntryInUse(); |
63be0a78 | 367 | |
368 | /// \ingroup StoreAPI | |
71b673d4 | 369 | const char *storeEntryFlags(const StoreEntry *); |
63be0a78 | 370 | |
371 | /// \ingroup StoreAPI | |
71b673d4 | 372 | void storeEntryReplaceObject(StoreEntry *, HttpReply *); |
e6ccf245 | 373 | |
63be0a78 | 374 | /// \ingroup StoreAPI |
71b673d4 | 375 | StoreEntry *storeGetPublic(const char *uri, const HttpRequestMethod& method); |
63be0a78 | 376 | |
377 | /// \ingroup StoreAPI | |
71b673d4 | 378 | StoreEntry *storeGetPublicByRequest(HttpRequest * request); |
63be0a78 | 379 | |
380 | /// \ingroup StoreAPI | |
71b673d4 | 381 | StoreEntry *storeGetPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& method); |
63be0a78 | 382 | |
383 | /// \ingroup StoreAPI | |
71b673d4 | 384 | StoreEntry *storeCreateEntry(const char *, const char *, const RequestFlags &, const HttpRequestMethod&); |
63be0a78 | 385 | |
386 | /// \ingroup StoreAPI | |
71b673d4 | 387 | void storeInit(void); |
63be0a78 | 388 | |
63be0a78 | 389 | /// \ingroup StoreAPI |
71b673d4 | 390 | void storeConfigure(void); |
63be0a78 | 391 | |
392 | /// \ingroup StoreAPI | |
71b673d4 | 393 | void storeFreeMemory(void); |
63be0a78 | 394 | |
395 | /// \ingroup StoreAPI | |
71b673d4 | 396 | int expiresMoreThan(time_t, time_t); |
63be0a78 | 397 | |
63be0a78 | 398 | /// \ingroup StoreAPI |
71b673d4 | 399 | void storeAppendPrintf(StoreEntry *, const char *,...) PRINTF_FORMAT_ARG2; |
63be0a78 | 400 | |
401 | /// \ingroup StoreAPI | |
71b673d4 | 402 | void storeAppendVPrintf(StoreEntry *, const char *, va_list ap); |
63be0a78 | 403 | |
404 | /// \ingroup StoreAPI | |
71b673d4 | 405 | int storeTooManyDiskFilesOpen(void); |
63be0a78 | 406 | |
e1f7507e | 407 | class SwapDir; |
63be0a78 | 408 | /// \ingroup StoreAPI |
71b673d4 | 409 | void storeHeapPositionUpdate(StoreEntry *, SwapDir *); |
63be0a78 | 410 | |
411 | /// \ingroup StoreAPI | |
71b673d4 | 412 | void storeSwapFileNumberSet(StoreEntry * e, sfileno filn); |
63be0a78 | 413 | |
414 | /// \ingroup StoreAPI | |
71b673d4 | 415 | void storeFsInit(void); |
63be0a78 | 416 | |
417 | /// \ingroup StoreAPI | |
71b673d4 | 418 | void storeFsDone(void); |
63be0a78 | 419 | |
420 | /// \ingroup StoreAPI | |
71b673d4 | 421 | void storeReplAdd(const char *, REMOVALPOLICYCREATE *); |
63be0a78 | 422 | |
423 | /// \ingroup StoreAPI | |
c8f4eac4 | 424 | extern FREE destroyStoreEntry; |
e6ccf245 | 425 | |
63be0a78 | 426 | /** |
427 | \ingroup StoreAPI | |
428 | \todo should be a subclass of Packer perhaps ? | |
429 | */ | |
71b673d4 | 430 | void packerToStoreInit(Packer * p, StoreEntry * e); |
25b6a907 | 431 | |
6d3c2758 | 432 | /// \ingroup StoreAPI |
71b673d4 | 433 | void storeGetMemSpace(int size); |
6d3c2758 | 434 | |
32d002cb | 435 | #if _USE_INLINE_ |
528b2c61 | 436 | #include "Store.cci" |
437 | #endif | |
438 | ||
e6ccf245 | 439 | #endif /* SQUID_STORE_H */ |