store.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 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 #if HAVE_DISKIO_MODULE_IPCIO
21 #include "DiskIO/IpcIo/IpcIoFile.h"
22 #endif
23 #include "ETag.h"
24 #include "event.h"
25 #include "fde.h"
26 #include "globals.h"
27 #include "http.h"
28 #include "HttpReply.h"
29 #include "HttpRequest.h"
30 #include "mem_node.h"
31 #include "MemObject.h"
32 #include "MemStore.h"
33 #include "mgr/Registration.h"
34 #include "mgr/StoreIoAction.h"
35 #include "profiler/Profiler.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);
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
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) << "'");
441  assert(!key);
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 
515  debugs(20, DBG_IMPORTANT, "WARNING: " << __FILE__ << ":" << __LINE__ << ": found KEY_PRIVATE");
516 
517  Store::Root().handleIdleEntry(*this); // may delete us
518 }
519 
520 StoreEntry *
521 storeGetPublic(const char *uri, const HttpRequestMethod& method)
522 {
523  return Store::Root().find(storeKeyPublic(uri, method));
524 }
525 
526 StoreEntry *
528 {
529  return Store::Root().find(storeKeyPublicByRequestMethod(req, method, keyScope));
530 }
531 
532 StoreEntry *
534 {
535  StoreEntry *e = storeGetPublicByRequestMethod(req, req->method, keyScope);
536 
537  if (e == NULL && req->method == Http::METHOD_HEAD)
538  /* We can generate a HEAD reply from a cached GET object */
540 
541  return e;
542 }
543 
544 static int
546 {
547  static int key_counter = 0;
548 
549  if (++key_counter < 0)
550  key_counter = 1;
551 
552  return key_counter;
553 }
554 
555 /* RBC 20050104 AFAICT this should become simpler:
556  * rather than reinserting with a special key it should be marked
557  * as 'released' and then cleaned up when refcounting indicates.
558  * the StoreHashIndex could well implement its 'released' in the
559  * current manner.
560  * Also, clean log writing should skip over ia,t
561  * Otherwise, we need a 'remove from the index but not the store
562  * concept'.
563  */
564 void
565 StoreEntry::setPrivateKey(const bool shareable, const bool permanent)
566 {
567  debugs(20, 3, shareable << permanent << ' ' << *this);
568  if (permanent)
569  EBIT_SET(flags, RELEASE_REQUEST); // may already be set
570  if (!shareable)
571  shareableWhenPrivate = false; // may already be false
572 
574  return;
575 
576  if (key) {
577  Store::Root().evictCached(*this); // all caches/workers will know
578  hashDelete();
579  }
580 
581  if (mem_obj && mem_obj->hasUris())
582  mem_obj->id = getKeyCounter();
583  const cache_key *newkey = storeKeyPrivate();
584 
585  assert(hash_lookup(store_table, newkey) == NULL);
587  shareableWhenPrivate = shareable;
588  hashInsert(newkey);
589 }
590 
591 bool
593 {
594  debugs(20, 3, *this);
595  if (key && !EBIT_TEST(flags, KEY_PRIVATE))
596  return true; // already public
597 
598  assert(mem_obj);
599 
600  /*
601  * We can't make RELEASE_REQUEST objects public. Depending on
602  * when RELEASE_REQUEST gets set, we might not be swapping out
603  * the object. If we're not swapping out, then subsequent
604  * store clients won't be able to access object data which has
605  * been freed from memory.
606  *
607  * If RELEASE_REQUEST is set, setPublicKey() should not be called.
608  */
609 #if MORE_DEBUG_OUTPUT
610 
612  debugs(20, DBG_IMPORTANT, "assertion failed: RELEASE key " << key << ", url " << mem_obj->url);
613 
614 #endif
615 
617 
618  try {
619  EntryGuard newVaryMarker(adjustVary(), "setPublicKey+failure");
620  const cache_key *pubKey = calcPublicKey(scope);
621  Store::Root().addWriting(this, pubKey);
622  forcePublicKey(pubKey);
623  newVaryMarker.unlockAndReset("setPublicKey+success");
624  return true;
625  } catch (const std::exception &ex) {
626  debugs(20, 2, "for " << *this << " failed: " << ex.what());
627  }
628  return false;
629 }
630 
631 void
633 {
634  if (!key || EBIT_TEST(flags, KEY_PRIVATE))
635  return; // probably the old public key was deleted or made private
636 
637  // TODO: adjustVary() when collapsed revalidation supports that
638 
639  const cache_key *newKey = calcPublicKey(ksDefault);
640  if (!storeKeyHashCmp(key, newKey))
641  return; // probably another collapsed revalidation beat us to this change
642 
643  forcePublicKey(newKey);
644 }
645 
648 void
650 {
651  debugs(20, 3, storeKeyText(newkey) << " for " << *this);
652  assert(mem_obj);
653 
654  if (StoreEntry *e2 = (StoreEntry *)hash_lookup(store_table, newkey)) {
655  assert(e2 != this);
656  debugs(20, 3, "releasing clashing " << *e2);
657  e2->release(true);
658  }
659 
660  if (key)
661  hashDelete();
662 
663  clearPrivate();
664 
665  assert(mem_obj->hasUris());
666  hashInsert(newkey);
667 
668  if (hasDisk())
670 }
671 
674 const cache_key *
676 {
677  assert(mem_obj);
678  return mem_obj->request ? storeKeyPublicByRequest(mem_obj->request.getRaw(), keyScope) :
679  storeKeyPublic(mem_obj->storeId(), mem_obj->method, keyScope);
680 }
681 
687 StoreEntry *
689 {
690  assert(mem_obj);
691 
692  if (!mem_obj->request)
693  return nullptr;
694 
696  const auto &reply = mem_obj->freshestReply();
697 
698  if (mem_obj->vary_headers.isEmpty()) {
699  /* First handle the case where the object no longer varies */
700  request->vary_headers.clear();
701  } else {
702  if (!request->vary_headers.isEmpty() && request->vary_headers.cmp(mem_obj->vary_headers) != 0) {
703  /* Oops.. the variance has changed. Kill the base object
704  * to record the new variance key
705  */
706  request->vary_headers.clear(); /* free old "bad" variance key */
708  pe->release(true);
709  }
710 
711  /* Make sure the request knows the variance status */
712  if (request->vary_headers.isEmpty())
713  request->vary_headers = httpMakeVaryMark(request.getRaw(), &reply);
714  }
715 
716  // TODO: storeGetPublic() calls below may create unlocked entries.
717  // We should add/use storeHas() API or lock/unlock those entries.
719  /* Create "vary" base object */
721  // XXX: storeCreateEntry() already tries to make `pe` public under
722  // certain conditions. If those conditions do not apply to Vary markers,
723  // then refactor to call storeCreatePureEntry() above. Otherwise,
724  // refactor to simply check whether `pe` is already public below.
725  if (!pe->makePublic()) {
726  pe->unlock("StoreEntry::adjustVary+failed_makePublic");
727  throw TexcHere("failed to make Vary marker public");
728  }
729  /* We are allowed to do this typecast */
730  const HttpReplyPointer rep(new HttpReply);
731  rep->setHeaders(Http::scOkay, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
732  auto vary = reply.header.getList(Http::HdrType::VARY);
733 
734  if (vary.size()) {
735  /* Again, we own this structure layout */
736  rep->header.putStr(Http::HdrType::VARY, vary.termedBuf());
737  vary.clean();
738  }
739 
740 #if X_ACCELERATOR_VARY
741  vary = reply.header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY);
742 
743  if (vary.size() > 0) {
744  /* Again, we own this structure layout */
745  rep->header.putStr(Http::HdrType::HDR_X_ACCELERATOR_VARY, vary.termedBuf());
746  vary.clean();
747  }
748 
749 #endif
750  pe->replaceHttpReply(rep, false); // no write until timestampsSet()
751 
752  pe->timestampsSet();
753 
754  pe->startWriting(); // after timestampsSet()
755 
756  pe->complete();
757 
758  return pe;
759  }
760  return nullptr;
761 }
762 
763 StoreEntry *
764 storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod& method)
765 {
766  StoreEntry *e = NULL;
767  debugs(20, 3, "storeCreateEntry: '" << url << "'");
768 
769  e = new StoreEntry();
770  e->createMemObject(url, log_url, method);
771 
773  e->refcount = 0;
774  e->lastref = squid_curtime;
775  e->timestamp = -1; /* set in StoreEntry::timestampsSet() */
776  e->ping_status = PING_NONE;
778  return e;
779 }
780 
781 StoreEntry *
782 storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod& method)
783 {
785  e->lock("storeCreateEntry");
786 
787  if (!neighbors_do_private_keys && flags.hierarchical && flags.cachable && e->setPublicKey())
788  return e;
789 
790  e->setPrivateKey(false, !flags.cachable);
791  return e;
792 }
793 
794 /* Mark object as expired */
795 void
797 {
798  debugs(20, 3, "StoreEntry::expireNow: '" << getMD5Text() << "'");
800 }
801 
802 void
804 {
805  assert(mem_obj != NULL);
806  /* This assert will change when we teach the store to update */
807  PROF_start(StoreEntry_write);
809 
810  // XXX: caller uses content offset, but we also store headers
811  writeBuffer.offset += mem_obj->baseReply().hdr_sz;
812 
813  debugs(20, 5, "storeWrite: writing " << writeBuffer.length << " bytes for '" << getMD5Text() << "'");
814  PROF_stop(StoreEntry_write);
815  storeGetMemSpace(writeBuffer.length);
816  mem_obj->write(writeBuffer);
817 
819  debugs(20, 3, "allow Store clients to get entry content after buffering too much for " << *this);
821  }
822 
823  invokeHandlers();
824 }
825 
826 /* Append incoming data from a primary server to an entry. */
827 void
828 StoreEntry::append(char const *buf, int len)
829 {
830  assert(mem_obj != NULL);
831  assert(len >= 0);
833 
834  StoreIOBuffer tempBuffer;
835  tempBuffer.data = (char *)buf;
836  tempBuffer.length = len;
837  /*
838  * XXX sigh, offset might be < 0 here, but it gets "corrected"
839  * later. This offset crap is such a mess.
840  */
841  tempBuffer.offset = mem_obj->endOffset() - mem_obj->baseReply().hdr_sz;
842  write(tempBuffer);
843 }
844 
845 void
846 StoreEntry::vappendf(const char *fmt, va_list vargs)
847 {
848  LOCAL_ARRAY(char, buf, 4096);
849  *buf = 0;
850  int x;
851 
852  va_list ap;
853  /* Fix of bug 753r. The value of vargs is undefined
854  * after vsnprintf() returns. Make a copy of vargs
855  * in case we loop around and call vsnprintf() again.
856  */
857  va_copy(ap,vargs);
858  errno = 0;
859  if ((x = vsnprintf(buf, sizeof(buf), fmt, ap)) < 0) {
860  fatal(xstrerr(errno));
861  return;
862  }
863  va_end(ap);
864 
865  if (x < static_cast<int>(sizeof(buf))) {
866  append(buf, x);
867  return;
868  }
869 
870  // okay, do it the slow way.
871  char *buf2 = new char[x+1];
872  int y = vsnprintf(buf2, x+1, fmt, vargs);
873  assert(y >= 0 && y == x);
874  append(buf2, y);
875  delete[] buf2;
876 }
877 
878 // deprecated. use StoreEntry::appendf() instead.
879 void
880 storeAppendPrintf(StoreEntry * e, const char *fmt,...)
881 {
882  va_list args;
883  va_start(args, fmt);
884  e->vappendf(fmt, args);
885  va_end(args);
886 }
887 
888 // deprecated. use StoreEntry::appendf() instead.
889 void
890 storeAppendVPrintf(StoreEntry * e, const char *fmt, va_list vargs)
891 {
892  e->vappendf(fmt, vargs);
893 }
894 
896 
897  struct {
898  int non_get;
901  int too_big;
907  } no;
908 
909  struct {
910  int Default;
911  } yes;
913 
914 int
916 {
917  if (Config.max_open_disk_fds == 0)
918  return 0;
919 
921  return 1;
922 
923  return 0;
924 }
925 
926 int
928 {
930  return 0;
931 
932  if (STORE_OK == store_status)
933  if (mem_obj->object_sz >= 0 &&
935  return 1;
936 
937  const auto clen = mem().baseReply().content_length;
938  if (clen >= 0 && clen < Config.Store.minObjectSize)
939  return 1;
940  return 0;
941 }
942 
943 bool
945 {
947  return true;
948 
949  const auto clen = mem_obj->baseReply().content_length;
950  return (clen >= 0 && clen > store_maxobjsize);
951 }
952 
953 // TODO: move "too many open..." checks outside -- we are called too early/late
954 bool
956 {
957  // XXX: This method is used for both memory and disk caches, but some
958  // checks are specific to disk caches. Move them to mayStartSwapOut().
959 
960  // XXX: This method may be called several times, sometimes with different
961  // outcomes, making store_check_cachable_hist counters misleading.
962 
963  // check this first to optimize handling of repeated calls for uncachables
965  debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
967  return 0; // avoid rerequesting release below
968  }
969 
970 #if CACHE_ALL_METHODS
971 
972  if (mem_obj->method != Http::METHOD_GET) {
973  debugs(20, 2, "StoreEntry::checkCachable: NO: non-GET method");
975  } else
976 #endif
978  debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
980  } else if (!mem_obj) {
981  // XXX: In bug 4131, we forgetHit() without mem_obj, so we need
982  // this segfault protection, but how can we get such a HIT?
983  debugs(20, 2, "StoreEntry::checkCachable: NO: missing parts: " << *this);
985  } else if (checkTooBig()) {
986  debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
988  } else if (checkTooSmall()) {
989  debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
991  } else if (EBIT_TEST(flags, KEY_PRIVATE)) {
992  debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
994  } else if (hasDisk()) {
995  /*
996  * the remaining cases are only relevant if we haven't
997  * started swapping out the object yet.
998  */
999  return 1;
1000  } else if (storeTooManyDiskFilesOpen()) {
1001  debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
1003  } else if (fdNFree() < RESERVED_FD) {
1004  debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
1006  } else {
1008  return 1;
1009  }
1010 
1011  releaseRequest();
1012  return 0;
1013 }
1014 
1015 void
1017 {
1018  storeAppendPrintf(sentry, "Category\t Count\n");
1019 
1020 #if CACHE_ALL_METHODS
1021 
1022  storeAppendPrintf(sentry, "no.non_get\t%d\n",
1024 #endif
1025 
1026  storeAppendPrintf(sentry, "no.not_entry_cachable\t%d\n",
1028  storeAppendPrintf(sentry, "no.wrong_content_length\t%d\n",
1030  storeAppendPrintf(sentry, "no.negative_cached\t%d\n",
1031  0); // TODO: Remove this backward compatibility hack.
1032  storeAppendPrintf(sentry, "no.missing_parts\t%d\n",
1034  storeAppendPrintf(sentry, "no.too_big\t%d\n",
1036  storeAppendPrintf(sentry, "no.too_small\t%d\n",
1038  storeAppendPrintf(sentry, "no.private_key\t%d\n",
1040  storeAppendPrintf(sentry, "no.too_many_open_files\t%d\n",
1042  storeAppendPrintf(sentry, "no.too_many_open_fds\t%d\n",
1044  storeAppendPrintf(sentry, "yes.default\t%d\n",
1046 }
1047 
1048 void
1049 StoreEntry::lengthWentBad(const char *reason)
1050 {
1051  debugs(20, 3, "because " << reason << ": " << *this);
1053  releaseRequest();
1054 }
1055 
1056 void
1058 {
1059  debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1060 
1061  // To preserve forwarding retries, call FwdState::complete() instead.
1063 
1064  if (store_status != STORE_PENDING) {
1065  /*
1066  * if we're not STORE_PENDING, then probably we got aborted
1067  * and there should be NO clients on this entry
1068  */
1070  assert(mem_obj->nclients == 0);
1071  return;
1072  }
1073 
1075 
1077 
1079 
1081  lengthWentBad("!validLength() in complete()");
1082 
1083 #if USE_CACHE_DIGESTS
1084  if (mem_obj->request)
1086 
1087 #endif
1088  /*
1089  * We used to call invokeHandlers, then storeSwapOut. However,
1090  * Madhukar Reddy <myreddy@persistence.com> reported that
1091  * responses without content length would sometimes get released
1092  * in client_side, thinking that the response is incomplete.
1093  */
1094  invokeHandlers();
1095 }
1096 
1097 /*
1098  * Someone wants to abort this transfer. Set the reason in the
1099  * request structure, call the callback and mark the
1100  * entry for releasing
1101  */
1102 void
1104 {
1107  assert(mem_obj != NULL);
1108  debugs(20, 6, "storeAbort: " << getMD5Text());
1109 
1110  lock("StoreEntry::abort"); /* lock while aborting */
1111  negativeCache();
1112 
1113  releaseRequest();
1114 
1116 
1117  // allow the Store clients to be told about the problem
1119 
1121 
1123 
1124  /* Notify the server side */
1125 
1126  if (mem_obj->abortCallback) {
1128  mem_obj->abortCallback = nullptr;
1129  }
1130 
1131  /* XXX Should we reverse these two, so that there is no
1132  * unneeded disk swapping triggered?
1133  */
1134  /* Notify the client side */
1135  invokeHandlers();
1136 
1137  // abort swap out, invalidating what was created so far (release follows)
1139 
1140  unlock("StoreEntry::abort"); /* unlock */
1141 }
1142 
1146 void
1148 {
1150  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1153 }
1154 
1155 /* thunk through to Store::Root().maintain(). Note that this would be better still
1156  * if registered against the root store itself, but that requires more complex
1157  * update logic - bigger fish to fry first. Long term each store when
1158  * it becomes active will self register
1159  */
1160 void
1162 {
1163  Store::Root().maintain();
1164 
1165  /* Reregister a maintain event .. */
1166  eventAdd("MaintainSwapSpace", Maintain, NULL, 1.0, 1);
1167 
1168 }
1169 
1170 /* The maximum objects to scan for maintain storage space */
1171 #define MAINTAIN_MAX_SCAN 1024
1172 #define MAINTAIN_MAX_REMOVE 64
1173 
1174 void
1175 StoreEntry::release(const bool shareable)
1176 {
1177  PROF_start(storeRelease);
1178  debugs(20, 3, shareable << ' ' << *this << ' ' << getMD5Text());
1179  /* If, for any reason we can't discard this object because of an
1180  * outstanding request, mark it for pending release */
1181 
1182  if (locked()) {
1183  releaseRequest(shareable);
1184  PROF_stop(storeRelease);
1185  return;
1186  }
1187 
1189  /* TODO: Teach disk stores to handle releases during rebuild instead. */
1190 
1191  // lock the entry until rebuilding is done
1192  lock("storeLateRelease");
1193  releaseRequest(shareable);
1194  LateReleaseStack.push(this);
1195  PROF_stop(storeRelease);
1196  return;
1197  }
1198 
1199  storeLog(STORE_LOG_RELEASE, this);
1200  Store::Root().evictCached(*this);
1201  destroyStoreEntry(static_cast<hash_link *>(this));
1202  PROF_stop(storeRelease);
1203 }
1204 
1205 static void
1207 {
1208  StoreEntry *e;
1209  static int n = 0;
1210 
1212  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1213  return;
1214  }
1215 
1216  // TODO: this works but looks unelegant.
1217  for (int i = 0; i < 10; ++i) {
1218  if (LateReleaseStack.empty()) {
1219  debugs(20, DBG_IMPORTANT, "storeLateRelease: released " << n << " objects");
1220  return;
1221  } else {
1222  e = LateReleaseStack.top();
1223  LateReleaseStack.pop();
1224  }
1225 
1226  e->unlock("storeLateRelease");
1227  ++n;
1228  }
1229 
1230  eventAdd("storeLateRelease", storeLateRelease, NULL, 0.0, 1);
1231 }
1232 
1236 bool
1238 {
1239  int64_t diff;
1240  assert(mem_obj != NULL);
1241  const auto reply = &mem_obj->baseReply();
1242  debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1243  debugs(20, 5, "storeEntryValidLength: object_len = " <<
1244  objectLen());
1245  debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply->hdr_sz);
1246  debugs(20, 5, "storeEntryValidLength: content_length = " << reply->content_length);
1247 
1248  if (reply->content_length < 0) {
1249  debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1250  return 1;
1251  }
1252 
1253  if (reply->hdr_sz == 0) {
1254  debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1255  return 1;
1256  }
1257 
1258  if (mem_obj->method == Http::METHOD_HEAD) {
1259  debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1260  return 1;
1261  }
1262 
1263  if (reply->sline.status() == Http::scNotModified)
1264  return 1;
1265 
1266  if (reply->sline.status() == Http::scNoContent)
1267  return 1;
1268 
1269  diff = reply->hdr_sz + reply->content_length - objectLen();
1270 
1271  if (diff == 0)
1272  return 1;
1273 
1274  debugs(20, 3, "storeEntryValidLength: " << (diff < 0 ? -diff : diff) << " bytes too " << (diff < 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1275 
1276  return 0;
1277 }
1278 
1279 static void
1281 {
1282  Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats, 0, 1);
1283  Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create, 0, 1);
1284  Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1285  storeCheckCachableStats, 0, 1);
1286  Mgr::RegisterAction("store_queues", "SMP Transients and Caching Queues", StatQueues, 0, 1);
1287 }
1288 
1289 void
1291 {
1292  storeKeyInit();
1294  storeDigestInit();
1295  storeLogOpen();
1296  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1297  Store::Root().init();
1299 
1301 }
1302 
1303 void
1305 {
1306  Store::Root().configure();
1307 }
1308 
1309 bool
1311 {
1312  if (!checkCachable())
1313  return 0;
1314 
1315  if (mem_obj == NULL)
1316  return 0;
1317 
1318  if (mem_obj->data_hdr.size() == 0)
1319  return 0;
1320 
1321  if (mem_obj->inmem_lo != 0)
1322  return 0;
1323 
1325  return 0;
1326 
1327  return 1;
1328 }
1329 
1330 int
1332 {
1334  return 0;
1335 
1336  if (expires <= squid_curtime)
1337  return 0;
1338 
1339  if (store_status != STORE_OK)
1340  return 0;
1341 
1342  return 1;
1343 }
1344 
1351 void
1353 {
1354  // XXX: should make the default for expires 0 instead of -1
1355  // so we can distinguish "Expires: -1" from nothing.
1356  if (expires <= 0)
1357 #if USE_HTTP_VIOLATIONS
1359 #else
1361 #endif
1362  if (expires > squid_curtime) {
1364  debugs(20, 6, "expires = " << expires << " +" << (expires-squid_curtime) << ' ' << *this);
1365  }
1366 }
1367 
1368 void
1370 {
1372 #if USE_CACHE_DIGESTS
1373  delete store_digest;
1374 #endif
1375  store_digest = NULL;
1376 }
1377 
1378 int
1379 expiresMoreThan(time_t expires, time_t when)
1380 {
1381  if (expires < 0) /* No Expires given */
1382  return 1;
1383 
1384  return (expires > (squid_curtime + when));
1385 }
1386 
1387 int
1389 {
1391  return 0;
1392 
1394  if (expires <= squid_curtime)
1395  return 0;
1396 
1398  return 0;
1399 
1400  // now check that the entry has a cache backing or is collapsed
1401  if (hasDisk()) // backed by a disk cache
1402  return 1;
1403 
1404  if (swappingOut()) // will be backed by a disk cache
1405  return 1;
1406 
1407  if (!mem_obj) // not backed by a memory cache and not collapsed
1408  return 0;
1409 
1410  // StoreEntry::storeClientType() assumes DISK_CLIENT here, but there is no
1411  // disk cache backing that store_client constructor will assert. XXX: This
1412  // is wrong for range requests (that could feed off nibbled memory) and for
1413  // entries backed by the shared memory cache (that could, in theory, get
1414  // nibbled bytes from that cache, but there is no such "memoryIn" code).
1415  if (mem_obj->inmem_lo) // in memory cache, but got nibbled at
1416  return 0;
1417 
1418  // The following check is correct but useless at this position. TODO: Move
1419  // it up when the shared memory cache can either replenish locally nibbled
1420  // bytes or, better, does not use local RAM copy at all.
1421  // if (mem_obj->memCache.index >= 0) // backed by a shared memory cache
1422  // return 1;
1423 
1424  return 1;
1425 }
1426 
1427 bool
1429 {
1430  debugs(20, 7, *this << " had " << describeTimestamps());
1431 
1432  // TODO: Remove change-reducing "&" before the official commit.
1433  const auto reply = &mem().freshestReply();
1434 
1435  time_t served_date = reply->date;
1436  int age = reply->header.getInt(Http::HdrType::AGE);
1437  /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1438  /* make sure that 0 <= served_date <= squid_curtime */
1439 
1440  if (served_date < 0 || served_date > squid_curtime)
1441  served_date = squid_curtime;
1442 
1443  /* Bug 1791:
1444  * If the returned Date: is more than 24 hours older than
1445  * the squid_curtime, then one of us needs to use NTP to set our
1446  * clock. We'll pretend that our clock is right.
1447  */
1448  else if (served_date < (squid_curtime - 24 * 60 * 60) )
1449  served_date = squid_curtime;
1450 
1451  /*
1452  * Compensate with Age header if origin server clock is ahead
1453  * of us and there is a cache in between us and the origin
1454  * server. But DONT compensate if the age value is larger than
1455  * squid_curtime because it results in a negative served_date.
1456  */
1457  if (age > squid_curtime - served_date)
1458  if (squid_curtime > age)
1459  served_date = squid_curtime - age;
1460 
1461  // compensate for Squid-to-server and server-to-Squid delays
1462  if (mem_obj && mem_obj->request) {
1463  struct timeval responseTime;
1464  if (mem_obj->request->hier.peerResponseTime(responseTime))
1465  served_date -= responseTime.tv_sec;
1466  }
1467 
1468  time_t exp = 0;
1469  if (reply->expires > 0 && reply->date > -1)
1470  exp = served_date + (reply->expires - reply->date);
1471  else
1472  exp = reply->expires;
1473 
1474  if (timestamp == served_date && expires == exp) {
1475  // if the reply lacks LMT, then we now know that our effective
1476  // LMT (i.e., timestamp) will stay the same, otherwise, old and
1477  // new modification times must match
1478  if (reply->last_modified < 0 || reply->last_modified == lastModified())
1479  return false; // nothing has changed
1480  }
1481 
1482  expires = exp;
1483 
1484  lastModified_ = reply->last_modified;
1485 
1486  timestamp = served_date;
1487 
1488  debugs(20, 5, *this << " has " << describeTimestamps());
1489  return true;
1490 }
1491 
1492 bool
1494 {
1495  assert(mem_obj);
1496  assert(e304.mem_obj);
1497 
1498  // update reply before calling timestampsSet() below
1499  const auto &oldReply = mem_obj->freshestReply();
1500  const auto updatedReply = oldReply.recreateOnNotModified(e304.mem_obj->baseReply());
1501  if (updatedReply) // HTTP 304 brought in new information
1502  mem_obj->updateReply(*updatedReply);
1503  // else continue to use the previous update, if any
1504 
1505  if (!timestampsSet() && !updatedReply)
1506  return false;
1507 
1508  // Keep the old mem_obj->vary_headers; see HttpHeader::skipUpdateHeader().
1509 
1510  debugs(20, 5, "updated basics in " << *this << " with " << e304);
1511  mem_obj->appliedUpdates = true; // helps in triage; may already be true
1512  return true;
1513 }
1514 
1515 void
1517 {
1518  assert(mem_obj);
1521 }
1522 
1523 void
1525 {
1526  assert(mem_obj);
1527  if (mem_obj->abortCallback) {
1528  mem_obj->abortCallback->cancel(reason);
1529  mem_obj->abortCallback = nullptr;
1530  }
1531 }
1532 
1533 void
1534 StoreEntry::dump(int l) const
1535 {
1536  debugs(20, l, "StoreEntry->key: " << getMD5Text());
1537  debugs(20, l, "StoreEntry->next: " << next);
1538  debugs(20, l, "StoreEntry->mem_obj: " << mem_obj);
1539  debugs(20, l, "StoreEntry->timestamp: " << timestamp);
1540  debugs(20, l, "StoreEntry->lastref: " << lastref);
1541  debugs(20, l, "StoreEntry->expires: " << expires);
1542  debugs(20, l, "StoreEntry->lastModified_: " << lastModified_);
1543  debugs(20, l, "StoreEntry->swap_file_sz: " << swap_file_sz);
1544  debugs(20, l, "StoreEntry->refcount: " << refcount);
1545  debugs(20, l, "StoreEntry->flags: " << storeEntryFlags(this));
1546  debugs(20, l, "StoreEntry->swap_dirn: " << swap_dirn);
1547  debugs(20, l, "StoreEntry->swap_filen: " << swap_filen);
1548  debugs(20, l, "StoreEntry->lock_count: " << lock_count);
1549  debugs(20, l, "StoreEntry->mem_status: " << mem_status);
1550  debugs(20, l, "StoreEntry->ping_status: " << ping_status);
1551  debugs(20, l, "StoreEntry->store_status: " << store_status);
1552  debugs(20, l, "StoreEntry->swap_status: " << swap_status);
1553 }
1554 
1555 /*
1556  * NOTE, this function assumes only two mem states
1557  */
1558 void
1560 {
1561  if (new_status == mem_status)
1562  return;
1563 
1564  // are we using a shared memory cache?
1565  if (MemStore::Enabled()) {
1566  // This method was designed to update replacement policy, not to
1567  // actually purge something from the memory cache (TODO: rename?).
1568  // Shared memory cache does not have a policy that needs updates.
1569  mem_status = new_status;
1570  return;
1571  }
1572 
1573  assert(mem_obj != NULL);
1574 
1575  if (new_status == IN_MEMORY) {
1576  assert(mem_obj->inmem_lo == 0);
1577 
1578  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1579  debugs(20, 4, "not inserting special " << *this << " into policy");
1580  } else {
1581  mem_policy->Add(mem_policy, this, &mem_obj->repl);
1582  debugs(20, 4, "inserted " << *this << " key: " << getMD5Text());
1583  }
1584 
1585  ++hot_obj_count; // TODO: maintain for the shared hot cache as well
1586  } else {
1587  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1588  debugs(20, 4, "not removing special " << *this << " from policy");
1589  } else {
1591  debugs(20, 4, "removed " << *this);
1592  }
1593 
1594  --hot_obj_count;
1595  }
1596 
1597  mem_status = new_status;
1598 }
1599 
1600 const char *
1602 {
1603  if (mem_obj == NULL)
1604  return "[null_mem_obj]";
1605  else
1606  return mem_obj->storeId();
1607 }
1608 
1609 void
1611 {
1612  assert(!mem_obj);
1613  mem_obj = new MemObject();
1614 }
1615 
1616 void
1617 StoreEntry::createMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1618 {
1619  assert(!mem_obj);
1620  ensureMemObject(aUrl, aLogUrl, aMethod);
1621 }
1622 
1623 void
1624 StoreEntry::ensureMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1625 {
1626  if (!mem_obj)
1627  mem_obj = new MemObject();
1628  mem_obj->setUris(aUrl, aLogUrl, aMethod);
1629 }
1630 
1635 void
1637 {
1639 }
1640 
1646 void
1648 {
1649  if (EBIT_TEST(flags, DELAY_SENDING)) {
1651  invokeHandlers();
1652  }
1653 }
1654 
1655 void
1657 {
1658  debugs(20, 3, url());
1659  mem().reset();
1660  expires = lastModified_ = timestamp = -1;
1661 }
1662 
1663 /*
1664  * storeFsInit
1665  *
1666  * This routine calls the SETUP routine for each fs type.
1667  * I don't know where the best place for this is, and I'm not going to shuffle
1668  * around large chunks of code right now (that can be done once its working.)
1669  */
1670 void
1672 {
1673  storeReplSetup();
1674 }
1675 
1676 /*
1677  * called to add another store removal policy module
1678  */
1679 void
1680 storeReplAdd(const char *type, REMOVALPOLICYCREATE * create)
1681 {
1682  int i;
1683 
1684  /* find the number of currently known repl types */
1685  for (i = 0; storerepl_list && storerepl_list[i].typestr; ++i) {
1686  if (strcmp(storerepl_list[i].typestr, type) == 0) {
1687  debugs(20, DBG_IMPORTANT, "WARNING: Trying to load store replacement policy " << type << " twice.");
1688  return;
1689  }
1690  }
1691 
1692  /* add the new type */
1693  storerepl_list = static_cast<storerepl_entry_t *>(xrealloc(storerepl_list, (i + 2) * sizeof(storerepl_entry_t)));
1694 
1695  memset(&storerepl_list[i + 1], 0, sizeof(storerepl_entry_t));
1696 
1698 
1699  storerepl_list[i].create = create;
1700 }
1701 
1702 /*
1703  * Create a removal policy instance
1704  */
1705 RemovalPolicy *
1707 {
1708  storerepl_entry_t *r;
1709 
1710  for (r = storerepl_list; r && r->typestr; ++r) {
1711  if (strcmp(r->typestr, settings->type) == 0)
1712  return r->create(settings->args);
1713  }
1714 
1715  debugs(20, DBG_IMPORTANT, "ERROR: Unknown policy " << settings->type);
1716  debugs(20, DBG_IMPORTANT, "ERROR: Be sure to have set cache_replacement_policy");
1717  debugs(20, DBG_IMPORTANT, "ERROR: and memory_replacement_policy in squid.conf!");
1718  fatalf("ERROR: Unknown policy %s\n", settings->type);
1719  return NULL; /* NOTREACHED */
1720 }
1721 
1722 #if 0
1723 void
1725 {
1726  if (e->swap_file_number == filn)
1727  return;
1728 
1729  if (filn < 0) {
1730  assert(-1 == filn);
1731  storeDirMapBitReset(e->swap_file_number);
1732  storeDirLRUDelete(e);
1733  e->swap_file_number = -1;
1734  } else {
1735  assert(-1 == e->swap_file_number);
1736  storeDirMapBitSet(e->swap_file_number = filn);
1737  storeDirLRUAdd(e);
1738  }
1739 }
1740 
1741 #endif
1742 
1743 void
1745 {
1746  lock("StoreEntry::storeErrorResponse");
1747  buffer();
1749  flush();
1750  complete();
1751  negativeCache();
1752  releaseRequest(false); // if it is safe to negatively cache, sharing is OK
1753  unlock("StoreEntry::storeErrorResponse");
1754 }
1755 
1756 /*
1757  * Replace a store entry with
1758  * a new reply. This eats the reply.
1759  */
1760 void
1761 StoreEntry::replaceHttpReply(const HttpReplyPointer &rep, const bool andStartWriting)
1762 {
1763  debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1764 
1765  if (!mem_obj) {
1766  debugs(20, DBG_CRITICAL, "Attempt to replace object with no in-memory representation");
1767  return;
1768  }
1769 
1770  mem_obj->replaceBaseReply(rep);
1771 
1772  if (andStartWriting)
1773  startWriting();
1774 }
1775 
1776 void
1778 {
1779  /* TODO: when we store headers separately remove the header portion */
1780  /* TODO: mark the length of the headers ? */
1781  /* We ONLY want the headers */
1782  assert (isEmpty());
1783  assert(mem_obj);
1784 
1785  // Per MemObject replies definitions, we can only write our base reply.
1786  // Currently, all callers replaceHttpReply() first, so there is no updated
1787  // reply here anyway. Eventually, we may need to support the
1788  // updateOnNotModified(),startWriting() sequence as well.
1790  const auto rep = &mem_obj->baseReply();
1791 
1792  buffer();
1793  rep->packHeadersUsingSlowPacker(*this);
1795 
1796  rep->body.packInto(this);
1797  flush();
1798 
1799  // The entry headers are written, new clients
1800  // should not collapse anymore.
1801  if (hittingRequiresCollapsing()) {
1802  setCollapsingRequirement(false);
1804  }
1805 }
1806 
1807 char const *
1809 {
1810  StoreMeta *tlv_list = storeSwapMetaBuild(this);
1811  int swap_hdr_sz;
1812  char *result = storeSwapMetaPack(tlv_list, &swap_hdr_sz);
1813  storeSwapTLVFree(tlv_list);
1814  assert (swap_hdr_sz >= 0);
1815  length = static_cast<size_t>(swap_hdr_sz);
1816  return result;
1817 }
1818 
1825 void
1827 {
1828  if (mem_obj && !Store::Root().transientsReader(*this) && // this worker is responsible
1829  hasTransients() && // other workers may be interested
1830  !hasMemStore() && // rejected by the shared memory cache
1832  debugs(20, 7, "cannot be shared: " << *this);
1833  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1834  Store::Root().stopSharing(*this);
1835  }
1836 }
1837 
1838 void
1840 {
1842 }
1843 
1844 void
1846 {
1847  // Abandon our transient entry if neither shared memory nor disk wants it.
1848  assert(mem_obj);
1849  mem_obj->swapout.decision = decision;
1851 }
1852 
1853 void
1854 StoreEntry::trimMemory(const bool preserveSwappable)
1855 {
1856  /*
1857  * DPW 2007-05-09
1858  * Bug #1943. We must not let go any data for IN_MEMORY
1859  * objects. We have to wait until the mem_status changes.
1860  */
1861  if (mem_status == IN_MEMORY)
1862  return;
1863 
1865  return; // cannot trim because we do not load them again
1866 
1867  if (preserveSwappable)
1869  else
1871 
1872  debugs(88, 7, *this << " inmem_lo=" << mem_obj->inmem_lo);
1873 }
1874 
1875 bool
1876 StoreEntry::modifiedSince(const time_t ims, const int imslen) const
1877 {
1878  const time_t mod_time = lastModified();
1879 
1880  debugs(88, 3, "modifiedSince: '" << url() << "'");
1881 
1882  debugs(88, 3, "modifiedSince: mod_time = " << mod_time);
1883 
1884  if (mod_time < 0)
1885  return true;
1886 
1887  assert(imslen < 0); // TODO: Either remove imslen or support it properly.
1888 
1889  if (mod_time > ims) {
1890  debugs(88, 3, "--> YES: entry newer than client");
1891  return true;
1892  } else if (mod_time < ims) {
1893  debugs(88, 3, "--> NO: entry older than client");
1894  return false;
1895  } else {
1896  debugs(88, 3, "--> NO: same LMT");
1897  return false;
1898  }
1899 }
1900 
1901 bool
1903 {
1904  if (const auto reply = hasFreshestReply()) {
1905  etag = reply->header.getETag(Http::HdrType::ETAG);
1906  if (etag.str)
1907  return true;
1908  }
1909  return false;
1910 }
1911 
1912 bool
1914 {
1915  const String reqETags = request.header.getList(Http::HdrType::IF_MATCH);
1916  return hasOneOfEtags(reqETags, false);
1917 }
1918 
1919 bool
1921 {
1922  const String reqETags = request.header.getList(Http::HdrType::IF_NONE_MATCH);
1923  // weak comparison is allowed only for HEAD or full-body GET requests
1924  const bool allowWeakMatch = !request.flags.isRanged &&
1926  return hasOneOfEtags(reqETags, allowWeakMatch);
1927 }
1928 
1930 bool
1931 StoreEntry::hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
1932 {
1933  const auto repETag = mem().freshestReply().header.getETag(Http::HdrType::ETAG);
1934  if (!repETag.str) {
1935  static SBuf asterisk("*", 1);
1936  return strListIsMember(&reqETags, asterisk, ',');
1937  }
1938 
1939  bool matched = false;
1940  const char *pos = NULL;
1941  const char *item;
1942  int ilen;
1943  while (!matched && strListGetItem(&reqETags, ',', &item, &ilen, &pos)) {
1944  if (!strncmp(item, "*", ilen))
1945  matched = true;
1946  else {
1947  String str;
1948  str.append(item, ilen);
1949  ETag reqETag;
1950  if (etagParseInit(&reqETag, str.termedBuf())) {
1951  matched = allowWeakMatch ? etagIsWeakEqual(repETag, reqETag) :
1952  etagIsStrongEqual(repETag, reqETag);
1953  }
1954  }
1955  }
1956  return matched;
1957 }
1958 
1959 Store::Disk &
1961 {
1962  assert(hasDisk());
1964  assert(sd);
1965  return *sd;
1966 }
1967 
1968 bool
1969 StoreEntry::hasDisk(const sdirno dirn, const sfileno filen) const
1970 {
1971  checkDisk();
1972  if (dirn < 0 && filen < 0)
1973  return swap_dirn >= 0;
1974  Must(dirn >= 0);
1975  const bool matchingDisk = (swap_dirn == dirn);
1976  return filen < 0 ? matchingDisk : (matchingDisk && swap_filen == filen);
1977 }
1978 
1979 void
1980 StoreEntry::attachToDisk(const sdirno dirn, const sfileno fno, const swap_status_t status)
1981 {
1982  debugs(88, 3, "attaching entry with key " << getMD5Text() << " : " <<
1983  swapStatusStr[status] << " " << dirn << " " <<
1984  std::hex << std::setw(8) << std::setfill('0') <<
1985  std::uppercase << fno);
1986  checkDisk();
1987  swap_dirn = dirn;
1988  swap_filen = fno;
1989  swap_status = status;
1990  checkDisk();
1991 }
1992 
1993 void
1995 {
1996  swap_dirn = -1;
1997  swap_filen = -1;
1999 }
2000 
2001 void
2003 {
2004  try {
2005  if (swap_dirn < 0) {
2006  Must(swap_filen < 0);
2008  } else {
2009  Must(swap_filen >= 0);
2011  if (swapoutFailed()) {
2013  } else {
2014  Must(swappingOut() || swappedOut());
2015  }
2016  }
2017  } catch (...) {
2018  debugs(88, DBG_IMPORTANT, "ERROR: inconsistent disk entry state " <<
2019  *this << "; problem: " << CurrentException);
2020  throw;
2021  }
2022 }
2023 
2024 /*
2025  * return true if the entry is in a state where
2026  * it can accept more data (ie with write() method)
2027  */
2028 bool
2030 {
2031  if (STORE_PENDING != store_status)
2032  return false;
2033 
2035  return false;
2036 
2037  return true;
2038 }
2039 
2040 const char *
2042 {
2043  LOCAL_ARRAY(char, buf, 256);
2044  snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
2045  static_cast<int>(timestamp),
2046  static_cast<int>(lastref),
2047  static_cast<int>(lastModified_),
2048  static_cast<int>(expires));
2049  return buf;
2050 }
2051 
2052 void
2054 {
2055  if (required)
2057  else
2059 }
2060 
2061 static std::ostream &
2062 operator <<(std::ostream &os, const Store::IoStatus &io)
2063 {
2064  switch (io) {
2065  case Store::ioUndecided:
2066  os << 'u';
2067  break;
2068  case Store::ioReading:
2069  os << 'r';
2070  break;
2071  case Store::ioWriting:
2072  os << 'w';
2073  break;
2074  case Store::ioDone:
2075  os << 'o';
2076  break;
2077  }
2078  return os;
2079 }
2080 
2081 std::ostream &operator <<(std::ostream &os, const StoreEntry &e)
2082 {
2083  os << "e:";
2084 
2085  if (e.hasTransients()) {
2086  const auto &xitTable = e.mem_obj->xitTable;
2087  os << 't' << xitTable.io << xitTable.index;
2088  }
2089 
2090  if (e.hasMemStore()) {
2091  const auto &memCache = e.mem_obj->memCache;
2092  os << 'm' << memCache.io << memCache.index << '@' << memCache.offset;
2093  }
2094 
2095  // Do not use e.hasDisk() here because its checkDisk() call may calls us.
2096  if (e.swap_filen > -1 || e.swap_dirn > -1)
2097  os << 'd' << e.swap_filen << '@' << e.swap_dirn;
2098 
2099  os << '=';
2100 
2101  // print only non-default status values, using unique letters
2102  if (e.mem_status != NOT_IN_MEMORY ||
2103  e.store_status != STORE_PENDING ||
2104  e.swap_status != SWAPOUT_NONE ||
2105  e.ping_status != PING_NONE) {
2106  if (e.mem_status != NOT_IN_MEMORY) os << 'm';
2107  if (e.store_status != STORE_PENDING) os << 's';
2108  if (e.swap_status != SWAPOUT_NONE) os << 'w' << e.swap_status;
2109  if (e.ping_status != PING_NONE) os << 'p' << e.ping_status;
2110  }
2111 
2112  // print only set flags, using unique letters
2113  if (e.flags) {
2114  if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) os << 'S';
2115  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_ALWAYS)) os << 'R';
2116  if (EBIT_TEST(e.flags, DELAY_SENDING)) os << 'P';
2117  if (EBIT_TEST(e.flags, RELEASE_REQUEST)) os << 'X';
2118  if (EBIT_TEST(e.flags, REFRESH_REQUEST)) os << 'F';
2119  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_STALE)) os << 'E';
2120  if (EBIT_TEST(e.flags, KEY_PRIVATE)) {
2121  os << 'I';
2122  if (e.shareableWhenPrivate)
2123  os << 'H';
2124  }
2125  if (EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT)) os << 'W';
2126  if (EBIT_TEST(e.flags, ENTRY_NEGCACHED)) os << 'N';
2127  if (EBIT_TEST(e.flags, ENTRY_VALIDATED)) os << 'V';
2128  if (EBIT_TEST(e.flags, ENTRY_BAD_LENGTH)) os << 'L';
2129  if (EBIT_TEST(e.flags, ENTRY_ABORTED)) os << 'A';
2130  if (EBIT_TEST(e.flags, ENTRY_REQUIRES_COLLAPSING)) os << 'C';
2131  }
2132 
2133  return os << '/' << &e << '*' << e.locks();
2134 }
2135 
2136 void
2138 {
2140  entry_->releaseRequest(false);
2142  });
2143 }
2144 
#define EBIT_CLR(flag, bit)
Definition: defines.h:106
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:629
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:309
Definition: store.cc:103
HASHCMP storeKeyHashCmp
void Maintain(void *unused)
Definition: store.cc:1161
virtual void buffer()
Definition: store.cc:1636
void abandon(const char *context)
Definition: Store.h:276
#define INDEXSD(i)
Definition: SquidConfig.h:71
int checkTooSmall()
Definition: store.cc:927
time_t timestamp
Definition: Store.h:216
@ 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:270
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:1237
void storeReplAdd(const char *type, REMOVALPOLICYCREATE *create)
Definition: store.cc:1680
bool updateOnNotModified(const StoreEntry &e304)
Definition: store.cc:1493
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:1624
const char * storeId() const
Definition: MemObject.cc:54
void unregisterAbortCallback(const char *reason)
Definition: store.cc:1524
void releaseRequest(const bool shareable=false)
Definition: store.cc:472
StoreEntry * adjustVary()
Definition: store.cc:688
static OBJH storeCheckCachableStats
Definition: store.cc:114
@ ENTRY_REVALIDATE_STALE
Definition: enums.h:100
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod const KeyScope scope const char const RequestFlags const HttpRequestMethod const char * logUrl
Definition: stub_store.cc:107
void checkDisk() const
does nothing except throwing if disk-associated data members are inconsistent
Definition: store.cc:2002
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:105
StoreEntry()
Definition: store.cc:350
int memory_cache_first
Definition: SquidConfig.h:341
bool isEmpty() const
Definition: SBuf.h:420
virtual void flush()
Definition: store.cc:1647
MemObject * mem_obj
Definition: Store.h:213
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:430
@ DELAY_SENDING
Definition: enums.h:97
void clearPublicKeyScope()
Definition: store.cc:632
C end
Definition: Range.h:25
void destroyStoreEntry(void *data)
Definition: store.cc:416
const char * url() const
Definition: store.cc:1601
void trimUnSwappable()
Definition: MemObject.cc:411
void storeInit(void)
Definition: store.cc:1290
void createMemObject()
Definition: store.cc:1610
MemObject & mem()
Definition: Store.h:52
bool shareableWhenPrivate
Definition: Store.h:320
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:880
void lock(const char *context)
Definition: store.cc:459
void FreeMemory()
undo Init()
Definition: Controller.cc:951
void transientsAbandonmentCheck()
Definition: store.cc:1826
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:224
@ KEY_PRIVATE
Definition: enums.h:102
Definition: SBuf.h:87
virtual void init() override
Definition: Controller.cc:59
void detachFromDisk()
Definition: store.cc:1994
void onException() noexcept
Definition: store.cc:2137
void touch()
update last reference timestamp and related Store metadata
Definition: store.cc:466
void setNoDelay(bool const newValue)
Definition: MemObject.cc:444
Io io
current I/O state
Definition: MemObject.h:173
void setPrivateKey(const bool shareable, const bool permanent)
Definition: store.cc:565
const char * str
quoted-string
Definition: ETag.h:20
@ REFRESH_REQUEST
Definition: enums.h:99
void configure()
update configuration, including limits (re)calculation
Definition: Controller.cc:198
static std::ostream & operator<<(std::ostream &os, const Store::IoStatus &io)
Definition: store.cc:2062
@ ENTRY_NEGCACHED
Definition: enums.h:112
bool setPublicKey(const KeyScope keyScope=ksDefault)
Definition: store.cc:592
Entry * entry_
the guarded Entry or nil
Definition: Store.h:379
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:220
uint16_t flags
Definition: Store.h:224
struct _store_check_cachable_hist store_check_cachable_hist
void storeGetMemSpace(int size)
Definition: store.cc:1147
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:408
int locks() const
returns a local concurrent use counter, for debugging
Definition: Store.h:261
static storerepl_entry_t * storerepl_list
Definition: store.cc:108
bool isAccepting() const
Definition: store.cc:2029
time_t expires
Definition: Store.h:218
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:427
Io io
current I/O state
Definition: MemObject.h:184
char * storeSwapMetaPack(tlv *tlv_list, int *length)
int64_t endOffset() const
Definition: MemObject.cc:235
static void storeRegisterWithCacheManager(void)
Definition: store.cc:1280
int64_t objectLen() const
Definition: Store.h:249
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1761
#define DBG_CRITICAL
Definition: Debug.h:45
swap_status_t
StoreEntry relationship with a disk cache.
Definition: enums.h:55
void startWriting()
Definition: store.cc:1777
void storeSwapFileNumberSet(StoreEntry *e, sfileno filn)
SQUIDCEXTERN void hash_join(hash_table *, hash_link *)
Definition: hash.cc:132
@ SWAP_LOG_ADD
Definition: swap_log_op.h:14
RemovalPolicy * mem_policy
Definition: MemObject.cc:45
#define PROF_stop(probename)
Definition: Profiler.h:63
void storeFsInit(void)
Definition: store.cc:1671
int store_open_disk_fd
void reset()
Definition: store.cc:1656
#define DBG_IMPORTANT
Definition: Debug.h:46
virtual void evictCached(StoreEntry &) override
Definition: Controller.cc:502
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:533
void destroyMemObject()
Definition: store.cc:398
int64_t inmem_lo
Definition: MemObject.h:139
int len
Definition: CommRead.h:27
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:612
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:527
#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:143
void storeReplSetup(void)
static DeferredRead::DeferrableRead DeferReader
Definition: Store.h:45
void addWriting(StoreEntry *, const cache_key *)
Definition: Controller.cc:783
@ ENTRY_BAD_LENGTH
Definition: enums.h:114
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:65
Definition: Range.h:19
enum _mem_status_t mem_status_t
@ ENTRY_SPECIAL
Definition: enums.h:84
int validToSend() const
Definition: store.cc:1388
@ ENTRY_FWD_HDR_WAIT
Definition: enums.h:111
@ 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:1369
struct SquidConfig::@113 onoff
void transientsDisconnect(StoreEntry &)
disassociates the entry from the intransit table
Definition: Controller.cc:665
Decision decision
current decision state
Definition: MemObject.h:156
struct SquidConfig::@111 Store
StoreEntry * find(const cache_key *)
Definition: Controller.cc:356
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:77
void memOutDecision(const bool willCacheInRam)
Definition: store.cc:1839
struct timeval store_complete_stop
void OBJH(StoreEntry *)
Definition: forward.h:44
#define NULL
Definition: types.h:166
RemovalPolicySettings * memPolicy
Definition: SquidConfig.h:97
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:1920
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
SBuf vary_headers
Definition: MemObject.h:204
@ IN_MEMORY
Definition: enums.h:36
@ ENTRY_VALIDATED
Definition: enums.h:113
const HttpReply & baseReply() const
Definition: MemObject.h:59
void abort()
Definition: store.cc:1103
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:161
bool hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
whether at least one of the request ETags matches entity ETag
Definition: store.cc:1931
void stopSharing(StoreEntry &)
stop any current (and prevent any future) SMP sharing of the given entry
Definition: Controller.cc:637
int max_open_disk_fds
Definition: SquidConfig.h:460
@ ENTRY_REVALIDATE_ALWAYS
Definition: enums.h:85
tlv * storeSwapMetaBuild(const StoreEntry *e)
uint16_t refcount
Definition: Store.h:223
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition: store.cc:1969
sdirno swap_dirn
Definition: Store.h:230
@ STORE_DISK_CLIENT
Definition: enums.h:74
#define INT_MAX
Definition: types.h:76
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
void setCollapsingRequirement(const bool required)
allow or forbid collapsed requests feeding
Definition: store.cc:2053
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:157
cache_key * storeKeyDup(const cache_key *key)
ping_status_t ping_status
Definition: Store.h:234
void write(const StoreIOBuffer &buf)
Definition: MemObject.cc:151
const char * getSerialisedMetaData(size_t &length) const
Definition: store.cc:1808
@ ioDone
Definition: forward.h:40
bool hasMemStore() const
whether there is a corresponding locked shared memory table entry
Definition: Store.h:205
void const char HLPCB void * data
Definition: stub_helper.cc:16
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:483
void expireNow()
Definition: store.cc:796
const char * storeEntryFlags(const StoreEntry *entry)
Definition: stat.cc:276
static size_t inUseCount()
Definition: store.cc:197
HttpRequestMethod method
Definition: MemObject.h:137
store_status_t store_status
Definition: Store.h:236
struct _store_check_cachable_hist::@146 no
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:91
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:1845
const char * pingStatusStr[]
Definition: store.cc:79
RemovalPolicy * createRemovalPolicy(RemovalPolicySettings *settings)
Definition: store.cc:1706
int checkNegativeHit() const
Definition: store.cc:1331
virtual void stat(StoreEntry &) const override
Definition: Controller.cc:141
bool swapoutFailed() const
whether we failed to write this entry to disk
Definition: Store.h:128
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
@ STORE_LOG_RELEASE
Definition: enums.h:159
@ PING_NONE
Has not considered whether to send ICP queries to peers yet.
Definition: enums.h:41
void write(StoreIOBuffer)
Definition: store.cc:803
bool checkCachable()
Definition: store.cc:955
void(* Remove)(RemovalPolicy *policy, StoreEntry *entry, RemovalPolicyNode *node)
Definition: RemovalPolicy.h:47
hash_table * store_table
bool cacheNegatively()
Definition: store.cc:186
mem_status_t mem_status
Definition: Store.h:232
AsyncCall::Pointer deferredProducer
producer callback registered with deferProducer
Definition: Store.h:324
void unlockAndReset(const char *resetContext=nullptr)
Definition: Store.h:369
void dump(int debug_lvl) const
Definition: store.cc:1534
@ STORE_OK
Definition: enums.h:50
RefCount< HttpReply > HttpReplyPointer
Definition: forward.h:46
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:672
static MemAllocator * pool
Definition: Store.h:311
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:782
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:44
void storeDirSwapLog(const StoreEntry *e, int op)
Definition: Disks.cc:836
void storeConfigure(void)
Definition: store.cc:1304
@ scNotModified
Definition: StatusCode.h:40
void EVH(void *)
Definition: event.h:19
char * buf
Definition: CommRead.h:26
void setMemStatus(mem_status_t)
Definition: store.cc:1559
ETag getETag(Http::HdrType id) const
Definition: HttpHeader.cc:1365
swap_status_t swap_status
Definition: Store.h:238
@ ksDefault
Definition: store_key_md5.h:19
void negativeCache()
Definition: store.cc:1352
#define fd_table
Definition: fde.h:189
void complete()
Definition: store.cc:1057
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:241
HttpRequestMethod method
Definition: HttpRequest.h:114
void storeKeyFree(const cache_key *key)
KeyScope
Definition: store_key_md5.h:18
@ ENTRY_ABORTED
Definition: enums.h:115
struct timeval current_time
Definition: stub_time.cc:15
@ ENTRY_REQUIRES_COLLAPSING
Definition: enums.h:118
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
void swapOutFileClose(int how)
void delayRead(DeferredRead const &)
Definition: MemObject.cc:457
const cache_key * calcPublicKey(const KeyScope keyScope)
Definition: store.cc:675
bool timestampsSet()
Definition: store.cc:1428
void storeSwapTLVFree(tlv *n)
@ scNoContent
Definition: StatusCode.h:30
void storeAppendVPrintf(StoreEntry *e, const char *fmt, va_list vargs)
Definition: store.cc:890
int storeTooManyDiskFilesOpen(void)
Definition: store.cc:915
const char * storeStatusStr[]
Definition: store.cc:85
virtual void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: Controller.cc:93
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:71
@ ioUndecided
Definition: forward.h:40
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1068
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:386
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:105
void handleIdleEntry(StoreEntry &)
called when the entry is no longer needed by any transaction
Definition: Controller.cc:679
int fdNFree(void)
Definition: fd.cc:295
int RESERVED_FD
int expiresMoreThan(time_t expires, time_t when)
Definition: store.cc:1379
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:72
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:38
uint64_t swap_file_sz
Definition: Store.h:222
void IPH * handler
Definition: stub_ipcache.cc:16
void const char HLPCB * callback
Definition: stub_helper.cc:16
const char * storeKeyText(const cache_key *key)
CacheDigest * store_digest
virtual void vappendf(const char *, va_list)
Definition: store.cc:846
bool hasTransients() const
whether there is a corresponding locked transients table entry
Definition: Store.h:203
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
Comm::ConnectionPointer conn
Definition: CommRead.h:25
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:521
void release(const bool shareable=false)
Definition: store.cc:1175
static void StatQueue(std::ostream &)
prints IPC message queue state; suitable for cache manager reports
Definition: IpcIoFile.cc:535
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:1960
const HttpReply & freshestReply() const
Definition: MemObject.h:67
static Pointer Create(const CommandPointer &cmd)
void forcePublicKey(const cache_key *newkey)
Definition: store.cc:649
@ RELEASE_REQUEST
prohibits making the key public
Definition: enums.h:98
int shutting_down
void hashInsert(const cache_key *)
Definition: store.cc:438
bool memoryCachable()
checkCachable() and can be cached in memory
Definition: store.cc:1310
StoreEntry * storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod &method)
Definition: store.cc:764
bool checkTooBig() const
Definition: store.cc:944
void freeMemorySpace(const int spaceRequired)
Definition: Controller.cc:542
void attachToDisk(const sdirno, const sfileno, const swap_status_t)
Definition: store.cc:1980
virtual void append(char const *, int)
Appends a c-string to existing packed data.
Definition: store.cc:828
struct _store_check_cachable_hist::@147 yes
void trimMemory(const bool preserveSwappable)
Definition: store.cc:1854
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
bool hittingRequiresCollapsing() const
whether this entry can feed collapsed requests and only them
Definition: Store.h:208
int locked() const
Definition: Store.h:136
static EVH storeLateRelease
Definition: store.cc:115
#define SWALLOW_EXCEPTIONS(code)
Definition: TextException.h:76
RemovalPolicy * REMOVALPOLICYCREATE(wordlist *args)
Definition: RemovalPolicy.h:80
@ 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:1049
void registerAbortCallback(const AsyncCall::Pointer &)
notify the StoreEntry writer of a 3rd-party initiated StoreEntry abort
Definition: store.cc:1516
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:124
@ METHOD_GET
Definition: MethodType.h:25
bool swappedOut() const
whether the entire entry is now on disk (possibly marked for deletion)
Definition: Store.h:126
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:1876
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
Definition: hash.cc:147
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition: MemObject.h:84
void reset()
Definition: MemObject.cc:285
#define false
Definition: GnuRegex.c:233
unsigned short lock_count
Definition: Store.h:313
void * xrealloc(void *s, size_t sz)
Definition: xalloc.cc:137
static int getKeyCounter(void)
Definition: store.cc:545
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1913
@ 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:1902
const char * context_
default unlock() message
Definition: Store.h:380
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:2041
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:77
time_t lastref
Definition: Store.h:217
int nclients
Definition: MemObject.h:146
const char * getMD5Text() const
Definition: store.cc:205
void const char * buf
Definition: stub_helper.cc:16
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:109
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1744
time_t negativeTtl
Definition: SquidConfig.h:99
void storeDigestInit(void)
#define PROF_start(probename)
Definition: Profiler.h:62
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:170
@ 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:228
Pointer recreateOnNotModified(const HttpReply &reply304) const
Definition: HttpReply.cc:263
Controller & Root()
safely access controller singleton
Definition: Controller.cc:938

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors