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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors