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