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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors