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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors