5 * DEBUG: section 20 Storage Manager
6 * AUTHOR: Harvest Derived
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 #include "CacheManager.h"
38 #include "comm/Connection.h"
42 #include "mgr/Registration.h"
43 #include "StoreClient.h"
45 #include "HttpReply.h"
46 #include "HttpRequest.h"
47 #include "MemObject.h"
49 #include "StoreMeta.h"
52 #include "DelayPools.h"
55 #include "SquidTime.h"
56 #include "swap_log_op.h"
57 #include "mgr/StoreIoAction.h"
59 static STMCB storeWriteComplete
;
61 #define REBUILD_TIMESTAMP_DELTA_MAX 2
63 #define STORE_IN_MEM_BUCKETS (229)
66 /** \todo Convert these string constants to enum string-arrays generated */
68 const char *memStatusStr
[] = {
73 const char *pingStatusStr
[] = {
79 const char *storeStatusStr
[] = {
84 const char *swapStatusStr
[] = {
92 * This defines an repl type
95 typedef struct _storerepl_entry storerepl_entry_t
;
97 struct _storerepl_entry
{
99 REMOVALPOLICYCREATE
*create
;
102 static storerepl_entry_t
*storerepl_list
= NULL
;
106 * local function prototypes
108 static int getKeyCounter(void);
109 static OBJH storeCheckCachableStats
;
110 static EVH storeLateRelease
;
115 static Stack
<StoreEntry
*> LateReleaseStack
;
116 MemAllocator
*StoreEntry::pool
= NULL
;
118 StorePointer
Store::CurrentRoot
= NULL
;
121 Store::Root(Store
* aRoot
)
127 Store::Root(StorePointer aRoot
)
129 Root(aRoot
.getRaw());
133 Store::Stats(StoreEntry
* output
)
136 Root().stat(*output
);
152 Store::unlink (StoreEntry
&anEntry
)
154 fatal("Store::unlink on invalid Store\n");
158 StoreEntry::operator new (size_t bytecount
)
160 assert (bytecount
== sizeof (StoreEntry
));
163 pool
= memPoolCreate ("StoreEntry", bytecount
);
164 pool
->setChunkSize(2048 * 1024);
167 return pool
->alloc();
171 StoreEntry::operator delete (void *address
)
173 pool
->freeOne(address
);
177 StoreEntry::makePublic()
179 /* This object can be cached for a long time */
181 if (EBIT_TEST(flags
, ENTRY_CACHABLE
))
186 StoreEntry::makePrivate()
188 /* This object should never be cached at all */
190 releaseRequest(); /* delete object when not used */
191 /* releaseRequest clears ENTRY_CACHABLE flag */
195 StoreEntry::cacheNegatively()
197 /* This object may be negatively cached */
200 if (EBIT_TEST(flags
, ENTRY_CACHABLE
))
205 StoreEntry::inUseCount()
209 return pool
->getInUseCount();
213 StoreEntry::getMD5Text() const
215 return storeKeyText((const cache_key
*)key
);
221 StoreEntry::DeferReader(void *theContext
, CommRead
const &aRead
)
223 StoreEntry
*anEntry
= (StoreEntry
*)theContext
;
224 anEntry
->delayAwareRead(aRead
.conn
,
231 StoreEntry::delayAwareRead(const Comm::ConnectionPointer
&conn
, char *buf
, int len
, AsyncCall::Pointer callback
)
233 size_t amountToRead
= bytesWanted(Range
<size_t>(0, len
));
234 /* sketch: readdeferer* = getdeferer.
235 * ->deferRead (fd, buf, len, callback, DelayAwareRead, this)
238 if (amountToRead
== 0) {
240 /* read ahead limit */
241 /* Perhaps these two calls should both live in MemObject */
243 if (!mem_obj
->readAheadPolicyCanRead()) {
245 mem_obj
->delayRead(DeferredRead(DeferReader
, this, CommRead(conn
, buf
, len
, callback
)));
251 mem_obj
->mostBytesAllowed().delayRead(DeferredRead(DeferReader
, this, CommRead(conn
, buf
, len
, callback
)));
258 comm_read(conn
, buf
, amountToRead
, callback
);
262 StoreEntry::bytesWanted (Range
<size_t> const aRange
) const
264 assert (aRange
.size());
267 return aRange
.end
- 1;
269 #if URL_CHECKSUM_DEBUG
271 mem_obj
->checkUrlChecksum();
275 /* Always read *something* here - we haven't got the header yet */
276 if (EBIT_TEST(flags
, ENTRY_FWD_HDR_WAIT
))
277 return aRange
.end
- 1;
279 if (!mem_obj
->readAheadPolicyCanRead())
282 return mem_obj
->mostBytesWanted(aRange
.end
- 1);
286 StoreEntry::checkDeferRead(int fd
) const
288 return (bytesWanted(Range
<size_t>(0,INT_MAX
)) == 0);
292 StoreEntry::setNoDelay (bool const newValue
)
295 mem_obj
->setNoDelay(newValue
);
299 StoreEntry::storeClientType() const
301 /* The needed offset isn't in memory
302 * XXX TODO: this is wrong for range requests
303 * as the needed offset may *not* be 0, AND
304 * offset 0 in the memory object is the HTTP headers.
307 if (mem_obj
->inmem_lo
)
308 return STORE_DISK_CLIENT
;
310 if (EBIT_TEST(flags
, ENTRY_ABORTED
)) {
311 /* I don't think we should be adding clients to aborted entries */
312 debugs(20, 1, "storeClientType: adding to ENTRY_ABORTED entry");
313 return STORE_MEM_CLIENT
;
316 if (store_status
== STORE_OK
) {
317 /* the object has completed. */
319 if (mem_obj
->inmem_lo
== 0 && !isEmpty()) {
320 if (swap_status
== SWAPOUT_DONE
) {
321 if (mem_obj
->endOffset() == mem_obj
->object_sz
) {
322 /* hot object fully swapped in */
323 return STORE_MEM_CLIENT
;
326 /* Memory-only, or currently being swapped out */
327 return STORE_MEM_CLIENT
;
330 return STORE_DISK_CLIENT
;
333 /* here and past, entry is STORE_PENDING */
335 * If this is the first client, let it be the mem client
337 if (mem_obj
->nclients
== 1)
338 return STORE_MEM_CLIENT
;
341 * If there is no disk file to open yet, we must make this a
342 * mem client. If we can't open the swapin file before writing
343 * to the client, there is no guarantee that we will be able
344 * to open it later when we really need it.
346 if (swap_status
== SWAPOUT_NONE
)
347 return STORE_MEM_CLIENT
;
350 * otherwise, make subsequent clients read from disk so they
351 * can not delay the first, and vice-versa.
353 return STORE_DISK_CLIENT
;
356 StoreEntry::StoreEntry()
358 debugs(20, 3, HERE
<< "new StoreEntry " << this);
361 expires
= lastmod
= lastref
= timestamp
= -1;
367 StoreEntry::StoreEntry(const char *aUrl
, const char *aLogUrl
)
369 debugs(20, 3, HERE
<< "new StoreEntry " << this);
370 mem_obj
= new MemObject(aUrl
, aLogUrl
);
372 expires
= lastmod
= lastref
= timestamp
= -1;
379 StoreEntry::destroyMemObject()
381 debugs(20, 3, HERE
<< "destroyMemObject " << mem_obj
);
382 setMemStatus(NOT_IN_MEMORY
);
383 MemObject
*mem
= mem_obj
;
389 destroyStoreEntry(void *data
)
391 debugs(20, 3, HERE
<< "destroyStoreEntry: destroying " << data
);
392 StoreEntry
*e
= static_cast<StoreEntry
*>(static_cast<hash_link
*>(data
));
395 if (e
== NullStoreEntry::getInstance())
398 e
->destroyMemObject();
402 assert(e
->key
== NULL
);
407 /* ----- INTERFACE BETWEEN STORAGE MANAGER AND HASH TABLE FUNCTIONS --------- */
410 StoreEntry::hashInsert(const cache_key
* someKey
)
412 debugs(20, 3, "StoreEntry::hashInsert: Inserting Entry " << this << " key '" << storeKeyText(someKey
) << "'");
413 key
= storeKeyDup(someKey
);
414 hash_join(store_table
, this);
418 StoreEntry::hashDelete()
420 hash_remove_link(store_table
, this);
421 storeKeyFree((const cache_key
*)key
);
425 /* -------------------------------------------------------------------------- */
428 /* get rid of memory copy of the object */
430 StoreEntry::purgeMem()
435 debugs(20, 3, "StoreEntry::purgeMem: Freeing memory-copy of " << getMD5Text());
439 if (swap_status
!= SWAPOUT_DONE
)
443 /* RBC 20050104 this is wrong- memory ref counting
444 * is not at all equivalent to the store 'usage' concept
445 * which the replacement policies should be acting upon.
446 * specifically, object iteration within stores needs
447 * memory ref counting to prevent race conditions,
448 * but this should not influence store replacement.
455 debugs(20, 3, "StoreEntry::lock: key '" << getMD5Text() <<"' count=" <<
457 lastref
= squid_curtime
;
458 Store::Root().reference(*this);
462 StoreEntry::setReleaseFlag()
464 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
467 debugs(20, 3, "StoreEntry::setReleaseFlag: '" << getMD5Text() << "'");
469 EBIT_SET(flags
, RELEASE_REQUEST
);
473 StoreEntry::releaseRequest()
475 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
481 * Clear cachable flag here because we might get called before
482 * anyone else even looks at the cachability flag. Also, this
483 * prevents httpMakePublic from really setting a public key.
485 EBIT_CLR(flags
, ENTRY_CACHABLE
);
490 /* unlock object, return -1 if object get released after unlock
491 * otherwise lock_count */
496 debugs(20, 3, "StoreEntry::unlock: key '" << getMD5Text() << "' count=" << lock_count
);
499 return (int) lock_count
;
501 if (store_status
== STORE_PENDING
)
504 assert(storePendingNClients(this) == 0);
506 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
508 else if (keepInMemory()) {
509 Store::Root().dereference(*this);
510 setMemStatus(IN_MEMORY
);
511 mem_obj
->unlinkRequest();
513 Store::Root().dereference(*this);
515 if (EBIT_TEST(flags
, KEY_PRIVATE
))
516 debugs(20, 1, "WARNING: " << __FILE__
<< ":" << __LINE__
<< ": found KEY_PRIVATE");
518 /* StoreEntry::purgeMem may free e */
526 StoreEntry::getPublicByRequestMethod (StoreClient
*aClient
, HttpRequest
* request
, const HttpRequestMethod
& method
)
529 StoreEntry
*result
= storeGetPublicByRequestMethod( request
, method
);
532 aClient
->created (NullStoreEntry::getInstance());
534 aClient
->created (result
);
538 StoreEntry::getPublicByRequest (StoreClient
*aClient
, HttpRequest
* request
)
541 StoreEntry
*result
= storeGetPublicByRequest (request
);
544 result
= NullStoreEntry::getInstance();
546 aClient
->created (result
);
550 StoreEntry::getPublic (StoreClient
*aClient
, const char *uri
, const HttpRequestMethod
& method
)
553 StoreEntry
*result
= storeGetPublic (uri
, method
);
556 result
= NullStoreEntry::getInstance();
558 aClient
->created (result
);
562 storeGetPublic(const char *uri
, const HttpRequestMethod
& method
)
564 return Store::Root().get(storeKeyPublic(uri
, method
));
568 storeGetPublicByRequestMethod(HttpRequest
* req
, const HttpRequestMethod
& method
)
570 return Store::Root().get(storeKeyPublicByRequestMethod(req
, method
));
574 storeGetPublicByRequest(HttpRequest
* req
)
576 StoreEntry
*e
= storeGetPublicByRequestMethod(req
, req
->method
);
578 if (e
== NULL
&& req
->method
== METHOD_HEAD
)
579 /* We can generate a HEAD reply from a cached GET object */
580 e
= storeGetPublicByRequestMethod(req
, METHOD_GET
);
588 static int key_counter
= 0;
590 if (++key_counter
< 0)
596 /* RBC 20050104 AFAICT this should become simpler:
597 * rather than reinserting with a special key it should be marked
598 * as 'released' and then cleaned up when refcounting indicates.
599 * the StoreHashIndex could well implement its 'released' in the
601 * Also, clean log writing should skip over ia,t
602 * Otherwise, we need a 'remove from the index but not the store
606 StoreEntry::setPrivateKey()
608 const cache_key
*newkey
;
610 if (key
&& EBIT_TEST(flags
, KEY_PRIVATE
))
611 return; /* is already private */
615 storeDirSwapLog(this, SWAP_LOG_DEL
);
620 if (mem_obj
!= NULL
) {
621 mem_obj
->id
= getKeyCounter();
622 newkey
= storeKeyPrivate(mem_obj
->url
, mem_obj
->method
, mem_obj
->id
);
624 newkey
= storeKeyPrivate("JUNK", METHOD_NONE
, getKeyCounter());
627 assert(hash_lookup(store_table
, newkey
) == NULL
);
628 EBIT_SET(flags
, KEY_PRIVATE
);
633 StoreEntry::setPublicKey()
635 StoreEntry
*e2
= NULL
;
636 const cache_key
*newkey
;
638 if (key
&& !EBIT_TEST(flags
, KEY_PRIVATE
))
639 return; /* is already public */
644 * We can't make RELEASE_REQUEST objects public. Depending on
645 * when RELEASE_REQUEST gets set, we might not be swapping out
646 * the object. If we're not swapping out, then subsequent
647 * store clients won't be able to access object data which has
648 * been freed from memory.
650 * If RELEASE_REQUEST is set, then ENTRY_CACHABLE should not
651 * be set, and StoreEntry::setPublicKey() should not be called.
653 #if MORE_DEBUG_OUTPUT
655 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
656 debugs(20, 1, "assertion failed: RELEASE key " << key
<< ", url " << mem_obj
->url
);
660 assert(!EBIT_TEST(flags
, RELEASE_REQUEST
));
662 if (mem_obj
->request
) {
663 HttpRequest
*request
= mem_obj
->request
;
665 if (!mem_obj
->vary_headers
) {
666 /* First handle the case where the object no longer varies */
667 safe_free(request
->vary_headers
);
669 if (request
->vary_headers
&& strcmp(request
->vary_headers
, mem_obj
->vary_headers
) != 0) {
670 /* Oops.. the variance has changed. Kill the base object
671 * to record the new variance key
673 safe_free(request
->vary_headers
); /* free old "bad" variance key */
674 StoreEntry
*pe
= storeGetPublic(mem_obj
->url
, mem_obj
->method
);
680 /* Make sure the request knows the variance status */
681 if (!request
->vary_headers
) {
682 const char *vary
= httpMakeVaryMark(request
, mem_obj
->getReply());
685 request
->vary_headers
= xstrdup(vary
);
689 if (mem_obj
->vary_headers
&& !storeGetPublic(mem_obj
->url
, mem_obj
->method
)) {
690 /* Create "vary" base object */
692 StoreEntry
*pe
= storeCreateEntry(mem_obj
->url
, mem_obj
->log_url
, request
->flags
, request
->method
);
693 /* We are allowed to do this typecast */
694 HttpReply
*rep
= new HttpReply
;
695 rep
->setHeaders(HTTP_OK
, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime
+ 100000);
696 vary
= mem_obj
->getReply()->header
.getList(HDR_VARY
);
699 /* Again, we own this structure layout */
700 rep
->header
.putStr(HDR_VARY
, vary
.termedBuf());
704 #if X_ACCELERATOR_VARY
705 vary
= mem_obj
->getReply()->header
.getList(HDR_X_ACCELERATOR_VARY
);
707 if (vary
.defined()) {
708 /* Again, we own this structure layout */
709 rep
->header
.putStr(HDR_X_ACCELERATOR_VARY
, vary
.termedBuf());
714 pe
->replaceHttpReply(rep
);
725 newkey
= storeKeyPublicByRequest(mem_obj
->request
);
727 newkey
= storeKeyPublic(mem_obj
->url
, mem_obj
->method
);
729 if ((e2
= (StoreEntry
*) hash_lookup(store_table
, newkey
))) {
730 debugs(20, 3, "StoreEntry::setPublicKey: Making old '" << mem_obj
->url
<< "' private.");
734 if (mem_obj
->request
)
735 newkey
= storeKeyPublicByRequest(mem_obj
->request
);
737 newkey
= storeKeyPublic(mem_obj
->url
, mem_obj
->method
);
743 EBIT_CLR(flags
, KEY_PRIVATE
);
748 storeDirSwapLog(this, SWAP_LOG_ADD
);
752 storeCreateEntry(const char *url
, const char *log_url
, request_flags flags
, const HttpRequestMethod
& method
)
754 StoreEntry
*e
= NULL
;
755 MemObject
*mem
= NULL
;
756 debugs(20, 3, "storeCreateEntry: '" << url
<< "'");
758 e
= new StoreEntry(url
, log_url
);
759 e
->lock_count
= 1; /* Note lock here w/o calling storeLock() */
761 mem
->method
= method
;
763 if (neighbors_do_private_keys
|| !flags
.hierarchical
)
768 if (flags
.cachable
) {
769 EBIT_SET(e
->flags
, ENTRY_CACHABLE
);
770 EBIT_CLR(e
->flags
, RELEASE_REQUEST
);
772 /* StoreEntry::releaseRequest() clears ENTRY_CACHABLE */
776 e
->store_status
= STORE_PENDING
;
777 e
->setMemStatus(NOT_IN_MEMORY
);
778 e
->swap_status
= SWAPOUT_NONE
;
782 e
->lastref
= squid_curtime
;
783 e
->timestamp
= -1; /* set in StoreEntry::timestampsSet() */
784 e
->ping_status
= PING_NONE
;
785 EBIT_SET(e
->flags
, ENTRY_VALIDATED
);
789 /* Mark object as expired */
791 StoreEntry::expireNow()
793 debugs(20, 3, "StoreEntry::expireNow: '" << getMD5Text() << "'");
794 expires
= squid_curtime
;
798 storeWriteComplete (void *data
, StoreIOBuffer wroteBuffer
)
800 PROF_start(storeWriteComplete
);
801 StoreEntry
*e
= (StoreEntry
*)data
;
803 if (EBIT_TEST(e
->flags
, DELAY_SENDING
)) {
804 PROF_stop(storeWriteComplete
);
809 PROF_stop(storeWriteComplete
);
813 StoreEntry::write (StoreIOBuffer writeBuffer
)
815 assert(mem_obj
!= NULL
);
816 /* This assert will change when we teach the store to update */
817 PROF_start(StoreEntry_write
);
818 assert(store_status
== STORE_PENDING
);
820 if (!writeBuffer
.length
) {
821 /* the headers are received already, but we have not received
822 * any body data. There are BROKEN abuses of HTTP which require
823 * the headers to be passed along before any body data - see
824 * http://developer.apple.com/documentation/QuickTime/QTSS/Concepts/chapter_2_section_14.html
825 * for an example of such bad behaviour. To accomodate this, if
826 * we have a empty write arrive, we flush to our clients.
829 PROF_stop(StoreEntry_write
);
834 debugs(20, 5, "storeWrite: writing " << writeBuffer
.length
<< " bytes for '" << getMD5Text() << "'");
835 PROF_stop(StoreEntry_write
);
836 storeGetMemSpace(writeBuffer
.length
);
837 mem_obj
->write (writeBuffer
, storeWriteComplete
, this);
840 /* Append incoming data from a primary server to an entry. */
842 StoreEntry::append(char const *buf
, int len
)
844 assert(mem_obj
!= NULL
);
846 assert(store_status
== STORE_PENDING
);
848 StoreIOBuffer tempBuffer
;
849 tempBuffer
.data
= (char *)buf
;
850 tempBuffer
.length
= len
;
852 * XXX sigh, offset might be < 0 here, but it gets "corrected"
853 * later. This offset crap is such a mess.
855 tempBuffer
.offset
= mem_obj
->endOffset() - (getReply() ? getReply()->hdr_sz
: 0);
861 storeAppendPrintf(StoreEntry
* e
, const char *fmt
,...)
866 storeAppendVPrintf(e
, fmt
, args
);
870 /* used be storeAppendPrintf and Packer */
872 storeAppendVPrintf(StoreEntry
* e
, const char *fmt
, va_list vargs
)
874 LOCAL_ARRAY(char, buf
, 4096);
876 vsnprintf(buf
, 4096, fmt
, vargs
);
877 e
->append(buf
, strlen(buf
));
880 struct _store_check_cachable_hist
{
884 int not_entry_cachable
;
885 int wrong_content_length
;
890 int too_many_open_files
;
891 int too_many_open_fds
;
897 } store_check_cachable_hist
;
900 storeTooManyDiskFilesOpen(void)
902 if (Config
.max_open_disk_fds
== 0)
905 if (store_open_disk_fd
> Config
.max_open_disk_fds
)
912 StoreEntry::checkTooSmall()
914 if (EBIT_TEST(flags
, ENTRY_SPECIAL
))
917 if (STORE_OK
== store_status
)
918 if (mem_obj
->object_sz
< 0 ||
919 mem_obj
->object_sz
< Config
.Store
.minObjectSize
)
921 if (getReply()->content_length
> -1)
922 if (getReply()->content_length
< Config
.Store
.minObjectSize
)
928 StoreEntry::checkCachable()
930 #if CACHE_ALL_METHODS
932 if (mem_obj
->method
!= METHOD_GET
) {
933 debugs(20, 2, "StoreEntry::checkCachable: NO: non-GET method");
934 store_check_cachable_hist
.no
.non_get
++;
937 if (store_status
== STORE_OK
&& EBIT_TEST(flags
, ENTRY_BAD_LENGTH
)) {
938 debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
939 store_check_cachable_hist
.no
.wrong_content_length
++;
940 } else if (!EBIT_TEST(flags
, ENTRY_CACHABLE
)) {
941 debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
942 store_check_cachable_hist
.no
.not_entry_cachable
++;
943 } else if (EBIT_TEST(flags
, ENTRY_NEGCACHED
)) {
944 debugs(20, 3, "StoreEntry::checkCachable: NO: negative cached");
945 store_check_cachable_hist
.no
.negative_cached
++;
946 return 0; /* avoid release call below */
947 } else if ((getReply()->content_length
> 0 &&
948 getReply()->content_length
949 > Config
.Store
.maxObjectSize
) ||
950 mem_obj
->endOffset() > Config
.Store
.maxObjectSize
) {
951 debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
952 store_check_cachable_hist
.no
.too_big
++;
953 } else if (getReply()->content_length
> Config
.Store
.maxObjectSize
) {
954 debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
955 store_check_cachable_hist
.no
.too_big
++;
956 } else if (checkTooSmall()) {
957 debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
958 store_check_cachable_hist
.no
.too_small
++;
959 } else if (EBIT_TEST(flags
, KEY_PRIVATE
)) {
960 debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
961 store_check_cachable_hist
.no
.private_key
++;
962 } else if (swap_status
!= SWAPOUT_NONE
) {
964 * here we checked the swap_status because the remaining
965 * cases are only relevant only if we haven't started swapping
966 * out the object yet.
969 } else if (storeTooManyDiskFilesOpen()) {
970 debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
971 store_check_cachable_hist
.no
.too_many_open_files
++;
972 } else if (fdNFree() < RESERVED_FD
) {
973 debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
974 store_check_cachable_hist
.no
.too_many_open_fds
++;
976 store_check_cachable_hist
.yes
.Default
++;
981 /* StoreEntry::releaseRequest() cleared ENTRY_CACHABLE */
986 storeCheckCachableStats(StoreEntry
*sentry
)
988 storeAppendPrintf(sentry
, "Category\t Count\n");
990 #if CACHE_ALL_METHODS
992 storeAppendPrintf(sentry
, "no.non_get\t%d\n",
993 store_check_cachable_hist
.no
.non_get
);
996 storeAppendPrintf(sentry
, "no.not_entry_cachable\t%d\n",
997 store_check_cachable_hist
.no
.not_entry_cachable
);
998 storeAppendPrintf(sentry
, "no.wrong_content_length\t%d\n",
999 store_check_cachable_hist
.no
.wrong_content_length
);
1000 storeAppendPrintf(sentry
, "no.negative_cached\t%d\n",
1001 store_check_cachable_hist
.no
.negative_cached
);
1002 storeAppendPrintf(sentry
, "no.too_big\t%d\n",
1003 store_check_cachable_hist
.no
.too_big
);
1004 storeAppendPrintf(sentry
, "no.too_small\t%d\n",
1005 store_check_cachable_hist
.no
.too_small
);
1006 storeAppendPrintf(sentry
, "no.private_key\t%d\n",
1007 store_check_cachable_hist
.no
.private_key
);
1008 storeAppendPrintf(sentry
, "no.too_many_open_files\t%d\n",
1009 store_check_cachable_hist
.no
.too_many_open_files
);
1010 storeAppendPrintf(sentry
, "no.too_many_open_fds\t%d\n",
1011 store_check_cachable_hist
.no
.too_many_open_fds
);
1012 storeAppendPrintf(sentry
, "yes.default\t%d\n",
1013 store_check_cachable_hist
.yes
.Default
);
1017 StoreEntry::complete()
1019 debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1021 if (store_status
!= STORE_PENDING
) {
1023 * if we're not STORE_PENDING, then probably we got aborted
1024 * and there should be NO clients on this entry
1026 assert(EBIT_TEST(flags
, ENTRY_ABORTED
));
1027 assert(mem_obj
->nclients
== 0);
1031 /* This is suspect: mem obj offsets include the headers. do we adjust for that
1032 * in use of object_sz?
1034 mem_obj
->object_sz
= mem_obj
->endOffset();
1036 store_status
= STORE_OK
;
1038 assert(mem_status
== NOT_IN_MEMORY
);
1040 if (!validLength()) {
1041 EBIT_SET(flags
, ENTRY_BAD_LENGTH
);
1045 #if USE_CACHE_DIGESTS
1046 if (mem_obj
->request
)
1047 mem_obj
->request
->hier
.store_complete_stop
= current_time
;
1051 * We used to call invokeHandlers, then storeSwapOut. However,
1052 * Madhukar Reddy <myreddy@persistence.com> reported that
1053 * responses without content length would sometimes get released
1054 * in client_side, thinking that the response is incomplete.
1060 * Someone wants to abort this transfer. Set the reason in the
1061 * request structure, call the server-side callback and mark the
1062 * entry for releasing
1067 statCounter
.aborted_requests
++;
1068 assert(store_status
== STORE_PENDING
);
1069 assert(mem_obj
!= NULL
);
1070 debugs(20, 6, "storeAbort: " << getMD5Text());
1072 lock(); /* lock while aborting */
1077 EBIT_SET(flags
, ENTRY_ABORTED
);
1079 setMemStatus(NOT_IN_MEMORY
);
1081 store_status
= STORE_OK
;
1084 * We assign an object length here. The only other place we assign
1085 * the object length is in storeComplete()
1087 /* RBC: What do we need an object length for? we've just aborted the
1088 * request, the request is private and negatively cached. Surely
1089 * the object length is inappropriate to set.
1091 mem_obj
->object_sz
= mem_obj
->endOffset();
1093 /* Notify the server side */
1097 * Should we check abort.data for validity?
1099 if (mem_obj
->abort
.callback
) {
1100 if (!cbdataReferenceValid(mem_obj
->abort
.data
))
1101 debugs(20,1,HERE
<< "queueing event when abort.data is not valid");
1102 eventAdd("mem_obj->abort.callback",
1103 mem_obj
->abort
.callback
,
1104 mem_obj
->abort
.data
,
1110 /* XXX Should we reverse these two, so that there is no
1111 * unneeded disk swapping triggered?
1113 /* Notify the client side */
1116 /* Close any swapout file */
1119 unlock(); /* unlock */
1123 * Clear Memory storage to accommodate the given object len
1126 storeGetMemSpace(int size
)
1128 PROF_start(storeGetMemSpace
);
1129 StoreEntry
*e
= NULL
;
1131 static time_t last_check
= 0;
1132 size_t pages_needed
;
1133 RemovalPurgeWalker
*walker
;
1135 if (squid_curtime
== last_check
) {
1136 PROF_stop(storeGetMemSpace
);
1140 last_check
= squid_curtime
;
1142 pages_needed
= (size
/ SM_PAGE_SIZE
) + 1;
1144 if (mem_node::InUseCount() + pages_needed
< store_pages_max
) {
1145 PROF_stop(storeGetMemSpace
);
1149 debugs(20, 2, "storeGetMemSpace: Starting, need " << pages_needed
<<
1152 /* XXX what to set as max_scan here? */
1153 walker
= mem_policy
->PurgeInit(mem_policy
, 100000);
1155 while ((e
= walker
->Next(walker
))) {
1159 if (mem_node::InUseCount() + pages_needed
< store_pages_max
)
1163 walker
->Done(walker
);
1164 debugs(20, 3, "storeGetMemSpace stats:");
1165 debugs(20, 3, " " << std::setw(6) << hot_obj_count
<< " HOT objects");
1166 debugs(20, 3, " " << std::setw(6) << released
<< " were released");
1167 PROF_stop(storeGetMemSpace
);
1171 /* thunk through to Store::Root().maintain(). Note that this would be better still
1172 * if registered against the root store itself, but that requires more complex
1173 * update logic - bigger fish to fry first. Long term each store when
1174 * it becomes active will self register
1177 Store::Maintain(void *notused
)
1179 Store::Root().maintain();
1181 /* Reregister a maintain event .. */
1182 eventAdd("MaintainSwapSpace", Maintain
, NULL
, 1.0, 1);
1186 /* The maximum objects to scan for maintain storage space */
1187 #define MAINTAIN_MAX_SCAN 1024
1188 #define MAINTAIN_MAX_REMOVE 64
1191 * This routine is to be called by main loop in main.c.
1192 * It removes expired objects on only one bucket for each time called.
1194 * This should get called 1/s from main().
1197 StoreController::maintain()
1199 static time_t last_warn_time
= 0;
1201 PROF_start(storeMaintainSwapSpace
);
1202 swapDir
->maintain();
1204 /* this should be emitted by the oversize dir, not globally */
1206 if (store_swap_size
> Store::Root().maxSize()) {
1207 if (squid_curtime
- last_warn_time
> 10) {
1208 debugs(20, 0, "WARNING: Disk space over limit: " << store_swap_size
<< " KB > "
1209 << Store::Root().maxSize() << " KB");
1210 last_warn_time
= squid_curtime
;
1214 PROF_stop(storeMaintainSwapSpace
);
1217 /* release an object from a cache */
1219 StoreEntry::release()
1221 PROF_start(storeRelease
);
1222 debugs(20, 3, "storeRelease: Releasing: '" << getMD5Text() << "'");
1223 /* If, for any reason we can't discard this object because of an
1224 * outstanding request, mark it for pending release */
1228 debugs(20, 3, "storeRelease: Only setting RELEASE_REQUEST bit");
1230 PROF_stop(storeRelease
);
1234 if (StoreController::store_dirs_rebuilding
&& swap_filen
> -1) {
1240 if (swap_filen
> -1) {
1242 * Fake a call to StoreEntry->lock() When rebuilding is done,
1243 * we'll just call StoreEntry->unlock() on these.
1247 LateReleaseStack
.push_back(this);
1248 PROF_stop(storeRelease
);
1251 destroyStoreEntry(static_cast<hash_link
*>(this));
1255 storeLog(STORE_LOG_RELEASE
, this);
1257 if (swap_filen
> -1) {
1260 if (swap_status
== SWAPOUT_DONE
)
1261 if (EBIT_TEST(flags
, ENTRY_VALIDATED
))
1262 store()->updateSize(swap_file_sz
, -1);
1264 if (!EBIT_TEST(flags
, KEY_PRIVATE
))
1265 storeDirSwapLog(this, SWAP_LOG_DEL
);
1268 /* From 2.4. I think we do this in storeUnlink? */
1269 storeSwapFileNumberSet(this, -1);
1275 setMemStatus(NOT_IN_MEMORY
);
1276 destroyStoreEntry(static_cast<hash_link
*>(this));
1277 PROF_stop(storeRelease
);
1281 storeLateRelease(void *unused
)
1287 if (StoreController::store_dirs_rebuilding
) {
1288 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 1.0, 1);
1292 for (i
= 0; i
< 10; i
++) {
1293 e
= LateReleaseStack
.pop();
1297 debugs(20, 1, "storeLateRelease: released " << n
<< " objects");
1305 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 0.0, 1);
1308 /* return 1 if a store entry is locked */
1310 StoreEntry::locked() const
1315 if (swap_status
== SWAPOUT_WRITING
)
1318 if (store_status
== STORE_PENDING
)
1322 * SPECIAL, PUBLIC entries should be "locked"
1324 if (EBIT_TEST(flags
, ENTRY_SPECIAL
))
1325 if (!EBIT_TEST(flags
, KEY_PRIVATE
))
1332 StoreEntry::validLength() const
1335 const HttpReply
*reply
;
1336 assert(mem_obj
!= NULL
);
1338 debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1339 debugs(20, 5, "storeEntryValidLength: object_len = " <<
1341 debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply
->hdr_sz
);
1342 debugs(20, 5, "storeEntryValidLength: content_length = " << reply
->content_length
);
1344 if (reply
->content_length
< 0) {
1345 debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1349 if (reply
->hdr_sz
== 0) {
1350 debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1354 if (mem_obj
->method
== METHOD_HEAD
) {
1355 debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1359 if (reply
->sline
.status
== HTTP_NOT_MODIFIED
)
1362 if (reply
->sline
.status
== HTTP_NO_CONTENT
)
1365 diff
= reply
->hdr_sz
+ reply
->content_length
- objectLen();
1370 debugs(20, 3, "storeEntryValidLength: " << (diff
< 0 ? -diff
: diff
) << " bytes too " << (diff
< 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1376 storeRegisterWithCacheManager(void)
1378 Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats
, 0, 1);
1379 Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create
, 0, 1);
1380 Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1381 storeCheckCachableStats
, 0, 1);
1388 mem_policy
= createRemovalPolicy(Config
.memPolicy
);
1391 eventAdd("storeLateRelease", storeLateRelease
, NULL
, 1.0, 1);
1392 Store::Root().init();
1393 storeRebuildStart();
1395 storeRegisterWithCacheManager();
1399 storeConfigure(void)
1401 store_swap_high
= (long) (((float) Store::Root().maxSize() *
1402 (float) Config
.Swap
.highWaterMark
) / (float) 100);
1403 store_swap_low
= (long) (((float) Store::Root().maxSize() *
1404 (float) Config
.Swap
.lowWaterMark
) / (float) 100);
1405 store_pages_max
= Config
.memMaxSize
/ sizeof(mem_node
);
1409 StoreEntry::keepInMemory() const
1411 if (mem_obj
== NULL
)
1414 if (mem_obj
->data_hdr
.size() == 0)
1417 if (mem_obj
->inmem_lo
!= 0)
1420 if (!Config
.onoff
.memory_cache_first
&& swap_status
== SWAPOUT_DONE
&& refcount
== 1)
1427 StoreEntry::checkNegativeHit() const
1429 if (!EBIT_TEST(flags
, ENTRY_NEGCACHED
))
1432 if (expires
<= squid_curtime
)
1435 if (store_status
!= STORE_OK
)
1442 * Set object for negative caching.
1443 * Preserves any expiry information given by the server.
1444 * In absence of proper expiry info it will set to expire immediately,
1445 * or with HTTP-violations enabled the configured negative-TTL is observed
1448 StoreEntry::negativeCache()
1451 #if USE_HTTP_VIOLATIONS
1452 expires
= squid_curtime
+ Config
.negativeTtl
;
1454 expires
= squid_curtime
;
1456 EBIT_SET(flags
, ENTRY_NEGCACHED
);
1460 storeFreeMemory(void)
1463 #if USE_CACHE_DIGESTS
1466 cacheDigestDestroy(store_digest
);
1470 store_digest
= NULL
;
1474 expiresMoreThan(time_t expires
, time_t when
)
1476 if (expires
< 0) /* No Expires given */
1479 return (expires
> (squid_curtime
+ when
));
1483 StoreEntry::validToSend() const
1485 if (EBIT_TEST(flags
, RELEASE_REQUEST
))
1488 if (EBIT_TEST(flags
, ENTRY_NEGCACHED
))
1489 if (expires
<= squid_curtime
)
1492 if (EBIT_TEST(flags
, ENTRY_ABORTED
))
1499 StoreEntry::timestampsSet()
1501 const HttpReply
*reply
= getReply();
1502 time_t served_date
= reply
->date
;
1503 int age
= reply
->header
.getInt(HDR_AGE
);
1504 /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1505 /* make sure that 0 <= served_date <= squid_curtime */
1507 if (served_date
< 0 || served_date
> squid_curtime
)
1508 served_date
= squid_curtime
;
1511 * Compensate with Age header if origin server clock is ahead
1512 * of us and there is a cache in between us and the origin
1513 * server. But DONT compensate if the age value is larger than
1514 * squid_curtime because it results in a negative served_date.
1516 if (age
> squid_curtime
- served_date
)
1517 if (squid_curtime
> age
)
1518 served_date
= squid_curtime
- age
;
1520 // compensate for Squid-to-server and server-to-Squid delays
1521 if (mem_obj
&& mem_obj
->request
) {
1522 const time_t request_sent
=
1523 mem_obj
->request
->hier
.peer_http_request_sent
.tv_sec
;
1524 if (0 < request_sent
&& request_sent
< squid_curtime
)
1525 served_date
-= (squid_curtime
- request_sent
);
1528 if (reply
->expires
> 0 && reply
->date
> -1)
1529 expires
= served_date
+ (reply
->expires
- reply
->date
);
1531 expires
= reply
->expires
;
1533 lastmod
= reply
->last_modified
;
1535 timestamp
= served_date
;
1539 StoreEntry::registerAbort(STABH
* cb
, void *data
)
1542 assert(mem_obj
->abort
.callback
== NULL
);
1543 mem_obj
->abort
.callback
= cb
;
1544 mem_obj
->abort
.data
= cbdataReference(data
);
1548 StoreEntry::unregisterAbort()
1551 if (mem_obj
->abort
.callback
) {
1552 mem_obj
->abort
.callback
= NULL
;
1553 cbdataReferenceDone(mem_obj
->abort
.data
);
1558 StoreEntry::dump(int l
) const
1560 debugs(20, l
, "StoreEntry->key: " << getMD5Text());
1561 debugs(20, l
, "StoreEntry->next: " << next
);
1562 debugs(20, l
, "StoreEntry->mem_obj: " << mem_obj
);
1563 debugs(20, l
, "StoreEntry->timestamp: " << timestamp
);
1564 debugs(20, l
, "StoreEntry->lastref: " << lastref
);
1565 debugs(20, l
, "StoreEntry->expires: " << expires
);
1566 debugs(20, l
, "StoreEntry->lastmod: " << lastmod
);
1567 debugs(20, l
, "StoreEntry->swap_file_sz: " << swap_file_sz
);
1568 debugs(20, l
, "StoreEntry->refcount: " << refcount
);
1569 debugs(20, l
, "StoreEntry->flags: " << storeEntryFlags(this));
1570 debugs(20, l
, "StoreEntry->swap_dirn: " << swap_dirn
);
1571 debugs(20, l
, "StoreEntry->swap_filen: " << swap_filen
);
1572 debugs(20, l
, "StoreEntry->lock_count: " << lock_count
);
1573 debugs(20, l
, "StoreEntry->mem_status: " << mem_status
);
1574 debugs(20, l
, "StoreEntry->ping_status: " << ping_status
);
1575 debugs(20, l
, "StoreEntry->store_status: " << store_status
);
1576 debugs(20, l
, "StoreEntry->swap_status: " << swap_status
);
1580 * NOTE, this function assumes only two mem states
1583 StoreEntry::setMemStatus(mem_status_t new_status
)
1585 if (new_status
== mem_status
)
1588 assert(mem_obj
!= NULL
);
1590 if (new_status
== IN_MEMORY
) {
1591 assert(mem_obj
->inmem_lo
== 0);
1593 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1594 debugs(20, 4, "StoreEntry::setMemStatus: not inserting special " << mem_obj
->url
<< " into policy");
1596 mem_policy
->Add(mem_policy
, this, &mem_obj
->repl
);
1597 debugs(20, 4, "StoreEntry::setMemStatus: inserted mem node " << mem_obj
->url
);
1602 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1603 debugs(20, 4, "StoreEntry::setMemStatus: special entry " << mem_obj
->url
);
1605 mem_policy
->Remove(mem_policy
, this, &mem_obj
->repl
);
1606 debugs(20, 4, "StoreEntry::setMemStatus: removed mem node " << mem_obj
->url
);
1612 mem_status
= new_status
;
1616 StoreEntry::url() const
1619 return "[null_entry]";
1620 else if (mem_obj
== NULL
)
1621 return "[null_mem_obj]";
1623 return mem_obj
->url
;
1627 StoreEntry::createMemObject(const char *aUrl
, const char *aLogUrl
)
1632 mem_obj
= new MemObject(aUrl
, aLogUrl
);
1635 /* this just sets DELAY_SENDING */
1637 StoreEntry::buffer()
1639 EBIT_SET(flags
, DELAY_SENDING
);
1642 /* this just clears DELAY_SENDING and Invokes the handlers */
1646 if (EBIT_TEST(flags
, DELAY_SENDING
)) {
1647 EBIT_CLR(flags
, DELAY_SENDING
);
1653 StoreEntry::objectLen() const
1655 assert(mem_obj
!= NULL
);
1656 return mem_obj
->object_sz
;
1660 StoreEntry::contentLen() const
1662 assert(mem_obj
!= NULL
);
1663 assert(getReply() != NULL
);
1664 return objectLen() - getReply()->hdr_sz
;
1668 StoreEntry::getReply () const
1670 if (NULL
== mem_obj
)
1673 return mem_obj
->getReply();
1680 debugs(20, 3, "StoreEntry::reset: " << url());
1682 HttpReply
*rep
= (HttpReply
*) getReply(); // bypass const
1684 expires
= lastmod
= timestamp
= -1;
1690 * This routine calls the SETUP routine for each fs type.
1691 * I don't know where the best place for this is, and I'm not going to shuffle
1692 * around large chunks of code right now (that can be done once its working.)
1701 * called to add another store removal policy module
1704 storeReplAdd(const char *type
, REMOVALPOLICYCREATE
* create
)
1708 /* find the number of currently known repl types */
1709 for (i
= 0; storerepl_list
&& storerepl_list
[i
].typestr
; i
++) {
1710 if (strcmp(storerepl_list
[i
].typestr
, type
) == 0) {
1711 debugs(20, 1, "WARNING: Trying to load store replacement policy " << type
<< " twice.");
1716 /* add the new type */
1717 storerepl_list
= static_cast<storerepl_entry_t
*>(xrealloc(storerepl_list
, (i
+ 2) * sizeof(storerepl_entry_t
)));
1719 memset(&storerepl_list
[i
+ 1], 0, sizeof(storerepl_entry_t
));
1721 storerepl_list
[i
].typestr
= type
;
1723 storerepl_list
[i
].create
= create
;
1727 * Create a removal policy instance
1730 createRemovalPolicy(RemovalPolicySettings
* settings
)
1732 storerepl_entry_t
*r
;
1734 for (r
= storerepl_list
; r
&& r
->typestr
; r
++) {
1735 if (strcmp(r
->typestr
, settings
->type
) == 0)
1736 return r
->create(settings
->args
);
1739 debugs(20, 1, "ERROR: Unknown policy " << settings
->type
);
1740 debugs(20, 1, "ERROR: Be sure to have set cache_replacement_policy");
1741 debugs(20, 1, "ERROR: and memory_replacement_policy in squid.conf!");
1742 fatalf("ERROR: Unknown policy %s\n", settings
->type
);
1743 return NULL
; /* NOTREACHED */
1748 storeSwapFileNumberSet(StoreEntry
* e
, sfileno filn
)
1750 if (e
->swap_file_number
== filn
)
1755 storeDirMapBitReset(e
->swap_file_number
);
1756 storeDirLRUDelete(e
);
1757 e
->swap_file_number
= -1;
1759 assert(-1 == e
->swap_file_number
);
1760 storeDirMapBitSet(e
->swap_file_number
= filn
);
1769 * Replace a store entry with
1770 * a new reply. This eats the reply.
1773 StoreEntry::replaceHttpReply(HttpReply
*rep
)
1775 debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1779 debugs(20, 0, "Attempt to replace object with no in-memory representation");
1783 mem_obj
->replaceHttpReply(rep
);
1785 /* TODO: when we store headers serparately remove the header portion */
1786 /* TODO: mark the length of the headers ? */
1787 /* We ONLY want the headers */
1788 packerToStoreInit(&p
, this);
1792 getReply()->packHeadersInto(&p
);
1794 rep
->hdr_sz
= mem_obj
->endOffset();
1796 httpBodyPackInto(&getReply()->body
, &p
);
1803 StoreEntry::getSerialisedMetaData()
1805 StoreMeta
*tlv_list
= storeSwapMetaBuild(this);
1807 char *result
= storeSwapMetaPack(tlv_list
, &swap_hdr_sz
);
1808 storeSwapTLVFree(tlv_list
);
1809 assert (swap_hdr_sz
>= 0);
1810 mem_obj
->swap_hdr_sz
= (size_t) swap_hdr_sz
;
1815 StoreEntry::swapoutPossible()
1817 /* should we swap something out to disk? */
1818 debugs(20, 7, "storeSwapOut: " << url());
1819 debugs(20, 7, "storeSwapOut: store_status = " << storeStatusStr
[store_status
]);
1821 if (EBIT_TEST(flags
, ENTRY_ABORTED
)) {
1822 assert(EBIT_TEST(flags
, RELEASE_REQUEST
));
1827 if (EBIT_TEST(flags
, ENTRY_SPECIAL
)) {
1828 debugs(20, 3, "storeSwapOut: " << url() << " SPECIAL");
1836 StoreEntry::trimMemory()
1840 * Bug #1943. We must not let go any data for IN_MEMORY
1841 * objects. We have to wait until the mem_status changes.
1843 if (mem_status
== IN_MEMORY
)
1846 if (!swapOutAble()) {
1847 if (mem_obj
->policyLowestOffsetToKeep(0) == 0) {
1852 * Its not swap-able, and we're about to delete a chunk,
1853 * so we must make it PRIVATE. This is tricky/ugly because
1854 * for the most part, we treat swapable == cachable here.
1857 mem_obj
->trimUnSwappable ();
1859 mem_obj
->trimSwappable ();
1864 StoreEntry::modifiedSince(HttpRequest
* request
) const
1867 time_t mod_time
= lastmod
;
1870 mod_time
= timestamp
;
1872 debugs(88, 3, "modifiedSince: '" << url() << "'");
1874 debugs(88, 3, "modifiedSince: mod_time = " << mod_time
);
1879 /* Find size of the object */
1880 object_length
= getReply()->content_length
;
1882 if (object_length
< 0)
1883 object_length
= contentLen();
1885 if (mod_time
> request
->ims
) {
1886 debugs(88, 3, "--> YES: entry newer than client");
1888 } else if (mod_time
< request
->ims
) {
1889 debugs(88, 3, "--> NO: entry older than client");
1891 } else if (request
->imslen
< 0) {
1892 debugs(88, 3, "--> NO: same LMT, no client length");
1894 } else if (request
->imslen
== object_length
) {
1895 debugs(88, 3, "--> NO: same LMT, same length");
1898 debugs(88, 3, "--> YES: same LMT, different length");
1904 StoreEntry::hasIfMatchEtag(const HttpRequest
&request
) const
1906 const String reqETags
= request
.header
.getList(HDR_IF_MATCH
);
1907 return hasOneOfEtags(reqETags
, false);
1911 StoreEntry::hasIfNoneMatchEtag(const HttpRequest
&request
) const
1913 const String reqETags
= request
.header
.getList(HDR_IF_NONE_MATCH
);
1914 // weak comparison is allowed only for HEAD or full-body GET requests
1915 const bool allowWeakMatch
= !request
.flags
.range
&&
1916 (request
.method
== METHOD_GET
|| request
.method
== METHOD_HEAD
);
1917 return hasOneOfEtags(reqETags
, allowWeakMatch
);
1920 /// whether at least one of the request ETags matches entity ETag
1922 StoreEntry::hasOneOfEtags(const String
&reqETags
, const bool allowWeakMatch
) const
1924 const ETag repETag
= getReply()->header
.getETag(HDR_ETAG
);
1926 return strListIsMember(&reqETags
, "*", ',');
1928 bool matched
= false;
1929 const char *pos
= NULL
;
1932 while (!matched
&& strListGetItem(&reqETags
, ',', &item
, &ilen
, &pos
)) {
1933 if (!strncmp(item
, "*", ilen
))
1937 str
.append(item
, ilen
);
1939 if (etagParseInit(&reqETag
, str
.termedBuf())) {
1940 matched
= allowWeakMatch
? etagIsWeakEqual(repETag
, reqETag
) :
1941 etagIsStrongEqual(repETag
, reqETag
);
1949 StoreEntry::store() const
1951 assert(0 <= swap_dirn
&& swap_dirn
< Config
.cacheSwap
.n_configured
);
1952 return INDEXSD(swap_dirn
);
1956 StoreEntry::unlink()
1958 store()->unlink(*this);
1962 * return true if the entry is in a state where
1963 * it can accept more data (ie with write() method)
1966 StoreEntry::isAccepting() const
1968 if (STORE_PENDING
!= store_status
)
1971 if (EBIT_TEST(flags
, ENTRY_ABORTED
))
1977 /* NullStoreEntry */
1979 NullStoreEntry
NullStoreEntry::_instance
;
1982 NullStoreEntry::getInstance()
1988 NullStoreEntry::getMD5Text() const
1994 NullStoreEntry::operator delete(void*)
1996 fatal ("Attempt to delete NullStoreEntry\n");
2000 NullStoreEntry::getSerialisedMetaData()
2006 #include "Store.cci"