Squid Web Cache master
Loading...
Searching...
No Matches
store.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 20 Storage Manager */
10
11#include "squid.h"
13#include "base/IoManip.h"
14#include "base/PackableStream.h"
15#include "base/TextException.h"
16#include "CacheDigest.h"
17#include "CacheManager.h"
18#include "CollapsedForwarding.h"
19#include "comm/Connection.h"
20#include "comm/Read.h"
21#include "debug/Messages.h"
22#if HAVE_DISKIO_MODULE_IPCIO
24#endif
25#include "ETag.h"
26#include "event.h"
27#include "fde.h"
28#include "globals.h"
29#include "http.h"
30#include "HttpReply.h"
31#include "HttpRequest.h"
32#include "mem_node.h"
33#include "MemObject.h"
34#include "MemStore.h"
35#include "mgr/Registration.h"
36#include "mgr/StoreIoAction.h"
37#include "repl_modules.h"
38#include "RequestFlags.h"
39#include "sbuf/Stream.h"
40#include "SquidConfig.h"
41#include "StatCounters.h"
42#include "stmem.h"
43#include "Store.h"
44#include "store/Controller.h"
45#include "store/Disk.h"
46#include "store/Disks.h"
47#include "store/SwapMetaOut.h"
48#include "store_digest.h"
49#include "store_key_md5.h"
50#include "store_log.h"
51#include "store_rebuild.h"
52#include "StoreClient.h"
53#include "StoreIOState.h"
54#include "StrList.h"
55#include "swap_log_op.h"
56#include "tools.h"
57#if USE_DELAY_POOLS
58#include "DelayPools.h"
59#endif
60
64#include "mem/Allocator.h"
65#include "mem/Pool.h"
66
67#include <climits>
68#include <stack>
69
70#define REBUILD_TIMESTAMP_DELTA_MAX 2
71
72#define STORE_IN_MEM_BUCKETS (229)
73
74// TODO: Convert these string constants to enum string-arrays generated
75
76const char *memStatusStr[] = {
77 "NOT_IN_MEMORY",
78 "IN_MEMORY"
79};
80
81const char *pingStatusStr[] = {
82 "PING_NONE",
83 "PING_WAITING",
84 "PING_DONE"
85};
86
87const char *storeStatusStr[] = {
88 "STORE_OK",
89 "STORE_PENDING"
90};
91
92const char *swapStatusStr[] = {
93 "SWAPOUT_NONE",
94 "SWAPOUT_WRITING",
95 "SWAPOUT_DONE",
96 "SWAPOUT_FAILED"
97};
98
99/*
100 * This defines an repl type
101 */
102
104
109
111
112/*
113 * local function prototypes
114 */
115static int getKeyCounter(void);
118
119/*
120 * local variables
121 */
122static std::stack<StoreEntry*> LateReleaseStack;
124
125void
127{
128 assert(output);
129 Root().stat(*output);
130}
131
133static void
135{
136 assert(e);
137 PackableStream stream(*e);
139#if HAVE_DISKIO_MODULE_IPCIO
140 stream << "\n";
141 IpcIoFile::StatQueue(stream);
142#endif
143 stream.flush();
144}
145
146// XXX: new/delete operators need to be replaced with MEMPROXY_CLASS
147// definitions but doing so exposes bug 4370, and maybe 4354 and 4355
148void *
149StoreEntry::operator new (size_t bytecount)
150{
151 assert(bytecount == sizeof (StoreEntry));
152
153 if (!pool) {
154 pool = memPoolCreate ("StoreEntry", bytecount);
155 }
156
157 return pool->alloc();
158}
159
160void
161StoreEntry::operator delete (void *address)
162{
163 pool->freeOne(address);
164}
165
166bool
168{
169 /* This object can be cached for a long time */
170 return !EBIT_TEST(flags, RELEASE_REQUEST) && setPublicKey(scope);
171}
172
173void
174StoreEntry::makePrivate(const bool shareable)
175{
176 releaseRequest(shareable); /* delete object when not used */
177}
178
179void
186
187bool
189{
190 /* This object may be negatively cached */
191 if (makePublic()) {
193 return true;
194 }
195 return false;
196}
197
198size_t
200{
201 if (!pool)
202 return 0;
203 return pool->getInUseCount();
204}
205
206const char *
208{
209 return storeKeyText((const cache_key *)key);
210}
211
212size_t
213StoreEntry::bytesWanted (Range<size_t> const aRange, bool ignoreDelayPools) const
214{
215 if (mem_obj == nullptr)
216 return aRange.end;
217
218#if URL_CHECKSUM_DEBUG
219
220 mem_obj->checkUrlChecksum();
221
222#endif
223
225 return 0;
226
227 return mem_obj->mostBytesWanted(aRange.end, ignoreDelayPools);
228}
229
230bool
232{
233 if (mem_obj) {
234 const auto &reply = mem_obj->baseReply();
235 if (reply.pstate == Http::Message::psParsed) {
236 debugs(20, 7, reply.hdr_sz);
237 return true;
238 }
239 }
240 return false;
241}
242
243bool
245{
246 return (bytesWanted(Range<size_t>(0,INT_MAX)) == 0);
247}
248
249void
250StoreEntry::setNoDelay(bool const newValue)
251{
252 if (mem_obj)
253 mem_obj->setNoDelay(newValue);
254}
255
256// XXX: Type names mislead. STORE_DISK_CLIENT actually means that we should
257// open swapin file, aggressively trim memory, and ignore read-ahead gap.
258// It does not mean we will read from disk exclusively (or at all!).
259// STORE_MEM_CLIENT covers all other cases, including in-memory entries,
260// newly created entries, and entries not backed by disk or memory cache.
261// XXX: May create STORE_DISK_CLIENT with no disk caching configured.
262// XXX: Collapsed clients cannot predict their type.
265{
266 /* The needed offset isn't in memory
267 * XXX TODO: this is wrong for range requests
268 * as the needed offset may *not* be 0, AND
269 * offset 0 in the memory object is the HTTP headers.
270 */
271
273
274 debugs(20, 7, *this << " inmem_lo=" << mem_obj->inmem_lo);
275
276 if (mem_obj->inmem_lo)
277 return STORE_DISK_CLIENT;
278
280 /* I don't think we should be adding clients to aborted entries */
281 debugs(20, DBG_IMPORTANT, "storeClientType: adding to ENTRY_ABORTED entry");
282 return STORE_MEM_CLIENT;
283 }
284
285 if (swapoutFailed())
286 return STORE_MEM_CLIENT;
287
288 if (store_status == STORE_OK) {
289 /* the object has completed. */
290
291 if (mem_obj->inmem_lo == 0 && !isEmpty()) {
292 if (swappedOut()) {
293 debugs(20,7, mem_obj << " lo: " << mem_obj->inmem_lo << " hi: " << mem_obj->endOffset() << " size: " << mem_obj->object_sz);
294 if (mem_obj->endOffset() == mem_obj->object_sz) {
295 /* hot object fully swapped in (XXX: or swapped out?) */
296 return STORE_MEM_CLIENT;
297 }
298 } else {
299 /* Memory-only, or currently being swapped out */
300 return STORE_MEM_CLIENT;
301 }
302 }
303 debugs(20, 7, "STORE_OK STORE_DISK_CLIENT");
304 return STORE_DISK_CLIENT;
305 }
306
307 /* here and past, entry is STORE_PENDING */
308 /*
309 * If this is the first client, let it be the mem client
310 */
311 if (mem_obj->nclients == 0)
312 return STORE_MEM_CLIENT;
313
314 /*
315 * If there is no disk file to open yet, we must make this a
316 * mem client. If we can't open the swapin file before writing
317 * to the client, there is no guarantee that we will be able
318 * to open it later when we really need it.
319 */
321 return STORE_MEM_CLIENT;
322
323 // TODO: The above "must make this a mem client" logic contradicts "Slight
324 // weirdness" logic in store_client::doCopy() that converts hits to misses
325 // on startSwapin() failures. We should probably attempt to open a swapin
326 // file _here_ instead (and avoid STORE_DISK_CLIENT designation for clients
327 // that fail to do so). That would also address a similar problem with Rock
328 // store that does not yet support swapin during SWAPOUT_WRITING.
329
330 /*
331 * otherwise, make subsequent clients read from disk so they
332 * can not delay the first, and vice-versa.
333 */
334 debugs(20, 7, "STORE_PENDING STORE_DISK_CLIENT");
335 return STORE_DISK_CLIENT;
336}
339 mem_obj(nullptr),
340 timestamp(-1),
341 lastref(-1),
342 expires(-1),
343 lastModified_(-1),
344 swap_file_sz(0),
345 refcount(0),
346 flags(0),
347 swap_filen(-1),
348 swap_dirn(-1),
349 mem_status(NOT_IN_MEMORY),
350 ping_status(PING_NONE),
351 store_status(STORE_PENDING),
352 swap_status(SWAPOUT_NONE),
353 lock_count(0),
354 shareableWhenPrivate(false)
355{
356 debugs(20, 5, "StoreEntry constructed, this=" << this);
357}
358
360{
361 debugs(20, 5, "StoreEntry destructed, this=" << this);
362}
363
364#if USE_ADAPTATION
365void
367{
368 if (!deferredProducer)
369 deferredProducer = producer;
370 else
371 debugs(20, 5, "Deferred producer call is already set to: " <<
372 *deferredProducer << ", requested call: " << *producer);
373}
374
375void
377{
378 if (deferredProducer != nullptr) {
380 deferredProducer = nullptr;
381 }
382}
383#endif
384
385void
387{
388 debugs(20, 3, mem_obj << " in " << *this);
389
390 if (hasTransients())
392 if (hasMemStore())
394
395 if (auto memObj = mem_obj) {
397 mem_obj = nullptr;
398 delete memObj;
399 }
400}
401
402void
405 debugs(20, 3, "destroyStoreEntry: destroying " << data);
406 StoreEntry *e = static_cast<StoreEntry *>(static_cast<hash_link *>(data));
407 assert(e != nullptr);
408
409 if (e->hasDisk())
410 e->disk().disconnect(*e);
411
412 e->destroyMemObject();
413
414 e->hashDelete();
415
416 assert(e->key == nullptr);
417
418 delete e;
419}
420
421/* ----- INTERFACE BETWEEN STORAGE MANAGER AND HASH TABLE FUNCTIONS --------- */
422
423void
425{
426 debugs(20, 3, "StoreEntry::hashInsert: Inserting Entry " << *this << " key '" << storeKeyText(someKey) << "'");
427 assert(!key);
428 key = storeKeyDup(someKey);
429 hash_join(store_table, this);
430}
431
432void
434{
435 if (key) { // some test cases do not create keys and do not hashInsert()
437 storeKeyFree((const cache_key *)key);
438 key = nullptr;
439 }
440}
441
442/* -------------------------------------------------------------------------- */
443
444void
445StoreEntry::lock(const char *context)
446{
447 ++lock_count;
448 debugs(20, 3, context << " locked key " << getMD5Text() << ' ' << *this);
449}
450
451void
456
457void
458StoreEntry::releaseRequest(const bool shareable)
459{
460 debugs(20, 3, shareable << ' ' << *this);
461 if (!shareable)
462 shareableWhenPrivate = false; // may already be false
464 return;
465 setPrivateKey(shareable, true);
466}
467
468int
469StoreEntry::unlock(const char *context)
470{
471 debugs(20, 3, (context ? context : "somebody") <<
472 " unlocking key " << getMD5Text() << ' ' << *this);
473 assert(lock_count > 0);
474 --lock_count;
475
476 if (lock_count)
477 return (int) lock_count;
478
479 abandon(context);
480 return 0;
481}
482
485void
486StoreEntry::doAbandon(const char *context)
487{
488 debugs(20, 5, *this << " via " << (context ? context : "somebody"));
489 assert(!locked());
490 assert(storePendingNClients(this) == 0);
491
492 // Both aborted local writers and aborted local readers (of remote writers)
493 // are STORE_PENDING, but aborted readers should never release().
495 (store_status == STORE_PENDING && !Store::Root().transientsReader(*this))) {
496 this->release();
497 return;
498 }
499
500 Store::Root().handleIdleEntry(*this); // may delete us
501}
502
504storeGetPublic(const char *uri, const HttpRequestMethod& method)
505{
506 return Store::Root().find(storeKeyPublic(uri, method));
507}
508
511{
512 return Store::Root().find(storeKeyPublicByRequestMethod(req, method, keyScope));
513}
514
517{
518 StoreEntry *e = storeGetPublicByRequestMethod(req, req->method, keyScope);
519
520 if (e == nullptr && req->method == Http::METHOD_HEAD)
521 /* We can generate a HEAD reply from a cached GET object */
523
524 return e;
525}
526
527static int
529{
530 static int key_counter = 0;
531
532 if (++key_counter < 0)
533 key_counter = 1;
534
535 return key_counter;
536}
537
538/* RBC 20050104 AFAICT this should become simpler:
539 * rather than reinserting with a special key it should be marked
540 * as 'released' and then cleaned up when refcounting indicates.
541 * the StoreHashIndex could well implement its 'released' in the
542 * current manner.
543 * Also, clean log writing should skip over ia,t
544 * Otherwise, we need a 'remove from the index but not the store
545 * concept'.
546 */
547void
548StoreEntry::setPrivateKey(const bool shareable, const bool permanent)
549{
550 debugs(20, 3, shareable << permanent << ' ' << *this);
551 if (permanent)
552 EBIT_SET(flags, RELEASE_REQUEST); // may already be set
553 if (!shareable)
554 shareableWhenPrivate = false; // may already be false
555
557 return;
558
559 if (key) {
560 Store::Root().evictCached(*this); // all caches/workers will know
561 hashDelete();
562 }
563
564 if (mem_obj && mem_obj->hasUris())
566 const cache_key *newkey = storeKeyPrivate();
567
568 assert(hash_lookup(store_table, newkey) == nullptr);
570 shareableWhenPrivate = shareable;
571 hashInsert(newkey);
572}
573
574bool
576{
577 debugs(20, 3, *this);
578 if (key && !EBIT_TEST(flags, KEY_PRIVATE))
579 return true; // already public
580
582
583 /*
584 * We can't make RELEASE_REQUEST objects public. Depending on
585 * when RELEASE_REQUEST gets set, we might not be swapping out
586 * the object. If we're not swapping out, then subsequent
587 * store clients won't be able to access object data which has
588 * been freed from memory.
589 *
590 * If RELEASE_REQUEST is set, setPublicKey() should not be called.
591 */
592
594
595 try {
596 EntryGuard newVaryMarker(adjustVary(), "setPublicKey+failure");
597 const cache_key *pubKey = calcPublicKey(scope);
598 Store::Root().addWriting(this, pubKey);
599 forcePublicKey(pubKey);
600 newVaryMarker.unlockAndReset("setPublicKey+success");
601 return true;
602 } catch (const std::exception &ex) {
603 debugs(20, 2, "for " << *this << " failed: " << ex.what());
604 }
605 return false;
606}
607
608void
610{
611 if (!key || EBIT_TEST(flags, KEY_PRIVATE))
612 return; // probably the old public key was deleted or made private
613
614 // TODO: adjustVary() when collapsed revalidation supports that
615
616 const cache_key *newKey = calcPublicKey(ksDefault);
617 if (!storeKeyHashCmp(key, newKey))
618 return; // probably another collapsed revalidation beat us to this change
619
620 forcePublicKey(newKey);
621}
622
625void
627{
628 debugs(20, 3, storeKeyText(newkey) << " for " << *this);
630
631 if (StoreEntry *e2 = (StoreEntry *)hash_lookup(store_table, newkey)) {
632 assert(e2 != this);
633 debugs(20, 3, "releasing clashing " << *e2);
634 e2->release(true);
635 }
636
637 if (key)
638 hashDelete();
639
640 clearPrivate();
641
643 hashInsert(newkey);
644
645 if (hasDisk())
647}
648
651const cache_key *
658
666{
668
669 if (!mem_obj->request)
670 return nullptr;
671
673 const auto &reply = mem_obj->freshestReply();
674
676 /* First handle the case where the object no longer varies */
677 request->vary_headers.clear();
678 } else {
679 if (!request->vary_headers.isEmpty() && request->vary_headers.cmp(mem_obj->vary_headers) != 0) {
680 /* Oops.. the variance has changed. Kill the base object
681 * to record the new variance key
682 */
683 request->vary_headers.clear(); /* free old "bad" variance key */
685 pe->release(true);
686 }
687
688 /* Make sure the request knows the variance status */
689 if (request->vary_headers.isEmpty())
690 request->vary_headers = httpMakeVaryMark(request.getRaw(), &reply);
691 }
692
693 // TODO: storeGetPublic() calls below may create unlocked entries.
694 // We should add/use storeHas() API or lock/unlock those entries.
696 /* Create "vary" base object */
697 StoreEntry *pe = storeCreateEntry(mem_obj->storeId(), mem_obj->logUri(), request->flags, request->method);
698 // XXX: storeCreateEntry() already tries to make `pe` public under
699 // certain conditions. If those conditions do not apply to Vary markers,
700 // then refactor to call storeCreatePureEntry() above. Otherwise,
701 // refactor to simply check whether `pe` is already public below.
702 if (!pe->makePublic()) {
703 pe->unlock("StoreEntry::adjustVary+failed_makePublic");
704 throw TexcHere("failed to make Vary marker public");
705 }
706 /* We are allowed to do this typecast */
707 const HttpReplyPointer rep(new HttpReply);
708 rep->setHeaders(Http::scOkay, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
709 auto vary = reply.header.getList(Http::HdrType::VARY);
710
711 if (vary.size()) {
712 /* Again, we own this structure layout */
713 rep->header.putStr(Http::HdrType::VARY, vary.termedBuf());
714 vary.clean();
715 }
716
717#if X_ACCELERATOR_VARY
718 vary = reply.header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY);
719
720 if (vary.size() > 0) {
721 /* Again, we own this structure layout */
723 vary.clean();
724 }
725
726#endif
727 pe->replaceHttpReply(rep, false); // no write until timestampsSet()
728
729 pe->timestampsSet();
730
731 pe->startWriting(); // after timestampsSet()
732
733 pe->completeSuccessfully("wrote the entire Vary marker object");
734
735 return pe;
736 }
737 return nullptr;
738}
739
741storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod& method)
742{
743 StoreEntry *e = nullptr;
744 debugs(20, 3, "storeCreateEntry: '" << url << "'");
745
746 e = new StoreEntry();
747 e->createMemObject(url, log_url, method);
748
750 e->refcount = 0;
752 e->timestamp = -1; /* set in StoreEntry::timestampsSet() */
755 return e;
756}
757
759storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod& method)
760{
761 StoreEntry *e = storeCreatePureEntry(url, logUrl, method);
762 e->lock("storeCreateEntry");
763
764 if (!neighbors_do_private_keys && flags.hierarchical && flags.cachable && e->setPublicKey())
765 return e;
766
767 e->setPrivateKey(false, !flags.cachable);
768 return e;
769}
770
771/* Mark object as expired */
772void
774{
775 debugs(20, 3, "StoreEntry::expireNow: '" << getMD5Text() << "'");
777}
778
779void
781{
782 assert(mem_obj != nullptr);
783 /* This assert will change when we teach the store to update */
785
786 // XXX: caller uses content offset, but we also store headers
787 writeBuffer.offset += mem_obj->baseReply().hdr_sz;
788
789 debugs(20, 5, "storeWrite: writing " << writeBuffer.length << " bytes for '" << getMD5Text() << "'");
790 storeGetMemSpace(writeBuffer.length);
791 mem_obj->write(writeBuffer);
792
794 debugs(20, 3, "allow Store clients to get entry content after buffering too much for " << *this);
796 }
797
799}
800
801/* Append incoming data from a primary server to an entry. */
802void
803StoreEntry::append(char const *buf, int len)
804{
805 assert(mem_obj != nullptr);
806 assert(len >= 0);
808
809 StoreIOBuffer tempBuffer;
810 tempBuffer.data = (char *)buf;
811 tempBuffer.length = len;
812 /*
813 * XXX sigh, offset might be < 0 here, but it gets "corrected"
814 * later. This offset crap is such a mess.
815 */
816 tempBuffer.offset = mem_obj->endOffset() - mem_obj->baseReply().hdr_sz;
817 write(tempBuffer);
818}
819
820void
821StoreEntry::vappendf(const char *fmt, va_list vargs)
822{
823 LOCAL_ARRAY(char, buf, 4096);
824 *buf = 0;
825 int x;
826
827 va_list ap;
828 /* Fix of bug 753r. The value of vargs is undefined
829 * after vsnprintf() returns. Make a copy of vargs
830 * in case we loop around and call vsnprintf() again.
831 */
832 va_copy(ap,vargs);
833 errno = 0;
834 if ((x = vsnprintf(buf, sizeof(buf), fmt, ap)) < 0) {
835 fatal(xstrerr(errno));
836 return;
837 }
838 va_end(ap);
839
840 if (x < static_cast<int>(sizeof(buf))) {
841 append(buf, x);
842 return;
843 }
844
845 // okay, do it the slow way.
846 char *buf2 = new char[x+1];
847 int y = vsnprintf(buf2, x+1, fmt, vargs);
848 assert(y >= 0 && y == x);
849 append(buf2, y);
850 delete[] buf2;
851}
852
853// deprecated. use StoreEntry::appendf() instead.
854void
855storeAppendPrintf(StoreEntry * e, const char *fmt,...)
856{
857 va_list args;
858 va_start(args, fmt);
859 e->vappendf(fmt, args);
860 va_end(args);
861}
862
863// deprecated. use StoreEntry::appendf() instead.
864void
865storeAppendVPrintf(StoreEntry * e, const char *fmt, va_list vargs)
866{
867 e->vappendf(fmt, vargs);
868}
869
887
888int
890{
891 if (Config.max_open_disk_fds == 0)
892 return 0;
893
895 return 1;
896
897 return 0;
898}
899
900int
902{
904 return 0;
905
906 if (STORE_OK == store_status)
907 if (mem_obj->object_sz >= 0 &&
909 return 1;
910
911 const auto clen = mem().baseReply().content_length;
912 if (clen >= 0 && clen < Config.Store.minObjectSize)
913 return 1;
914 return 0;
915}
916
917bool
919{
921 return true;
922
923 const auto clen = mem_obj->baseReply().content_length;
924 return (clen >= 0 && clen > store_maxobjsize);
925}
926
927// TODO: move "too many open..." checks outside -- we are called too early/late
928bool
930{
931 // XXX: This method is used for both memory and disk caches, but some
932 // checks are specific to disk caches. Move them to mayStartSwapOut().
933
934 // XXX: This method may be called several times, sometimes with different
935 // outcomes, making store_check_cachable_hist counters misleading.
936
937 // check this first to optimize handling of repeated calls for uncachables
939 debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
941 return 0; // avoid rerequesting release below
942 }
943
945 debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
947 } else if (!mem_obj) {
948 // XXX: In bug 4131, we forgetHit() without mem_obj, so we need
949 // this segfault protection, but how can we get such a HIT?
950 debugs(20, 2, "StoreEntry::checkCachable: NO: missing parts: " << *this);
952 } else if (checkTooBig()) {
953 debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
955 } else if (checkTooSmall()) {
956 debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
958 } else if (EBIT_TEST(flags, KEY_PRIVATE)) {
959 debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
961 } else if (hasDisk()) {
962 /*
963 * the remaining cases are only relevant if we haven't
964 * started swapping out the object yet.
965 */
966 return 1;
967 } else if (storeTooManyDiskFilesOpen()) {
968 debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
970 } else if (fdNFree() < RESERVED_FD) {
971 debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
973 } else {
975 return 1;
976 }
977
979 return 0;
980}
981
982void
984{
985 storeAppendPrintf(sentry, "Category\t Count\n");
986 storeAppendPrintf(sentry, "no.not_entry_cachable\t%d\n",
988 storeAppendPrintf(sentry, "no.wrong_content_length\t%d\n",
990 storeAppendPrintf(sentry, "no.negative_cached\t%d\n",
991 0); // TODO: Remove this backward compatibility hack.
992 storeAppendPrintf(sentry, "no.missing_parts\t%d\n",
994 storeAppendPrintf(sentry, "no.too_big\t%d\n",
996 storeAppendPrintf(sentry, "no.too_small\t%d\n",
998 storeAppendPrintf(sentry, "no.private_key\t%d\n",
1000 storeAppendPrintf(sentry, "no.too_many_open_files\t%d\n",
1002 storeAppendPrintf(sentry, "no.too_many_open_fds\t%d\n",
1004 storeAppendPrintf(sentry, "yes.default\t%d\n",
1006}
1007
1008void
1009StoreEntry::lengthWentBad(const char *reason)
1010{
1011 debugs(20, 3, "because " << reason << ": " << *this);
1014}
1015
1016void
1017StoreEntry::completeSuccessfully(const char * const whyWeAreSure)
1018{
1019 debugs(20, 3, whyWeAreSure << "; " << *this);
1020 complete();
1021}
1022
1023void
1024StoreEntry::completeTruncated(const char * const truncationReason)
1025{
1026 lengthWentBad(truncationReason);
1027 complete();
1028}
1029
1030void
1032{
1033 debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1034
1035 // To preserve forwarding retries, call FwdState::complete() instead.
1037
1038 if (store_status != STORE_PENDING) {
1039 /*
1040 * if we're not STORE_PENDING, then probably we got aborted
1041 * and there should be NO clients on this entry
1042 */
1044 assert(mem_obj->nclients == 0);
1045 return;
1046 }
1047
1049
1051
1053
1055 lengthWentBad("!validLength() in complete()");
1056
1057#if USE_CACHE_DIGESTS
1058 if (mem_obj->request)
1060
1061#endif
1062 /*
1063 * We used to call invokeHandlers, then storeSwapOut. However,
1064 * Madhukar Reddy <myreddy@persistence.com> reported that
1065 * responses without content length would sometimes get released
1066 * in client_side, thinking that the response is incomplete.
1067 */
1069}
1070
1071/*
1072 * Someone wants to abort this transfer. Set the reason in the
1073 * request structure, call the callback and mark the
1074 * entry for releasing
1075 */
1076void
1078{
1081 assert(mem_obj != nullptr);
1082 debugs(20, 6, "storeAbort: " << getMD5Text());
1083
1084 lock("StoreEntry::abort"); /* lock while aborting */
1085 negativeCache();
1086
1088
1090
1091 // allow the Store clients to be told about the problem
1093
1095
1097
1098 /* Notify the server side */
1099
1100 if (mem_obj->abortCallback) {
1102 mem_obj->abortCallback = nullptr;
1103 }
1104
1105 /* XXX Should we reverse these two, so that there is no
1106 * unneeded disk swapping triggered?
1107 */
1108 /* Notify the client side */
1110
1111 // abort swap out, invalidating what was created so far (release follows)
1113
1114 unlock("StoreEntry::abort"); /* unlock */
1115}
1116
1120void
1125
1126/* thunk through to Store::Root().maintain(). Note that this would be better still
1127 * if registered against the root store itself, but that requires more complex
1128 * update logic - bigger fish to fry first. Long term each store when
1129 * it becomes active will self register
1130 */
1131void
1133{
1135
1136 /* Reregister a maintain event .. */
1137 eventAdd("MaintainSwapSpace", Maintain, nullptr, 1.0, 1);
1138
1139}
1140
1141/* The maximum objects to scan for maintain storage space */
1142#define MAINTAIN_MAX_SCAN 1024
1143#define MAINTAIN_MAX_REMOVE 64
1144
1145void
1146StoreEntry::release(const bool shareable)
1147{
1148 debugs(20, 3, shareable << ' ' << *this << ' ' << getMD5Text());
1149 /* If, for any reason we can't discard this object because of an
1150 * outstanding request, mark it for pending release */
1151
1152 if (locked()) {
1153 releaseRequest(shareable);
1154 return;
1155 }
1156
1158 /* TODO: Teach disk stores to handle releases during rebuild instead. */
1159
1160 // lock the entry until rebuilding is done
1161 lock("storeLateRelease");
1162 releaseRequest(shareable);
1163 LateReleaseStack.push(this);
1164 return;
1165 }
1166
1168 Store::Root().evictCached(*this);
1169 destroyStoreEntry(static_cast<hash_link *>(this));
1170}
1171
1172static void
1174{
1175 StoreEntry *e;
1176 static int n = 0;
1177
1179 eventAdd("storeLateRelease", storeLateRelease, nullptr, 1.0, 1);
1180 return;
1181 }
1182
1183 // TODO: this works but looks unelegant.
1184 for (int i = 0; i < 10; ++i) {
1185 if (LateReleaseStack.empty()) {
1186 debugs(20, Important(30), "storeLateRelease: released " << n << " objects");
1187 return;
1188 } else {
1189 e = LateReleaseStack.top();
1190 LateReleaseStack.pop();
1191 }
1192
1193 e->unlock("storeLateRelease");
1194 ++n;
1195 }
1196
1197 eventAdd("storeLateRelease", storeLateRelease, nullptr, 0.0, 1);
1198}
1199
1203bool
1205{
1206 int64_t diff;
1207 assert(mem_obj != nullptr);
1208 const auto reply = &mem_obj->baseReply();
1209 debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1210 debugs(20, 5, "storeEntryValidLength: object_len = " <<
1211 objectLen());
1212 debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply->hdr_sz);
1213 debugs(20, 5, "storeEntryValidLength: content_length = " << reply->content_length);
1214
1215 if (reply->content_length < 0) {
1216 debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1217 return 1;
1218 }
1219
1220 if (reply->hdr_sz == 0) {
1221 debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1222 return 1;
1223 }
1224
1226 debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1227 return 1;
1228 }
1229
1230 if (reply->sline.status() == Http::scNotModified)
1231 return 1;
1232
1233 if (reply->sline.status() == Http::scNoContent)
1234 return 1;
1235
1236 diff = reply->hdr_sz + reply->content_length - objectLen();
1237
1238 if (diff == 0)
1239 return 1;
1240
1241 debugs(20, 3, "storeEntryValidLength: " << (diff < 0 ? -diff : diff) << " bytes too " << (diff < 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1242
1243 return 0;
1244}
1245
1246static void
1248{
1249 Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats, 0, 1);
1250 Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create, 0, 1);
1251 Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1253 Mgr::RegisterAction("store_queues", "SMP Transients and Caching Queues", StatQueues, 0, 1);
1254}
1255
1256void
1258{
1261 storeLogOpen();
1262 eventAdd("storeLateRelease", storeLateRelease, nullptr, 1.0, 1);
1263 Store::Root().init();
1265
1267}
1268
1269void
1271{
1273}
1274
1275bool
1277{
1278 if (!checkCachable())
1279 return 0;
1280
1281 if (shutting_down)
1282 return 0; // avoid heavy optional work during shutdown
1283
1284 if (mem_obj == nullptr)
1285 return 0;
1286
1287 if (mem_obj->data_hdr.size() == 0)
1288 return 0;
1289
1290 if (mem_obj->inmem_lo != 0)
1291 return 0;
1292
1294 return 0;
1295
1296 return 1;
1297}
1298
1299int
1301{
1303 return 0;
1304
1305 if (expires <= squid_curtime)
1306 return 0;
1307
1308 if (store_status != STORE_OK)
1309 return 0;
1310
1311 return 1;
1312}
1313
1320void
1322{
1323 // XXX: should make the default for expires 0 instead of -1
1324 // so we can distinguish "Expires: -1" from nothing.
1325 if (expires <= 0)
1326#if USE_HTTP_VIOLATIONS
1328#else
1330#endif
1331 if (expires > squid_curtime) {
1333 debugs(20, 6, "expires = " << expires << " +" << (expires-squid_curtime) << ' ' << *this);
1334 }
1335}
1336
1337int
1338expiresMoreThan(time_t expires, time_t when)
1339{
1340 if (expires < 0) /* No Expires given */
1341 return 1;
1342
1343 return (expires > (squid_curtime + when));
1344}
1345
1346int
1348{
1350 return 0;
1351
1353 if (expires <= squid_curtime)
1354 return 0;
1355
1357 return 0;
1358
1359 // now check that the entry has a cache backing or is collapsed
1360 if (hasDisk()) // backed by a disk cache
1361 return 1;
1362
1363 if (swappingOut()) // will be backed by a disk cache
1364 return 1;
1365
1366 if (!mem_obj) // not backed by a memory cache and not collapsed
1367 return 0;
1368
1369 // StoreEntry::storeClientType() assumes DISK_CLIENT here, but there is no
1370 // disk cache backing that store_client constructor will assert. XXX: This
1371 // is wrong for range requests (that could feed off nibbled memory) and for
1372 // entries backed by the shared memory cache (that could, in theory, get
1373 // nibbled bytes from that cache, but there is no such "memoryIn" code).
1374 if (mem_obj->inmem_lo) // in memory cache, but got nibbled at
1375 return 0;
1376
1377 // The following check is correct but useless at this position. TODO: Move
1378 // it up when the shared memory cache can either replenish locally nibbled
1379 // bytes or, better, does not use local RAM copy at all.
1380 // if (mem_obj->memCache.index >= 0) // backed by a shared memory cache
1381 // return 1;
1382
1383 return 1;
1384}
1385
1386bool
1388{
1389 debugs(20, 7, *this << " had " << describeTimestamps());
1390
1391 // TODO: Remove change-reducing "&" before the official commit.
1392 const auto reply = &mem().freshestReply();
1393
1394 time_t served_date = reply->date;
1395 int age = reply->header.getInt(Http::HdrType::AGE);
1396 /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1397 /* make sure that 0 <= served_date <= squid_curtime */
1398
1399 if (served_date < 0 || served_date > squid_curtime)
1400 served_date = squid_curtime;
1401
1402 /* Bug 1791:
1403 * If the returned Date: is more than 24 hours older than
1404 * the squid_curtime, then one of us needs to use NTP to set our
1405 * clock. We'll pretend that our clock is right.
1406 */
1407 else if (served_date < (squid_curtime - 24 * 60 * 60) )
1408 served_date = squid_curtime;
1409
1410 /*
1411 * Compensate with Age header if origin server clock is ahead
1412 * of us and there is a cache in between us and the origin
1413 * server. But DONT compensate if the age value is larger than
1414 * squid_curtime because it results in a negative served_date.
1415 */
1416 if (age > squid_curtime - served_date)
1417 if (squid_curtime > age)
1418 served_date = squid_curtime - age;
1419
1420 // compensate for Squid-to-server and server-to-Squid delays
1421 if (mem_obj && mem_obj->request) {
1422 struct timeval responseTime;
1423 if (mem_obj->request->hier.peerResponseTime(responseTime))
1424 served_date -= responseTime.tv_sec;
1425 }
1426
1427 time_t exp = 0;
1428 if (reply->expires > 0 && reply->date > -1)
1429 exp = served_date + (reply->expires - reply->date);
1430 else
1431 exp = reply->expires;
1432
1433 if (timestamp == served_date && expires == exp) {
1434 // if the reply lacks LMT, then we now know that our effective
1435 // LMT (i.e., timestamp) will stay the same, otherwise, old and
1436 // new modification times must match
1437 if (reply->last_modified < 0 || reply->last_modified == lastModified())
1438 return false; // nothing has changed
1439 }
1440
1441 expires = exp;
1442
1443 lastModified_ = reply->last_modified;
1444
1445 timestamp = served_date;
1446
1447 debugs(20, 5, *this << " has " << describeTimestamps());
1448 return true;
1449}
1450
1451bool
1453{
1454 assert(mem_obj);
1455 assert(e304.mem_obj);
1456
1457 // update reply before calling timestampsSet() below
1458 const auto &oldReply = mem_obj->freshestReply();
1459 const auto updatedReply = oldReply.recreateOnNotModified(e304.mem_obj->baseReply());
1460 if (updatedReply) { // HTTP 304 brought in new information
1461 if (updatedReply->prefixLen() > Config.maxReplyHeaderSize) {
1462 throw TextException(ToSBuf("cannot update the cached response because its updated ",
1463 updatedReply->prefixLen(), "-byte header would exceed ",
1464 Config.maxReplyHeaderSize, "-byte reply_header_max_size"), Here());
1465 }
1466 mem_obj->updateReply(*updatedReply);
1467 }
1468 // else continue to use the previous update, if any
1469
1470 if (!timestampsSet() && !updatedReply)
1471 return false;
1472
1473 // Keep the old mem_obj->vary_headers; see HttpHeader::skipUpdateHeader().
1474
1475 debugs(20, 5, "updated basics in " << *this << " with " << e304);
1476 mem_obj->appliedUpdates = true; // helps in triage; may already be true
1477 return true;
1478}
1479
1480void
1487
1488void
1490{
1491 assert(mem_obj);
1492 if (mem_obj->abortCallback) {
1493 mem_obj->abortCallback->cancel(reason);
1494 mem_obj->abortCallback = nullptr;
1495 }
1496}
1497
1498void
1500{
1501 debugs(20, l, "StoreEntry->key: " << getMD5Text());
1502 debugs(20, l, "StoreEntry->next: " << next);
1503 debugs(20, l, "StoreEntry->mem_obj: " << mem_obj);
1504 debugs(20, l, "StoreEntry->timestamp: " << timestamp);
1505 debugs(20, l, "StoreEntry->lastref: " << lastref);
1506 debugs(20, l, "StoreEntry->expires: " << expires);
1507 debugs(20, l, "StoreEntry->lastModified_: " << lastModified_);
1508 debugs(20, l, "StoreEntry->swap_file_sz: " << swap_file_sz);
1509 debugs(20, l, "StoreEntry->refcount: " << refcount);
1510 debugs(20, l, "StoreEntry->flags: " << storeEntryFlags(this));
1511 debugs(20, l, "StoreEntry->swap_dirn: " << swap_dirn);
1512 debugs(20, l, "StoreEntry->swap_filen: " << swap_filen);
1513 debugs(20, l, "StoreEntry->lock_count: " << lock_count);
1514 debugs(20, l, "StoreEntry->mem_status: " << mem_status);
1515 debugs(20, l, "StoreEntry->ping_status: " << ping_status);
1516 debugs(20, l, "StoreEntry->store_status: " << store_status);
1517 debugs(20, l, "StoreEntry->swap_status: " << swap_status);
1518}
1519
1520/*
1521 * NOTE, this function assumes only two mem states
1522 */
1523void
1525{
1526 if (new_status == mem_status)
1527 return;
1528
1529 // are we using a shared memory cache?
1530 if (MemStore::Enabled()) {
1531 // This method was designed to update replacement policy, not to
1532 // actually purge something from the memory cache (TODO: rename?).
1533 // Shared memory cache does not have a policy that needs updates.
1534 mem_status = new_status;
1535 return;
1536 }
1537
1538 assert(mem_obj != nullptr);
1539
1540 if (new_status == IN_MEMORY) {
1541 assert(mem_obj->inmem_lo == 0);
1542
1544 debugs(20, 4, "not inserting special " << *this << " into policy");
1545 } else {
1547 debugs(20, 4, "inserted " << *this << " key: " << getMD5Text());
1548 }
1549
1550 ++hot_obj_count; // TODO: maintain for the shared hot cache as well
1551 } else {
1553 debugs(20, 4, "not removing special " << *this << " from policy");
1554 } else {
1556 debugs(20, 4, "removed " << *this);
1557 }
1558
1559 --hot_obj_count;
1560 }
1561
1562 mem_status = new_status;
1563}
1564
1565const char *
1567{
1568 if (mem_obj == nullptr)
1569 return "[null_mem_obj]";
1570 else
1571 return mem_obj->storeId();
1572}
1573
1574void
1576{
1577 assert(!mem_obj);
1578 mem_obj = new MemObject();
1579}
1580
1581void
1582StoreEntry::createMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1583{
1584 assert(!mem_obj);
1585 ensureMemObject(aUrl, aLogUrl, aMethod);
1586}
1587
1588void
1589StoreEntry::ensureMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1590{
1591 if (!mem_obj)
1592 mem_obj = new MemObject();
1593 mem_obj->setUris(aUrl, aLogUrl, aMethod);
1594}
1595
1600void
1605
1611void
1619
1620void
1622{
1623 debugs(20, 3, url());
1624 mem().reset();
1626}
1627
1628/*
1629 * storeFsInit
1630 *
1631 * This routine calls the SETUP routine for each fs type.
1632 * I don't know where the best place for this is, and I'm not going to shuffle
1633 * around large chunks of code right now (that can be done once its working.)
1634 */
1635void
1637{
1639}
1640
1641/*
1642 * called to add another store removal policy module
1643 */
1644void
1645storeReplAdd(const char *type, REMOVALPOLICYCREATE * create)
1646{
1647 int i;
1648
1649 /* find the number of currently known repl types */
1650 for (i = 0; storerepl_list && storerepl_list[i].typestr; ++i) {
1651 if (strcmp(storerepl_list[i].typestr, type) == 0) {
1652 debugs(20, DBG_IMPORTANT, "WARNING: Trying to load store replacement policy " << type << " twice.");
1653 return;
1654 }
1655 }
1656
1657 /* add the new type */
1658 storerepl_list = static_cast<storerepl_entry_t *>(xrealloc(storerepl_list, (i + 2) * sizeof(storerepl_entry_t)));
1659
1660 memset(&storerepl_list[i + 1], 0, sizeof(storerepl_entry_t));
1661
1662 storerepl_list[i].typestr = type;
1663
1664 storerepl_list[i].create = create;
1665}
1666
1667/*
1668 * Create a removal policy instance
1669 */
1672{
1674
1675 for (r = storerepl_list; r && r->typestr; ++r) {
1676 if (strcmp(r->typestr, settings->type) == 0)
1677 return r->create(settings->args);
1678 }
1679
1680 debugs(20, DBG_IMPORTANT, "ERROR: Unknown policy " << settings->type);
1681 debugs(20, DBG_IMPORTANT, "ERROR: Be sure to have set cache_replacement_policy");
1682 debugs(20, DBG_IMPORTANT, "ERROR: and memory_replacement_policy in squid.conf!");
1683 fatalf("ERROR: Unknown policy %s\n", settings->type);
1684 return nullptr; /* NOTREACHED */
1685}
1686
1687void
1689{
1690 lock("StoreEntry::storeErrorResponse");
1691 buffer();
1693 flush();
1694 completeSuccessfully("replaceHttpReply() stored the entire error");
1695 negativeCache();
1696 releaseRequest(false); // if it is safe to negatively cache, sharing is OK
1697 unlock("StoreEntry::storeErrorResponse");
1698}
1699
1700/*
1701 * Replace a store entry with
1702 * a new reply. This eats the reply.
1703 */
1704void
1705StoreEntry::replaceHttpReply(const HttpReplyPointer &rep, const bool andStartWriting)
1706{
1707 debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1708
1709 if (!mem_obj) {
1710 debugs(20, DBG_CRITICAL, "Attempt to replace object with no in-memory representation");
1711 return;
1712 }
1713
1715
1716 if (andStartWriting)
1717 startWriting();
1718}
1719
1720void
1722{
1723 /* TODO: when we store headers separately remove the header portion */
1724 /* TODO: mark the length of the headers ? */
1725 /* We ONLY want the headers */
1726 assert (isEmpty());
1727 assert(mem_obj);
1728
1729 // Per MemObject replies definitions, we can only write our base reply.
1730 // Currently, all callers replaceHttpReply() first, so there is no updated
1731 // reply here anyway. Eventually, we may need to support the
1732 // updateOnNotModified(),startWriting() sequence as well.
1734 const auto rep = &mem_obj->baseReply();
1735
1736 buffer();
1737 rep->packHeadersUsingSlowPacker(*this);
1739
1740 // Same-worker collapsing risks end with the receipt of the headers.
1741 // SMP collapsing risks remain until the headers are actually cached, but
1742 // that event is announced via CF-agnostic Store writing broadcasts.
1744
1745 rep->body.packInto(this);
1746 flush();
1747}
1748
1749char const *
1751{
1752 return static_cast<const char *>(Store::PackSwapMeta(*this, length).release());
1753}
1754
1760void
1762{
1763 if (!hasTransients())
1764 return; // no SMP complications
1765
1766 // writers become readers but only after completeWriting() which we trigger
1767 if (Store::Root().transientsReader(*this))
1768 return; // readers do not need to inform
1769
1770 assert(mem_obj);
1771 if (mem_obj->memCache.io != Store::ioDone) {
1772 debugs(20, 7, "not done with mem-caching " << *this);
1773 return;
1774 }
1775
1776 const auto doneWithDiskCache =
1777 // will not start
1779 // or has started but finished already
1781 if (!doneWithDiskCache) {
1782 debugs(20, 7, "not done with disk-caching " << *this);
1783 return;
1784 }
1785
1786 debugs(20, 7, "done with writing " << *this);
1788}
1789
1790void
1791StoreEntry::memOutDecision(const bool willCacheInRam)
1792{
1793 if (!willCacheInRam)
1794 return storeWritingCheckpoint();
1796 // and wait for storeWriterDone()
1797}
1798
1799void
1806
1807void
1812
1813void
1814StoreEntry::trimMemory(const bool preserveSwappable)
1815{
1816 /*
1817 * DPW 2007-05-09
1818 * Bug #1943. We must not let go any data for IN_MEMORY
1819 * objects. We have to wait until the mem_status changes.
1820 */
1821 if (mem_status == IN_MEMORY)
1822 return;
1823
1825 return; // cannot trim because we do not load them again
1826
1827 if (preserveSwappable)
1829 else
1831
1832 debugs(88, 7, *this << " inmem_lo=" << mem_obj->inmem_lo);
1833}
1834
1835bool
1836StoreEntry::modifiedSince(const time_t ims, const int imslen) const
1837{
1838 const time_t mod_time = lastModified();
1839
1840 debugs(88, 3, "modifiedSince: '" << url() << "'");
1841
1842 debugs(88, 3, "modifiedSince: mod_time = " << mod_time);
1843
1844 if (mod_time < 0)
1845 return true;
1846
1847 assert(imslen < 0); // TODO: Either remove imslen or support it properly.
1848
1849 if (mod_time > ims) {
1850 debugs(88, 3, "--> YES: entry newer than client");
1851 return true;
1852 } else if (mod_time < ims) {
1853 debugs(88, 3, "--> NO: entry older than client");
1854 return false;
1855 } else {
1856 debugs(88, 3, "--> NO: same LMT");
1857 return false;
1858 }
1859}
1860
1861bool
1863{
1864 if (const auto reply = hasFreshestReply()) {
1865 etag = reply->header.getETag(Http::HdrType::ETAG);
1866 if (etag.str)
1867 return true;
1868 }
1869 return false;
1870}
1871
1872bool
1874{
1875 const String reqETags = request.header.getList(Http::HdrType::IF_MATCH);
1876 return hasOneOfEtags(reqETags, false);
1877}
1878
1879bool
1881{
1882 const String reqETags = request.header.getList(Http::HdrType::IF_NONE_MATCH);
1883 // weak comparison is allowed only for HEAD or full-body GET requests
1884 const bool allowWeakMatch = !request.flags.isRanged &&
1885 (request.method == Http::METHOD_GET || request.method == Http::METHOD_HEAD);
1886 return hasOneOfEtags(reqETags, allowWeakMatch);
1887}
1888
1890bool
1891StoreEntry::hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
1892{
1893 const auto repETag = mem().freshestReply().header.getETag(Http::HdrType::ETAG);
1894 if (!repETag.str) {
1895 static SBuf asterisk("*", 1);
1896 return strListIsMember(&reqETags, asterisk, ',');
1897 }
1898
1899 bool matched = false;
1900 const char *pos = nullptr;
1901 const char *item;
1902 int ilen;
1903 while (!matched && strListGetItem(&reqETags, ',', &item, &ilen, &pos)) {
1904 if (!strncmp(item, "*", ilen))
1905 matched = true;
1906 else {
1907 String str;
1908 str.append(item, ilen);
1909 ETag reqETag;
1910 if (etagParseInit(&reqETag, str.termedBuf())) {
1911 matched = allowWeakMatch ? etagIsWeakEqual(repETag, reqETag) :
1912 etagIsStrongEqual(repETag, reqETag);
1913 }
1914 }
1915 }
1916 return matched;
1917}
1918
1921{
1922 assert(hasDisk());
1924 assert(sd);
1925 return *sd;
1926}
1927
1928bool
1929StoreEntry::hasDisk(const sdirno dirn, const sfileno filen) const
1930{
1931 checkDisk();
1932 if (dirn < 0 && filen < 0)
1933 return swap_dirn >= 0;
1934 Must(dirn >= 0);
1935 const bool matchingDisk = (swap_dirn == dirn);
1936 return filen < 0 ? matchingDisk : (matchingDisk && swap_filen == filen);
1937}
1938
1939void
1940StoreEntry::attachToDisk(const sdirno dirn, const sfileno fno, const swap_status_t status)
1941{
1942 debugs(88, 3, "attaching entry with key " << getMD5Text() << " : " <<
1943 swapStatusStr[status] << " " << dirn << " " <<
1944 asHex(fno).upperCase().minDigits(8));
1945 checkDisk();
1946 swap_dirn = dirn;
1947 swap_filen = fno;
1948 swap_status = status;
1949 checkDisk();
1950}
1951
1952void
1954{
1955 swap_dirn = -1;
1956 swap_filen = -1;
1958}
1959
1960void
1962{
1963 try {
1964 if (swap_dirn < 0) {
1965 Must(swap_filen < 0);
1967 } else {
1968 Must(swap_filen >= 0);
1969 Must(static_cast<size_t>(swap_dirn) < Config.cacheSwap.n_configured);
1970 if (swapoutFailed()) {
1972 } else {
1973 Must(swappingOut() || swappedOut());
1974 }
1975 }
1976 } catch (...) {
1977 debugs(88, DBG_IMPORTANT, "ERROR: inconsistent disk entry state " <<
1978 *this << "; problem: " << CurrentException);
1979 throw;
1980 }
1981}
1982
1983/*
1984 * return true if the entry is in a state where
1985 * it can accept more data (ie with write() method)
1986 */
1987bool
1989{
1991 return false;
1992
1994 return false;
1995
1996 return true;
1997}
1998
1999const char *
2001{
2002 LOCAL_ARRAY(char, buf, 256);
2003 snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
2004 static_cast<int>(timestamp),
2005 static_cast<int>(lastref),
2006 static_cast<int>(lastModified_),
2007 static_cast<int>(expires));
2008 return buf;
2009}
2010
2011void
2013{
2014 if (hittingRequiresCollapsing() == required)
2015 return; // no change
2016
2017 debugs(20, 5, (required ? "adding to " : "removing from ") << *this);
2018 if (required)
2020 else
2022}
2023
2024static std::ostream &
2025operator <<(std::ostream &os, const Store::IoStatus &io)
2026{
2027 switch (io) {
2028 case Store::ioUndecided:
2029 os << 'u';
2030 break;
2031 case Store::ioReading:
2032 os << 'r';
2033 break;
2034 case Store::ioWriting:
2035 os << 'w';
2036 break;
2037 case Store::ioDone:
2038 os << 'o';
2039 break;
2040 }
2041 return os;
2042}
2043
2044std::ostream &operator <<(std::ostream &os, const StoreEntry &e)
2045{
2046 os << "e:";
2047
2048 if (e.hasTransients()) {
2049 const auto &xitTable = e.mem_obj->xitTable;
2050 os << 't' << xitTable.io << xitTable.index;
2051 }
2052
2053 if (e.hasMemStore()) {
2054 const auto &memCache = e.mem_obj->memCache;
2055 os << 'm' << memCache.io << memCache.index << '@' << memCache.offset;
2056 }
2057
2058 // Do not use e.hasDisk() here because its checkDisk() call may calls us.
2059 if (e.swap_filen > -1 || e.swap_dirn > -1)
2060 os << 'd' << e.swap_filen << '@' << e.swap_dirn;
2061
2062 os << '=';
2063
2064 // print only non-default status values, using unique letters
2065 if (e.mem_status != NOT_IN_MEMORY ||
2068 e.ping_status != PING_NONE) {
2069 if (e.mem_status != NOT_IN_MEMORY) os << 'm';
2070 if (e.store_status != STORE_PENDING) os << 's';
2071 if (e.swap_status != SWAPOUT_NONE) os << 'w' << e.swap_status;
2072 if (e.ping_status != PING_NONE) os << 'p' << e.ping_status;
2073 }
2074
2075 // print only set flags, using unique letters
2076 if (e.flags) {
2077 if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) os << 'S';
2078 if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_ALWAYS)) os << 'R';
2079 if (EBIT_TEST(e.flags, DELAY_SENDING)) os << 'P';
2080 if (EBIT_TEST(e.flags, RELEASE_REQUEST)) os << 'X';
2081 if (EBIT_TEST(e.flags, REFRESH_REQUEST)) os << 'F';
2082 if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_STALE)) os << 'E';
2083 if (EBIT_TEST(e.flags, KEY_PRIVATE)) {
2084 os << 'I';
2086 os << 'H';
2087 }
2088 if (EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT)) os << 'W';
2089 if (EBIT_TEST(e.flags, ENTRY_NEGCACHED)) os << 'N';
2090 if (EBIT_TEST(e.flags, ENTRY_VALIDATED)) os << 'V';
2091 if (EBIT_TEST(e.flags, ENTRY_BAD_LENGTH)) os << 'L';
2092 if (EBIT_TEST(e.flags, ENTRY_ABORTED)) os << 'A';
2093 if (EBIT_TEST(e.flags, ENTRY_REQUIRES_COLLAPSING)) os << 'C';
2094 }
2095
2096 return os << '/' << &e << '*' << e.locks();
2097}
2098
2099void
2101{
2103 entry_->releaseRequest(false);
2105 });
2106}
2107
#define ScheduleCallHere(call)
Definition AsyncCall.h:166
void storeDirSwapLog(const StoreEntry *e, int op)
Definition Disks.cc:833
bool etagIsWeakEqual(const ETag &tag1, const ETag &tag2)
whether etags are weak-equal
Definition ETag.cc:55
int etagParseInit(ETag *etag, const char *str)
Definition ETag.cc:29
bool etagIsStrongEqual(const ETag &tag1, const ETag &tag2)
whether etags are strong-equal
Definition ETag.cc:49
#define Here()
source code location of the caller
Definition Here.h:15
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
Definition IoManip.h:169
RemovalPolicy * mem_policy
Definition MemObject.cc:44
int size
Definition ModDevPoll.cc:70
time_t squid_curtime
#define memPoolCreate
Creates a named MemPool of elements with the given size.
Definition Pool.h:123
RemovalPolicy * REMOVALPOLICYCREATE(wordlist *args)
class SquidConfig Config
#define INDEXSD(i)
Definition SquidConfig.h:74
StatCounters statCounter
void storeGetMemSpace(int size)
Definition store.cc:1121
int storeTooManyDiskFilesOpen(void)
Definition store.cc:889
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition store.cc:504
const char * storeEntryFlags(const StoreEntry *)
Definition stat.cc:253
FREE destroyStoreEntry
StoreEntry * storeCreateEntry(const char *, const char *, const RequestFlags &, const HttpRequestMethod &)
Definition store.cc:759
int strListGetItem(const String *str, char del, const char **item, int *ilen, const char **pos)
Definition StrList.cc:78
int strListIsMember(const String *list, const SBuf &m, char del)
Definition StrList.cc:46
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
#define SWALLOW_EXCEPTIONS(code)
#define Must(condition)
#define assert(EX)
Definition assert.h:17
bool cancel(const char *reason)
Definition AsyncCall.cc:56
static void StatQueue(std::ostream &)
prints IPC message queue state; suitable for cache manager reports
Definition ETag.h:18
const char * str
quoted-string
Definition ETag.h:20
struct timeval store_complete_stop
bool peerResponseTime(struct timeval &responseTime)
void putStr(Http::HdrType id, const char *str)
ETag getETag(Http::HdrType id) const
String getList(Http::HdrType id) const
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition HttpReply.cc:170
Pointer recreateOnNotModified(const HttpReply &reply304) const
Definition HttpReply.cc:265
time_t date
Definition HttpReply.h:40
HttpRequestMethod method
HierarchyLogEntry hier
RequestFlags flags
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
HttpHeader header
Definition Message.h:74
int64_t content_length
Definition Message.h:83
static void StatQueue(std::ostream &)
prints IPC message queue state; suitable for cache manager reports
Definition IpcIoFile.cc:548
Store::IoStatus io
current I/O state
Definition MemObject.h:201
Decision decision
current decision state
Definition MemObject.h:166
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition MemObject.h:165
Store::IoStatus io
current I/O state
Definition MemObject.h:190
void replaceBaseReply(const HttpReplyPointer &r)
Definition MemObject.cc:128
bool appliedUpdates
Definition MemObject.h:90
RemovalPolicyNode repl
Definition MemObject.h:213
int nclients
Definition MemObject.h:156
SwapOut swapout
Definition MemObject.h:169
HttpRequestMethod method
Definition MemObject.h:147
HttpRequestPointer request
Definition MemObject.h:205
void trimSwappable()
Definition MemObject.cc:371
void setNoDelay(bool const newValue)
Definition MemObject.cc:431
void reset()
Definition MemObject.cc:264
void trimUnSwappable()
Definition MemObject.cc:396
XitTable xitTable
current [shared] memory caching state for the entry
Definition MemObject.h:192
SBuf vary_headers
Definition MemObject.h:221
const HttpReplyPointer & updatedReply() const
Definition MemObject.h:64
mem_hdr data_hdr
Definition MemObject.h:148
AsyncCallPointer abortCallback
used for notifying StoreEntry writers about 3rd-party initiated aborts
Definition MemObject.h:212
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition MemObject.h:85
const HttpReply & freshestReply() const
Definition MemObject.h:68
void markEndOfReplyHeaders()
sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset()
Definition MemObject.cc:220
void write(const StoreIOBuffer &buf)
Definition MemObject.cc:136
int64_t inmem_lo
Definition MemObject.h:149
int mostBytesWanted(int max, bool ignoreDelayPools) const
Definition MemObject.cc:415
MemCache memCache
current [shared] memory caching state for the entry
Definition MemObject.h:203
int64_t endOffset() const
Definition MemObject.cc:214
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition MemObject.cc:76
const char * storeId() const
Definition MemObject.cc:53
const HttpReply & baseReply() const
Definition MemObject.h:60
bool hasUris() const
whether setUris() has been called
Definition MemObject.cc:70
const char * logUri() const
client request URI used for logging; storeId() by default
Definition MemObject.cc:64
bool readAheadPolicyCanRead() const
Definition MemObject.cc:288
int64_t object_sz
Definition MemObject.h:215
static bool Enabled()
whether Squid is correctly configured to use a shared memory cache
Definition MemStore.h:68
int getInUseCount() const
the difference between the number of alloc() and freeOne() calls
Definition Allocator.h:59
static Pointer Create(const CommandPointer &cmd)
Definition Range.h:19
C end
Definition Range.h:25
C * getRaw() const
Definition RefCount.h:89
void(* Add)(RemovalPolicy *policy, StoreEntry *entry, RemovalPolicyNode *node)
void(* Remove)(RemovalPolicy *policy, StoreEntry *entry, RemovalPolicyNode *node)
SupportOrVeto cachable
whether the response may be stored in the cache
Definition SBuf.h:94
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition SBuf.h:279
bool isEmpty() const
Definition SBuf.h:435
void clear()
Definition SBuf.cc:175
int memory_cache_first
size_t maxReplyHeaderSize
Store::DiskConfig cacheSwap
time_t negativeTtl
RemovalPolicySettings * memPolicy
struct SquidConfig::@90 onoff
int max_open_disk_fds
struct SquidConfig::@88 Store
int64_t minObjectSize
void storeWritingCheckpoint()
Definition store.cc:1761
int locks() const
returns a local concurrent use counter, for debugging
Definition Store.h:265
void negativeCache()
Definition store.cc:1321
int checkTooSmall()
Definition store.cc:901
void completeSuccessfully(const char *whyWeAreSureWeStoredTheWholeReply)
Definition store.cc:1017
void hashInsert(const cache_key *)
Definition store.cc:424
void doAbandon(const char *context)
Definition store.cc:486
size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition store.cc:213
mem_status_t mem_status
Definition Store.h:239
bool isAccepting() const
Definition store.cc:1988
void unregisterAbortCallback(const char *reason)
Definition store.cc:1489
const cache_key * calcPublicKey(const KeyScope keyScope)
Definition store.cc:652
bool swappedOut() const
whether the entire entry is now on disk (possibly marked for deletion)
Definition Store.h:135
bool shareableWhenPrivate
Definition Store.h:327
uint16_t flags
Definition Store.h:231
StoreEntry * adjustVary()
Definition store.cc:665
void invokeHandlers()
unsigned short lock_count
Definition Store.h:320
MemObject & mem()
Definition Store.h:47
sdirno swap_dirn
Definition Store.h:237
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition store.cc:1873
void setCollapsingRequirement(const bool required)
allow or forbid collapsed requests feeding
Definition store.cc:2012
const char * getSerialisedMetaData(size_t &length) const
Definition store.cc:1750
void ensureMemObject(const char *storeId, const char *logUri, const HttpRequestMethod &aMethod)
initialize mem_obj (if needed) and set URIs/method (if missing)
Definition store.cc:1589
int locked() const
Definition Store.h:145
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition store.cc:1880
void dump(int debug_lvl) const
Definition store.cc:1499
void checkDisk() const
does nothing except throwing if disk-associated data members are inconsistent
Definition store.cc:1961
void completeTruncated(const char *whyWeConsiderTheReplyTruncated)
Definition store.cc:1024
int unlock(const char *context)
Definition store.cc:469
const char * url() const
Definition store.cc:1566
bool hasMemStore() const
whether there is a corresponding locked shared memory table entry
Definition Store.h:212
void complete()
Definition store.cc:1031
void startWriting()
Definition store.cc:1721
time_t lastModified() const
Definition Store.h:177
time_t expires
Definition Store.h:225
bool hasEtag(ETag &etag) const
whether this entry has an ETag; if yes, puts ETag value into parameter
Definition store.cc:1862
void release(const bool shareable=false)
Definition store.cc:1146
bool memoryCachable()
checkCachable() and can be cached in memory
Definition store.cc:1276
void detachFromDisk()
Definition store.cc:1953
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition store.cc:1929
swap_status_t swap_status
Definition Store.h:245
bool hasParsedReplyHeader() const
whether this entry has access to [deserialized] [HTTP] response headers
Definition store.cc:231
void write(StoreIOBuffer)
Definition store.cc:780
void lock(const char *context)
Definition store.cc:445
bool checkDeferRead(int fd) const
Definition store.cc:244
void swapOutDecision(const MemObject::SwapOut::Decision &decision)
Definition store.cc:1800
void flush() override
Definition store.cc:1612
time_t timestamp
Definition Store.h:223
bool makePublic(const KeyScope keyScope=ksDefault)
Definition store.cc:167
bool timestampsSet()
Definition store.cc:1387
void clearPublicKeyScope()
Definition store.cc:609
void memOutDecision(const bool willCacheInRam)
Definition store.cc:1791
void clearPrivate()
Definition store.cc:180
void abandon(const char *context)
Definition Store.h:280
bool swappingOut() const
whether we are in the process of writing this entry to disk
Definition Store.h:133
void lengthWentBad(const char *reason)
flags [truncated or too big] entry with ENTRY_BAD_LENGTH and releases it
Definition store.cc:1009
bool validLength() const
Definition store.cc:1204
void expireNow()
Definition store.cc:773
bool updateOnNotModified(const StoreEntry &e304)
Definition store.cc:1452
time_t lastModified_
received Last-Modified value or -1; use lastModified()
Definition Store.h:227
void registerAbortCallback(const AsyncCall::Pointer &)
notify the StoreEntry writer of a 3rd-party initiated StoreEntry abort
Definition store.cc:1481
const char * describeTimestamps() const
Definition store.cc:2000
Store::Disk & disk() const
the disk this entry is [being] cached on; asserts for entries w/o a disk
Definition store.cc:1920
void forcePublicKey(const cache_key *newkey)
Definition store.cc:626
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition store.cc:1688
const char * getMD5Text() const
Definition store.cc:207
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition Store.h:235
void storeWriterDone()
called when a store writer ends its work (successfully or not)
Definition store.cc:1808
void setPrivateKey(const bool shareable, const bool permanent)
Definition store.cc:548
void hashDelete()
Definition store.cc:433
void makePrivate(const bool shareable)
Definition store.cc:174
int checkNegativeHit() const
Definition store.cc:1300
void attachToDisk(const sdirno, const sfileno, const swap_status_t)
Definition store.cc:1940
void kickProducer()
calls back producer registered with deferProducer
Definition store.cc:376
AsyncCall::Pointer deferredProducer
producer callback registered with deferProducer
Definition Store.h:331
static size_t inUseCount()
Definition store.cc:199
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition store.cc:1705
bool hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
whether at least one of the request ETags matches entity ETag
Definition store.cc:1891
MemObject * mem_obj
Definition Store.h:220
void vappendf(const char *, va_list) override
Definition store.cc:821
StoreEntry()
Definition store.cc:338
ping_status_t ping_status
Definition Store.h:241
void setNoDelay(bool const)
Definition store.cc:250
void reset()
Definition store.cc:1621
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition store.cc:1836
void append(char const *, int) override
Appends a c-string to existing packed data.
Definition store.cc:803
void abort()
Definition store.cc:1077
void trimMemory(const bool preserveSwappable)
Definition store.cc:1814
int64_t objectLen() const
Definition Store.h:253
~StoreEntry() override
Definition store.cc:359
store_status_t store_status
Definition Store.h:243
void buffer() override
Definition store.cc:1601
void releaseRequest(const bool shareable=false)
Definition store.cc:458
time_t lastref
Definition Store.h:224
store_client_t storeClientType() const
Definition store.cc:264
static Mem::Allocator * pool
Definition Store.h:318
bool isEmpty() const
Definition Store.h:65
void touch()
update last reference timestamp and related Store metadata
Definition store.cc:452
void createMemObject()
Definition store.cc:1575
bool swapoutFailed() const
whether we failed to write this entry to disk
Definition Store.h:137
bool checkTooBig() const
Definition store.cc:918
bool setPublicKey(const KeyScope keyScope=ksDefault)
Definition store.cc:575
void deferProducer(const AsyncCall::Pointer &producer)
call back producer when more buffer space is available
Definition store.cc:366
const HttpReply * hasFreshestReply() const
Definition Store.h:53
uint64_t swap_file_sz
Definition Store.h:229
uint16_t refcount
Definition Store.h:230
bool checkCachable()
Definition store.cc:929
bool hasTransients() const
whether there is a corresponding locked transients table entry
Definition Store.h:210
void swapOutFileClose(int how)
bool hittingRequiresCollapsing() const
whether this entry can feed collapsed requests and only them
Definition Store.h:215
int validToSend() const
Definition store.cc:1347
void setMemStatus(mem_status_t)
Definition store.cc:1524
void destroyMemObject()
Definition store.cc:386
bool cacheNegatively()
Definition store.cc:188
@ writerGone
failure: caller left before swapping out everything
void configure()
update configuration, including limits (re)calculation
void noteStoppedSharedWriting(StoreEntry &)
adjust shared state after this worker stopped changing the entry
void addWriting(StoreEntry *, const cache_key *)
void handleIdleEntry(StoreEntry &)
called when the entry is no longer needed by any transaction
void stat(StoreEntry &) const override
void freeMemorySpace(const int spaceRequired)
void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition Controller.cc:87
void memoryDisconnect(StoreEntry &)
disassociates the entry from the memory cache, preserving cached data
void transientsDisconnect(StoreEntry &)
disassociates the entry from the intransit table
static int store_dirs_rebuilding
the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
Definition Controller.h:133
void init() override
Definition Controller.cc:53
void evictCached(StoreEntry &) override
StoreEntry * find(const cache_key *)
manages a single cache_dir
Definition Disk.h:22
virtual void disconnect(StoreEntry &)
called when the entry is about to forget its association with cache_dir
Definition Disk.h:71
Entry * entry_
the guarded Entry or nil
Definition Store.h:386
const char * context_
default unlock() message
Definition Store.h:387
void onException() noexcept
Definition store.cc:2100
void unlockAndReset(const char *resetContext=nullptr)
Definition Store.h:376
char const * termedBuf() const
Definition SquidString.h:93
void append(char const *buf, int len)
Definition String.cc:131
an std::runtime_error with thrower location info
size_t size() const
Definition stmem.cc:366
#define Important(id)
Definition Messages.h:93
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
#define EBIT_CLR(flag, bit)
Definition defines.h:66
#define EBIT_SET(flag, bit)
Definition defines.h:65
#define EBIT_TEST(flag, bit)
Definition defines.h:67
@ ENTRY_REQUIRES_COLLAPSING
Definition enums.h:113
@ ENTRY_BAD_LENGTH
Definition enums.h:109
@ ENTRY_VALIDATED
Definition enums.h:108
@ ENTRY_SPECIAL
Definition enums.h:79
@ KEY_PRIVATE
Definition enums.h:97
@ ENTRY_FWD_HDR_WAIT
Definition enums.h:106
@ DELAY_SENDING
Definition enums.h:92
@ RELEASE_REQUEST
prohibits making the key public
Definition enums.h:93
@ ENTRY_REVALIDATE_STALE
Definition enums.h:95
@ ENTRY_ABORTED
Definition enums.h:110
@ ENTRY_NEGCACHED
Definition enums.h:107
@ ENTRY_REVALIDATE_ALWAYS
Definition enums.h:80
@ REFRESH_REQUEST
Definition enums.h:94
@ NOT_IN_MEMORY
Definition enums.h:30
@ IN_MEMORY
Definition enums.h:31
@ PING_NONE
Has not considered whether to send ICP queries to peers yet.
Definition enums.h:36
enum _mem_status_t mem_status_t
swap_status_t
StoreEntry relationship with a disk cache.
Definition enums.h:50
@ SWAPOUT_NONE
Definition enums.h:53
store_client_t
Definition enums.h:66
@ STORE_DISK_CLIENT
Definition enums.h:69
@ STORE_MEM_CLIENT
Definition enums.h:68
@ STORE_PENDING
Definition enums.h:46
@ STORE_OK
Definition enums.h:45
@ STORE_LOG_RELEASE
Definition enums.h:154
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition event.cc:107
void EVH(void *)
Definition event.h:18
void fatal(const char *message)
Definition fatal.cc:28
void fatalf(const char *fmt,...)
Definition fatal.cc:68
int fdNFree(void)
Definition fd.cc:262
const char * swapStatusStr[]
Definition store.cc:92
hash_table * store_table
int store_open_disk_fd
int shutting_down
int neighbors_do_private_keys
int hot_obj_count
int64_t store_maxobjsize
int RESERVED_FD
hash_link * hash_lookup(hash_table *, const void *)
Definition hash.cc:146
void hash_join(hash_table *, hash_link *)
Definition hash.cc:131
void hash_remove_link(hash_table *, hash_link *)
Definition hash.cc:220
RefCount< HttpReply > HttpReplyPointer
Definition forward.h:50
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition http.cc:590
void OBJH(StoreEntry *)
Definition forward.h:44
@ scNotModified
Definition StatusCode.h:41
@ scOkay
Definition StatusCode.h:27
@ scNoContent
Definition StatusCode.h:31
@ METHOD_GET
Definition MethodType.h:25
@ METHOD_HEAD
Definition MethodType.h:28
@ HDR_X_ACCELERATOR_VARY
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
Controller & Root()
safely access controller singleton
IoStatus
cache "I/O" direction and status
Definition forward.h:40
@ ioReading
Definition forward.h:40
@ ioWriting
Definition forward.h:40
@ ioUndecided
Definition forward.h:40
@ ioDone
Definition forward.h:40
void Maintain(void *unused)
Definition store.cc:1132
void Stats(StoreEntry *output)
Definition store.cc:126
AllocedBuf PackSwapMeta(const StoreEntry &, size_t &size)
void storeReplSetup(void)
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition Stream.h:63
#define LOCAL_ARRAY(type, name, size)
Definition squid.h:62
signed int sdirno
Definition forward.h:23
unsigned char cache_key
Store key.
Definition forward.h:29
signed_int32_t sfileno
Definition forward.h:22
static EVH storeLateRelease
Definition store.cc:117
const char * swapStatusStr[]
Definition store.cc:92
static std::ostream & operator<<(std::ostream &os, const Store::IoStatus &io)
Definition store.cc:2025
int expiresMoreThan(time_t expires, time_t when)
Definition store.cc:1338
static void StatQueues(StoreEntry *e)
reports the current state of Store-related queues
Definition store.cc:134
void storeGetMemSpace(int size)
Definition store.cc:1121
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition store.cc:855
void storeConfigure(void)
Definition store.cc:1270
struct _store_check_cachable_hist store_check_cachable_hist
void storeAppendVPrintf(StoreEntry *e, const char *fmt, va_list vargs)
Definition store.cc:865
int storeTooManyDiskFilesOpen(void)
Definition store.cc:889
const char * pingStatusStr[]
Definition store.cc:81
void storeInit(void)
Definition store.cc:1257
const char * memStatusStr[]
Definition store.cc:76
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition store.cc:510
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition store.cc:516
static int getKeyCounter(void)
Definition store.cc:528
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition store.cc:759
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition store.cc:504
static storerepl_entry_t * storerepl_list
Definition store.cc:110
const char * storeStatusStr[]
Definition store.cc:87
StoreEntry * storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod &method)
Definition store.cc:741
RemovalPolicy * createRemovalPolicy(RemovalPolicySettings *settings)
Definition store.cc:1671
static OBJH storeCheckCachableStats
Definition store.cc:116
void storeReplAdd(const char *type, REMOVALPOLICYCREATE *create)
Definition store.cc:1645
void storeFsInit(void)
Definition store.cc:1636
static std::stack< StoreEntry * > LateReleaseStack
Definition store.cc:122
static void storeRegisterWithCacheManager(void)
Definition store.cc:1247
int storePendingNClients(const StoreEntry *e)
void storeDigestInit(void)
const cache_key * storeKeyPublicByRequest(HttpRequest *request, const KeyScope keyScope)
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
const cache_key * storeKeyPublicByRequestMethod(HttpRequest *request, const HttpRequestMethod &method, const KeyScope keyScope)
const cache_key * storeKeyPrivate()
cache_key * storeKeyDup(const cache_key *key)
void storeKeyFree(const cache_key *key)
const char * storeKeyText(const cache_key *key)
KeyScope
@ ksDefault
HASHCMP storeKeyHashCmp
void storeLogOpen(void)
Definition store_log.cc:123
void storeLog(int tag, const StoreEntry *e)
Definition store_log.cc:38
void storeRebuildStart(void)
struct _store_check_cachable_hist::@121 yes
struct _store_check_cachable_hist::@120 no
Definition store.cc:105
REMOVALPOLICYCREATE * create
Definition store.cc:107
const char * typestr
Definition store.cc:106
@ SWAP_LOG_ADD
Definition swap_log_op.h:14
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition gadgets.cc:18
#define INT_MAX
Definition types.h:70
void * xrealloc(void *s, size_t sz)
Definition xalloc.cc:126
const char * xstrerr(int error)
Definition xstrerror.cc:83