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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors