store.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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/TextException.h"
13 #include "CacheDigest.h"
14 #include "CacheManager.h"
15 #include "comm/Connection.h"
16 #include "comm/Read.h"
17 #include "ETag.h"
18 #include "event.h"
19 #include "fde.h"
20 #include "globals.h"
21 #include "http.h"
22 #include "HttpReply.h"
23 #include "HttpRequest.h"
24 #include "mem_node.h"
25 #include "MemObject.h"
26 #include "MemStore.h"
27 #include "mgr/Registration.h"
28 #include "mgr/StoreIoAction.h"
29 #include "profiler/Profiler.h"
30 #include "repl_modules.h"
31 #include "RequestFlags.h"
32 #include "SquidConfig.h"
33 #include "SquidTime.h"
34 #include "StatCounters.h"
35 #include "stmem.h"
36 #include "Store.h"
37 #include "store/Controller.h"
38 #include "store/Disk.h"
39 #include "store/Disks.h"
40 #include "store_digest.h"
41 #include "store_key_md5.h"
42 #include "store_log.h"
43 #include "store_rebuild.h"
44 #include "StoreClient.h"
45 #include "StoreIOState.h"
46 #include "StoreMeta.h"
47 #include "StrList.h"
48 #include "swap_log_op.h"
49 #include "tools.h"
50 #if USE_DELAY_POOLS
51 #include "DelayPools.h"
52 #endif
53 
57 #include "mem/Pool.h"
58 
59 #include <climits>
60 #include <stack>
61 
62 #define REBUILD_TIMESTAMP_DELTA_MAX 2
63 
64 #define STORE_IN_MEM_BUCKETS (229)
65 
68 const char *memStatusStr[] = {
69  "NOT_IN_MEMORY",
70  "IN_MEMORY"
71 };
72 
73 const char *pingStatusStr[] = {
74  "PING_NONE",
75  "PING_WAITING",
76  "PING_DONE"
77 };
78 
79 const char *storeStatusStr[] = {
80  "STORE_OK",
81  "STORE_PENDING"
82 };
83 
84 const char *swapStatusStr[] = {
85  "SWAPOUT_NONE",
86  "SWAPOUT_WRITING",
87  "SWAPOUT_DONE",
88  "SWAPOUT_FAILED"
89 };
90 
91 /*
92  * This defines an repl type
93  */
94 
96 
98  const char *typestr;
100 };
101 
102 static storerepl_entry_t *storerepl_list = NULL;
103 
104 /*
105  * local function prototypes
106  */
107 static int getKeyCounter(void);
110 
111 /*
112  * local variables
113  */
114 static std::stack<StoreEntry*> LateReleaseStack;
115 MemAllocator *StoreEntry::pool = NULL;
116 
117 void
119 {
120  assert(output);
121  Root().stat(*output);
122 }
123 
124 // XXX: new/delete operators need to be replaced with MEMPROXY_CLASS
125 // definitions but doing so exposes bug 4370, and maybe 4354 and 4355
126 void *
127 StoreEntry::operator new (size_t bytecount)
128 {
129  assert(bytecount == sizeof (StoreEntry));
130 
131  if (!pool) {
132  pool = memPoolCreate ("StoreEntry", bytecount);
133  }
134 
135  return pool->alloc();
136 }
137 
138 void
139 StoreEntry::operator delete (void *address)
140 {
141  pool->freeOne(address);
142 }
143 
144 bool
146 {
147  /* This object can be cached for a long time */
148  return !EBIT_TEST(flags, RELEASE_REQUEST) && setPublicKey(scope);
149 }
150 
151 void
152 StoreEntry::makePrivate(const bool shareable)
153 {
154  releaseRequest(shareable); /* delete object when not used */
155 }
156 
157 void
159 {
160  assert(!EBIT_TEST(flags, RELEASE_REQUEST));
161  EBIT_CLR(flags, KEY_PRIVATE);
162  shareableWhenPrivate = false;
163 }
164 
165 bool
167 {
168  /* This object may be negatively cached */
169  if (makePublic()) {
170  negativeCache();
171  return true;
172  }
173  return false;
174 }
175 
176 size_t
178 {
179  if (!pool)
180  return 0;
181  return pool->getInUseCount();
182 }
183 
184 const char *
186 {
187  return storeKeyText((const cache_key *)key);
188 }
189 
190 #include "comm.h"
191 
192 void
193 StoreEntry::DeferReader(void *theContext, CommRead const &aRead)
194 {
195  StoreEntry *anEntry = (StoreEntry *)theContext;
196  anEntry->delayAwareRead(aRead.conn,
197  aRead.buf,
198  aRead.len,
199  aRead.callback);
200 }
201 
202 void
204 {
205  size_t amountToRead = bytesWanted(Range<size_t>(0, len));
206  /* sketch: readdeferer* = getdeferer.
207  * ->deferRead (fd, buf, len, callback, DelayAwareRead, this)
208  */
209 
210  if (amountToRead <= 0) {
211  assert (mem_obj);
212  mem_obj->delayRead(DeferredRead(DeferReader, this, CommRead(conn, buf, len, callback)));
213  return;
214  }
215 
216  if (fd_table[conn->fd].closing()) {
217  // Readers must have closing callbacks if they want to be notified. No
218  // readers appeared to care around 2009/12/14 as they skipped reading
219  // for other reasons. Closing may already be true at the delyaAwareRead
220  // call time or may happen while we wait after delayRead() above.
221  debugs(20, 3, "will not read from closing " << conn << " for " << callback);
222  return; // the read callback will never be called
223  }
224 
225  comm_read(conn, buf, amountToRead, callback);
226 }
227 
228 size_t
229 StoreEntry::bytesWanted (Range<size_t> const aRange, bool ignoreDelayPools) const
230 {
231  if (mem_obj == NULL)
232  return aRange.end;
233 
234 #if URL_CHECKSUM_DEBUG
235 
236  mem_obj->checkUrlChecksum();
237 
238 #endif
239 
240  if (!mem_obj->readAheadPolicyCanRead())
241  return 0;
242 
243  return mem_obj->mostBytesWanted(aRange.end, ignoreDelayPools);
244 }
245 
246 bool
248 {
249  return (bytesWanted(Range<size_t>(0,INT_MAX)) == 0);
250 }
251 
252 void
253 StoreEntry::setNoDelay(bool const newValue)
254 {
255  if (mem_obj)
256  mem_obj->setNoDelay(newValue);
257 }
258 
259 // XXX: Type names mislead. STORE_DISK_CLIENT actually means that we should
260 // open swapin file, aggressively trim memory, and ignore read-ahead gap.
261 // It does not mean we will read from disk exclusively (or at all!).
262 // STORE_MEM_CLIENT covers all other cases, including in-memory entries,
263 // newly created entries, and entries not backed by disk or memory cache.
264 // XXX: May create STORE_DISK_CLIENT with no disk caching configured.
265 // XXX: Collapsed clients cannot predict their type.
268 {
269  /* The needed offset isn't in memory
270  * XXX TODO: this is wrong for range requests
271  * as the needed offset may *not* be 0, AND
272  * offset 0 in the memory object is the HTTP headers.
273  */
274 
275  assert(mem_obj);
276 
277  if (mem_obj->inmem_lo)
278  return STORE_DISK_CLIENT;
279 
280  if (EBIT_TEST(flags, ENTRY_ABORTED)) {
281  /* I don't think we should be adding clients to aborted entries */
282  debugs(20, DBG_IMPORTANT, "storeClientType: adding to ENTRY_ABORTED entry");
283  return STORE_MEM_CLIENT;
284  }
285 
286  if (swapoutFailed())
287  return STORE_MEM_CLIENT;
288 
289  if (store_status == STORE_OK) {
290  /* the object has completed. */
291 
292  if (mem_obj->inmem_lo == 0 && !isEmpty()) {
293  if (swappedOut()) {
294  debugs(20,7, HERE << mem_obj << " lo: " << mem_obj->inmem_lo << " hi: " << mem_obj->endOffset() << " size: " << mem_obj->object_sz);
295  if (mem_obj->endOffset() == mem_obj->object_sz) {
296  /* hot object fully swapped in (XXX: or swapped out?) */
297  return STORE_MEM_CLIENT;
298  }
299  } else {
300  /* Memory-only, or currently being swapped out */
301  return STORE_MEM_CLIENT;
302  }
303  }
304  return STORE_DISK_CLIENT;
305  }
306 
307  /* here and past, entry is STORE_PENDING */
308  /*
309  * If this is the first client, let it be the mem client
310  */
311  if (mem_obj->nclients == 1)
312  return STORE_MEM_CLIENT;
313 
314  /*
315  * If there is no disk file to open yet, we must make this a
316  * mem client. If we can't open the swapin file before writing
317  * to the client, there is no guarantee that we will be able
318  * to open it later when we really need it.
319  */
320  if (swap_status == SWAPOUT_NONE)
321  return STORE_MEM_CLIENT;
322 
323  /*
324  * otherwise, make subsequent clients read from disk so they
325  * can not delay the first, and vice-versa.
326  */
327  return STORE_DISK_CLIENT;
328 }
329 
331  mem_obj(NULL),
332  timestamp(-1),
333  lastref(-1),
334  expires(-1),
335  lastModified_(-1),
336  swap_file_sz(0),
337  refcount(0),
338  flags(0),
339  swap_filen(-1),
340  swap_dirn(-1),
341  mem_status(NOT_IN_MEMORY),
342  ping_status(PING_NONE),
343  store_status(STORE_PENDING),
344  swap_status(SWAPOUT_NONE),
345  lock_count(0),
346  shareableWhenPrivate(false)
347 {
348  debugs(20, 5, "StoreEntry constructed, this=" << this);
349 }
350 
352 {
353  debugs(20, 5, "StoreEntry destructed, this=" << this);
354 }
355 
356 #if USE_ADAPTATION
357 void
359 {
360  if (!deferredProducer)
361  deferredProducer = producer;
362  else
363  debugs(20, 5, "Deferred producer call is already set to: " <<
364  *deferredProducer << ", requested call: " << *producer);
365 }
366 
367 void
369 {
370  if (deferredProducer != NULL) {
373  }
374 }
375 #endif
376 
377 void
379 {
380  debugs(20, 3, mem_obj << " in " << *this);
381 
382  // Store::Root() is FATALly missing during shutdown
383  if (hasTransients() && !shutting_down)
385  if (hasMemStore() && !shutting_down)
386  Store::Root().memoryDisconnect(*this);
387 
388  if (MemObject *mem = mem_obj) {
390  mem_obj = NULL;
391  delete mem;
392  }
393 }
394 
395 void
397 {
398  debugs(20, 3, HERE << "destroyStoreEntry: destroying " << data);
399  StoreEntry *e = static_cast<StoreEntry *>(static_cast<hash_link *>(data));
400  assert(e != NULL);
401 
402  // Store::Root() is FATALly missing during shutdown
403  if (e->hasDisk() && !shutting_down)
404  e->disk().disconnect(*e);
405 
406  e->destroyMemObject();
407 
408  e->hashDelete();
409 
410  assert(e->key == NULL);
411 
412  delete e;
413 }
414 
415 /* ----- INTERFACE BETWEEN STORAGE MANAGER AND HASH TABLE FUNCTIONS --------- */
416 
417 void
419 {
420  debugs(20, 3, "StoreEntry::hashInsert: Inserting Entry " << *this << " key '" << storeKeyText(someKey) << "'");
421  assert(!key);
422  key = storeKeyDup(someKey);
423  hash_join(store_table, this);
424 }
425 
426 void
428 {
429  if (key) { // some test cases do not create keys and do not hashInsert()
431  storeKeyFree((const cache_key *)key);
432  key = NULL;
433  }
434 }
435 
436 /* -------------------------------------------------------------------------- */
437 
438 void
439 StoreEntry::lock(const char *context)
440 {
441  ++lock_count;
442  debugs(20, 3, context << " locked key " << getMD5Text() << ' ' << *this);
443 }
444 
445 void
447 {
449 }
450 
451 void
452 StoreEntry::releaseRequest(const bool shareable)
453 {
454  debugs(20, 3, shareable << ' ' << *this);
455  if (!shareable)
456  shareableWhenPrivate = false; // may already be false
458  return;
459  setPrivateKey(shareable, true);
460 }
461 
462 int
463 StoreEntry::unlock(const char *context)
464 {
465  debugs(20, 3, (context ? context : "somebody") <<
466  " unlocking key " << getMD5Text() << ' ' << *this);
467  assert(lock_count > 0);
468  --lock_count;
469 
470  if (lock_count)
471  return (int) lock_count;
472 
473  abandon(context);
474  return 0;
475 }
476 
479 void
480 StoreEntry::doAbandon(const char *context)
481 {
482  debugs(20, 5, *this << " via " << (context ? context : "somebody"));
483  assert(!locked());
484  assert(storePendingNClients(this) == 0);
485 
486  // Both aborted local writers and aborted local readers (of remote writers)
487  // are STORE_PENDING, but aborted readers should never release().
489  (store_status == STORE_PENDING && !Store::Root().transientsReader(*this))) {
490  this->release();
491  return;
492  }
493 
495  debugs(20, DBG_IMPORTANT, "WARNING: " << __FILE__ << ":" << __LINE__ << ": found KEY_PRIVATE");
496 
497  Store::Root().handleIdleEntry(*this); // may delete us
498 }
499 
500 void
502 {
503  assert (aClient);
504  aClient->created(storeGetPublicByRequestMethod(request, method));
505 }
506 
507 void
509 {
510  assert (aClient);
511  aClient->created(storeGetPublicByRequest(request));
512 }
513 
514 void
515 StoreEntry::getPublic (StoreClient *aClient, const char *uri, const HttpRequestMethod& method)
516 {
517  assert (aClient);
518  aClient->created(storeGetPublic(uri, method));
519 }
520 
521 StoreEntry *
522 storeGetPublic(const char *uri, const HttpRequestMethod& method)
523 {
524  return Store::Root().find(storeKeyPublic(uri, method));
525 }
526 
527 StoreEntry *
529 {
530  return Store::Root().find(storeKeyPublicByRequestMethod(req, method, keyScope));
531 }
532 
533 StoreEntry *
535 {
536  StoreEntry *e = storeGetPublicByRequestMethod(req, req->method, keyScope);
537 
538  if (e == NULL && req->method == Http::METHOD_HEAD)
539  /* We can generate a HEAD reply from a cached GET object */
541 
542  return e;
543 }
544 
545 static int
547 {
548  static int key_counter = 0;
549 
550  if (++key_counter < 0)
551  key_counter = 1;
552 
553  return key_counter;
554 }
555 
556 /* RBC 20050104 AFAICT this should become simpler:
557  * rather than reinserting with a special key it should be marked
558  * as 'released' and then cleaned up when refcounting indicates.
559  * the StoreHashIndex could well implement its 'released' in the
560  * current manner.
561  * Also, clean log writing should skip over ia,t
562  * Otherwise, we need a 'remove from the index but not the store
563  * concept'.
564  */
565 void
566 StoreEntry::setPrivateKey(const bool shareable, const bool permanent)
567 {
568  debugs(20, 3, shareable << permanent << ' ' << *this);
569  if (permanent)
570  EBIT_SET(flags, RELEASE_REQUEST); // may already be set
571  if (!shareable)
572  shareableWhenPrivate = false; // may already be false
573 
575  return;
576 
577  if (key) {
578  Store::Root().evictCached(*this); // all caches/workers will know
579  hashDelete();
580  }
581 
582  if (mem_obj && mem_obj->hasUris())
583  mem_obj->id = getKeyCounter();
584  const cache_key *newkey = storeKeyPrivate();
585 
586  assert(hash_lookup(store_table, newkey) == NULL);
588  shareableWhenPrivate = shareable;
589  hashInsert(newkey);
590 }
591 
592 bool
594 {
595  debugs(20, 3, *this);
596  if (key && !EBIT_TEST(flags, KEY_PRIVATE))
597  return true; // already public
598 
599  assert(mem_obj);
600 
601  /*
602  * We can't make RELEASE_REQUEST objects public. Depending on
603  * when RELEASE_REQUEST gets set, we might not be swapping out
604  * the object. If we're not swapping out, then subsequent
605  * store clients won't be able to access object data which has
606  * been freed from memory.
607  *
608  * If RELEASE_REQUEST is set, setPublicKey() should not be called.
609  */
610 #if MORE_DEBUG_OUTPUT
611 
613  debugs(20, DBG_IMPORTANT, "assertion failed: RELEASE key " << key << ", url " << mem_obj->url);
614 
615 #endif
616 
618 
619  try {
620  EntryGuard newVaryMarker(adjustVary(), "setPublicKey+failure");
621  const cache_key *pubKey = calcPublicKey(scope);
622  Store::Root().addWriting(this, pubKey);
623  forcePublicKey(pubKey);
624  newVaryMarker.unlockAndReset("setPublicKey+success");
625  return true;
626  } catch (const std::exception &ex) {
627  debugs(20, 2, "for " << *this << " failed: " << ex.what());
628  }
629  return false;
630 }
631 
632 void
634 {
635  if (!key || EBIT_TEST(flags, KEY_PRIVATE))
636  return; // probably the old public key was deleted or made private
637 
638  // TODO: adjustVary() when collapsed revalidation supports that
639 
640  const cache_key *newKey = calcPublicKey(ksDefault);
641  if (!storeKeyHashCmp(key, newKey))
642  return; // probably another collapsed revalidation beat us to this change
643 
644  forcePublicKey(newKey);
645 }
646 
649 void
651 {
652  debugs(20, 3, storeKeyText(newkey) << " for " << *this);
653  assert(mem_obj);
654 
655  if (StoreEntry *e2 = (StoreEntry *)hash_lookup(store_table, newkey)) {
656  assert(e2 != this);
657  debugs(20, 3, "releasing clashing " << *e2);
658  e2->release(true);
659  }
660 
661  if (key)
662  hashDelete();
663 
664  clearPrivate();
665 
666  assert(mem_obj->hasUris());
667  hashInsert(newkey);
668 
669  if (hasDisk())
671 }
672 
675 const cache_key *
677 {
678  assert(mem_obj);
679  return mem_obj->request ? storeKeyPublicByRequest(mem_obj->request.getRaw(), keyScope) :
680  storeKeyPublic(mem_obj->storeId(), mem_obj->method, keyScope);
681 }
682 
688 StoreEntry *
690 {
691  assert(mem_obj);
692 
693  if (!mem_obj->request)
694  return nullptr;
695 
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(), mem_obj->getReply().getRaw());
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 */
720  StoreEntry *pe = storeCreateEntry(mem_obj->storeId(), mem_obj->logUri(), request->flags, request->method);
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  HttpReply *rep = new HttpReply;
731  rep->setHeaders(Http::scOkay, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
733 
734  if (vary.size()) {
735  /* Again, we own this structure layout */
737  vary.clean();
738  }
739 
740 #if X_ACCELERATOR_VARY
742 
743  if (vary.size() > 0) {
744  /* Again, we own this structure layout */
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 {
784  StoreEntry *e = storeCreatePureEntry(url, logUrl, method);
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  if (const HttpReplyPointer reply = mem_obj->getReply())
812  writeBuffer.offset += reply->hdr_sz;
813 
814  debugs(20, 5, "storeWrite: writing " << writeBuffer.length << " bytes for '" << getMD5Text() << "'");
815  PROF_stop(StoreEntry_write);
816  storeGetMemSpace(writeBuffer.length);
817  mem_obj->write(writeBuffer);
818 
820  debugs(20, 3, "allow Store clients to get entry content after buffering too much for " << *this);
822  }
823 
824  invokeHandlers();
825 }
826 
827 /* Append incoming data from a primary server to an entry. */
828 void
829 StoreEntry::append(char const *buf, int len)
830 {
831  assert(mem_obj != NULL);
832  assert(len >= 0);
834 
835  StoreIOBuffer tempBuffer;
836  tempBuffer.data = (char *)buf;
837  tempBuffer.length = len;
838  /*
839  * XXX sigh, offset might be < 0 here, but it gets "corrected"
840  * later. This offset crap is such a mess.
841  */
842  tempBuffer.offset = mem_obj->endOffset() - (getReply() ? getReply()->hdr_sz : 0);
843  write(tempBuffer);
844 }
845 
846 void
847 StoreEntry::vappendf(const char *fmt, va_list vargs)
848 {
849  LOCAL_ARRAY(char, buf, 4096);
850  *buf = 0;
851  int x;
852 
853  va_list ap;
854  /* Fix of bug 753r. The value of vargs is undefined
855  * after vsnprintf() returns. Make a copy of vargs
856  * incase we loop around and call vsnprintf() again.
857  */
858  va_copy(ap,vargs);
859  errno = 0;
860  if ((x = vsnprintf(buf, sizeof(buf), fmt, ap)) < 0) {
861  fatal(xstrerr(errno));
862  return;
863  }
864  va_end(ap);
865 
866  if (x < static_cast<int>(sizeof(buf))) {
867  append(buf, x);
868  return;
869  }
870 
871  // okay, do it the slow way.
872  char *buf2 = new char[x+1];
873  int y = vsnprintf(buf2, x+1, fmt, vargs);
874  assert(y >= 0 && y == x);
875  append(buf2, y);
876  delete[] buf2;
877 }
878 
879 // deprecated. use StoreEntry::appendf() instead.
880 void
881 storeAppendPrintf(StoreEntry * e, const char *fmt,...)
882 {
883  va_list args;
884  va_start(args, fmt);
885  e->vappendf(fmt, args);
886  va_end(args);
887 }
888 
889 // deprecated. use StoreEntry::appendf() instead.
890 void
891 storeAppendVPrintf(StoreEntry * e, const char *fmt, va_list vargs)
892 {
893  e->vappendf(fmt, vargs);
894 }
895 
897 
898  struct {
899  int non_get;
903  int too_big;
909  } no;
910 
911  struct {
912  int Default;
913  } yes;
915 
916 int
918 {
919  if (Config.max_open_disk_fds == 0)
920  return 0;
921 
923  return 1;
924 
925  return 0;
926 }
927 
928 int
930 {
932  return 0;
933 
934  if (STORE_OK == store_status)
935  if (mem_obj->object_sz >= 0 &&
937  return 1;
938  if (getReply()->content_length > -1)
939  if (getReply()->content_length < Config.Store.minObjectSize)
940  return 1;
941  return 0;
942 }
943 
944 bool
946 {
948  return true;
949 
950  if (getReply()->content_length < 0)
951  return false;
952 
954 }
955 
956 // TODO: move "too many open..." checks outside -- we are called too early/late
957 bool
959 {
960  // XXX: This method is used for both memory and disk caches, but some
961  // checks are specific to disk caches. Move them to mayStartSwapOut().
962 
963  // XXX: This method may be called several times, sometimes with different
964  // outcomes, making store_check_cachable_hist counters misleading.
965 
966  // check this first to optimize handling of repeated calls for uncachables
968  debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
970  return 0; // avoid rerequesting release below
971  }
972 
973 #if CACHE_ALL_METHODS
974 
975  if (mem_obj->method != Http::METHOD_GET) {
976  debugs(20, 2, "StoreEntry::checkCachable: NO: non-GET method");
978  } else
979 #endif
981  debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
983  } else if (EBIT_TEST(flags, ENTRY_NEGCACHED)) {
984  debugs(20, 3, "StoreEntry::checkCachable: NO: negative cached");
986  return 0; /* avoid release call below */
987  } else if (!mem_obj || !getReply()) {
988  // XXX: In bug 4131, we forgetHit() without mem_obj, so we need
989  // this segfault protection, but how can we get such a HIT?
990  debugs(20, 2, "StoreEntry::checkCachable: NO: missing parts: " << *this);
992  } else if (checkTooBig()) {
993  debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
995  } else if (checkTooSmall()) {
996  debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
998  } else if (EBIT_TEST(flags, KEY_PRIVATE)) {
999  debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
1001  } else if (hasDisk()) {
1002  /*
1003  * the remaining cases are only relevant if we haven't
1004  * started swapping out the object yet.
1005  */
1006  return 1;
1007  } else if (storeTooManyDiskFilesOpen()) {
1008  debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
1010  } else if (fdNFree() < RESERVED_FD) {
1011  debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
1013  } else {
1015  return 1;
1016  }
1017 
1018  releaseRequest();
1019  return 0;
1020 }
1021 
1022 void
1024 {
1025  storeAppendPrintf(sentry, "Category\t Count\n");
1026 
1027 #if CACHE_ALL_METHODS
1028 
1029  storeAppendPrintf(sentry, "no.non_get\t%d\n",
1031 #endif
1032 
1033  storeAppendPrintf(sentry, "no.not_entry_cachable\t%d\n",
1035  storeAppendPrintf(sentry, "no.wrong_content_length\t%d\n",
1037  storeAppendPrintf(sentry, "no.negative_cached\t%d\n",
1039  storeAppendPrintf(sentry, "no.missing_parts\t%d\n",
1041  storeAppendPrintf(sentry, "no.too_big\t%d\n",
1043  storeAppendPrintf(sentry, "no.too_small\t%d\n",
1045  storeAppendPrintf(sentry, "no.private_key\t%d\n",
1047  storeAppendPrintf(sentry, "no.too_many_open_files\t%d\n",
1049  storeAppendPrintf(sentry, "no.too_many_open_fds\t%d\n",
1051  storeAppendPrintf(sentry, "yes.default\t%d\n",
1053 }
1054 
1055 void
1056 StoreEntry::lengthWentBad(const char *reason)
1057 {
1058  debugs(20, 3, "because " << reason << ": " << *this);
1060  releaseRequest();
1061 }
1062 
1063 void
1065 {
1066  debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1067 
1068  // To preserve forwarding retries, call FwdState::complete() instead.
1070 
1071  if (store_status != STORE_PENDING) {
1072  /*
1073  * if we're not STORE_PENDING, then probably we got aborted
1074  * and there should be NO clients on this entry
1075  */
1077  assert(mem_obj->nclients == 0);
1078  return;
1079  }
1080 
1081  /* This is suspect: mem obj offsets include the headers. do we adjust for that
1082  * in use of object_sz?
1083  */
1085 
1087 
1089 
1091  lengthWentBad("!validLength() in complete()");
1092 
1093 #if USE_CACHE_DIGESTS
1094  if (mem_obj->request)
1096 
1097 #endif
1098  /*
1099  * We used to call invokeHandlers, then storeSwapOut. However,
1100  * Madhukar Reddy <myreddy@persistence.com> reported that
1101  * responses without content length would sometimes get released
1102  * in client_side, thinking that the response is incomplete.
1103  */
1104  invokeHandlers();
1105 }
1106 
1107 /*
1108  * Someone wants to abort this transfer. Set the reason in the
1109  * request structure, call the callback and mark the
1110  * entry for releasing
1111  */
1112 void
1114 {
1117  assert(mem_obj != NULL);
1118  debugs(20, 6, "storeAbort: " << getMD5Text());
1119 
1120  lock("StoreEntry::abort"); /* lock while aborting */
1121  negativeCache();
1122 
1123  releaseRequest();
1124 
1126 
1127  // allow the Store clients to be told about the problem
1129 
1131 
1133 
1134  /* Notify the server side */
1135 
1136  /*
1137  * DPW 2007-05-07
1138  * Should we check abort.data for validity?
1139  */
1140  if (mem_obj->abort.callback) {
1142  debugs(20, DBG_IMPORTANT,HERE << "queueing event when abort.data is not valid");
1143  eventAdd("mem_obj->abort.callback",
1145  mem_obj->abort.data,
1146  0.0,
1147  true);
1148  unregisterAbort();
1149  }
1150 
1151  /* XXX Should we reverse these two, so that there is no
1152  * unneeded disk swapping triggered?
1153  */
1154  /* Notify the client side */
1155  invokeHandlers();
1156 
1157  // abort swap out, invalidating what was created so far (release follows)
1159 
1160  unlock("StoreEntry::abort"); /* unlock */
1161 }
1162 
1166 void
1168 {
1170  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1171  Store::Root().freeMemorySpace(size);
1173 }
1174 
1175 /* thunk through to Store::Root().maintain(). Note that this would be better still
1176  * if registered against the root store itself, but that requires more complex
1177  * update logic - bigger fish to fry first. Long term each store when
1178  * it becomes active will self register
1179  */
1180 void
1182 {
1183  Store::Root().maintain();
1184 
1185  /* Reregister a maintain event .. */
1186  eventAdd("MaintainSwapSpace", Maintain, NULL, 1.0, 1);
1187 
1188 }
1189 
1190 /* The maximum objects to scan for maintain storage space */
1191 #define MAINTAIN_MAX_SCAN 1024
1192 #define MAINTAIN_MAX_REMOVE 64
1193 
1194 void
1195 StoreEntry::release(const bool shareable)
1196 {
1197  PROF_start(storeRelease);
1198  debugs(20, 3, shareable << ' ' << *this << ' ' << getMD5Text());
1199  /* If, for any reason we can't discard this object because of an
1200  * outstanding request, mark it for pending release */
1201 
1202  if (locked()) {
1203  releaseRequest(shareable);
1204  PROF_stop(storeRelease);
1205  return;
1206  }
1207 
1209  /* TODO: Teach disk stores to handle releases during rebuild instead. */
1210 
1211  // lock the entry until rebuilding is done
1212  lock("storeLateRelease");
1213  releaseRequest(shareable);
1214  LateReleaseStack.push(this);
1215  PROF_stop(storeRelease);
1216  return;
1217  }
1218 
1219  storeLog(STORE_LOG_RELEASE, this);
1220  Store::Root().evictCached(*this);
1221  destroyStoreEntry(static_cast<hash_link *>(this));
1222  PROF_stop(storeRelease);
1223 }
1224 
1225 static void
1227 {
1228  StoreEntry *e;
1229  static int n = 0;
1230 
1232  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1233  return;
1234  }
1235 
1236  // TODO: this works but looks unelegant.
1237  for (int i = 0; i < 10; ++i) {
1238  if (LateReleaseStack.empty()) {
1239  debugs(20, DBG_IMPORTANT, "storeLateRelease: released " << n << " objects");
1240  return;
1241  } else {
1242  e = LateReleaseStack.top();
1243  LateReleaseStack.pop();
1244  }
1245 
1246  e->unlock("storeLateRelease");
1247  ++n;
1248  }
1249 
1250  eventAdd("storeLateRelease", storeLateRelease, NULL, 0.0, 1);
1251 }
1252 
1253 /* return 1 if a store entry is locked */
1254 int
1256 {
1257  if (lock_count)
1258  return 1;
1259 
1260  /*
1261  * SPECIAL, PUBLIC entries should be "locked";
1262  * XXX: Their owner should lock them then instead of relying on this hack.
1263  */
1265  if (!EBIT_TEST(flags, KEY_PRIVATE))
1266  return 1;
1267 
1268  return 0;
1269 }
1270 
1271 bool
1273 {
1274  int64_t diff;
1275  const HttpReply *reply;
1276  assert(mem_obj != NULL);
1277  reply = getReply();
1278  debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1279  debugs(20, 5, "storeEntryValidLength: object_len = " <<
1280  objectLen());
1281  debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply->hdr_sz);
1282  debugs(20, 5, "storeEntryValidLength: content_length = " << reply->content_length);
1283 
1284  if (reply->content_length < 0) {
1285  debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1286  return 1;
1287  }
1288 
1289  if (reply->hdr_sz == 0) {
1290  debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1291  return 1;
1292  }
1293 
1294  if (mem_obj->method == Http::METHOD_HEAD) {
1295  debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1296  return 1;
1297  }
1298 
1299  if (reply->sline.status() == Http::scNotModified)
1300  return 1;
1301 
1302  if (reply->sline.status() == Http::scNoContent)
1303  return 1;
1304 
1305  diff = reply->hdr_sz + reply->content_length - objectLen();
1306 
1307  if (diff == 0)
1308  return 1;
1309 
1310  debugs(20, 3, "storeEntryValidLength: " << (diff < 0 ? -diff : diff) << " bytes too " << (diff < 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1311 
1312  return 0;
1313 }
1314 
1315 static void
1317 {
1318  Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats, 0, 1);
1319  Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create, 0, 1);
1320  Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1321  storeCheckCachableStats, 0, 1);
1322 }
1323 
1324 void
1326 {
1327  storeKeyInit();
1329  storeDigestInit();
1330  storeLogOpen();
1331  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1332  Store::Root().init();
1334 
1336 }
1337 
1338 void
1340 {
1342 }
1343 
1344 bool
1346 {
1347  if (!checkCachable())
1348  return 0;
1349 
1350  if (mem_obj == NULL)
1351  return 0;
1352 
1353  if (mem_obj->data_hdr.size() == 0)
1354  return 0;
1355 
1356  if (mem_obj->inmem_lo != 0)
1357  return 0;
1358 
1360  return 0;
1361 
1362  return 1;
1363 }
1364 
1365 int
1367 {
1369  return 0;
1370 
1371  if (expires <= squid_curtime)
1372  return 0;
1373 
1374  if (store_status != STORE_OK)
1375  return 0;
1376 
1377  return 1;
1378 }
1379 
1386 void
1388 {
1389  // XXX: should make the default for expires 0 instead of -1
1390  // so we can distinguish "Expires: -1" from nothing.
1391  if (expires <= 0)
1392 #if USE_HTTP_VIOLATIONS
1394 #else
1396 #endif
1398 }
1399 
1400 void
1402 {
1404 #if USE_CACHE_DIGESTS
1405  delete store_digest;
1406 #endif
1407  store_digest = NULL;
1408 }
1409 
1410 int
1411 expiresMoreThan(time_t expires, time_t when)
1412 {
1413  if (expires < 0) /* No Expires given */
1414  return 1;
1415 
1416  return (expires > (squid_curtime + when));
1417 }
1418 
1419 int
1421 {
1423  return 0;
1424 
1426  if (expires <= squid_curtime)
1427  return 0;
1428 
1430  return 0;
1431 
1432  // now check that the entry has a cache backing or is collapsed
1433  if (hasDisk()) // backed by a disk cache
1434  return 1;
1435 
1436  if (swappingOut()) // will be backed by a disk cache
1437  return 1;
1438 
1439  if (!mem_obj) // not backed by a memory cache and not collapsed
1440  return 0;
1441 
1442  // StoreEntry::storeClientType() assumes DISK_CLIENT here, but there is no
1443  // disk cache backing that store_client constructor will assert. XXX: This
1444  // is wrong for range requests (that could feed off nibbled memory) and for
1445  // entries backed by the shared memory cache (that could, in theory, get
1446  // nibbled bytes from that cache, but there is no such "memoryIn" code).
1447  if (mem_obj->inmem_lo) // in memory cache, but got nibbled at
1448  return 0;
1449 
1450  // The following check is correct but useless at this position. TODO: Move
1451  // it up when the shared memory cache can either replenish locally nibbled
1452  // bytes or, better, does not use local RAM copy at all.
1453  // if (mem_obj->memCache.index >= 0) // backed by a shared memory cache
1454  // return 1;
1455 
1456  return 1;
1457 }
1458 
1459 bool
1461 {
1462  const HttpReply *reply = getReply();
1463  time_t served_date = reply->date;
1464  int age = reply->header.getInt(Http::HdrType::AGE);
1465  /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1466  /* make sure that 0 <= served_date <= squid_curtime */
1467 
1468  if (served_date < 0 || served_date > squid_curtime)
1469  served_date = squid_curtime;
1470 
1471  /* Bug 1791:
1472  * If the returned Date: is more than 24 hours older than
1473  * the squid_curtime, then one of us needs to use NTP to set our
1474  * clock. We'll pretend that our clock is right.
1475  */
1476  else if (served_date < (squid_curtime - 24 * 60 * 60) )
1477  served_date = squid_curtime;
1478 
1479  /*
1480  * Compensate with Age header if origin server clock is ahead
1481  * of us and there is a cache in between us and the origin
1482  * server. But DONT compensate if the age value is larger than
1483  * squid_curtime because it results in a negative served_date.
1484  */
1485  if (age > squid_curtime - served_date)
1486  if (squid_curtime > age)
1487  served_date = squid_curtime - age;
1488 
1489  // compensate for Squid-to-server and server-to-Squid delays
1490  if (mem_obj && mem_obj->request) {
1491  struct timeval responseTime;
1492  if (mem_obj->request->hier.peerResponseTime(responseTime))
1493  served_date -= responseTime.tv_sec;
1494  }
1495 
1496  time_t exp = 0;
1497  if (reply->expires > 0 && reply->date > -1)
1498  exp = served_date + (reply->expires - reply->date);
1499  else
1500  exp = reply->expires;
1501 
1502  if (timestamp == served_date && expires == exp) {
1503  // if the reply lacks LMT, then we now know that our effective
1504  // LMT (i.e., timestamp) will stay the same, otherwise, old and
1505  // new modification times must match
1506  if (reply->last_modified < 0 || reply->last_modified == lastModified())
1507  return false; // nothing has changed
1508  }
1509 
1510  expires = exp;
1511 
1512  lastModified_ = reply->last_modified;
1513 
1514  timestamp = served_date;
1515 
1516  return true;
1517 }
1518 
1519 void
1521 {
1522  assert(mem_obj);
1524  mem_obj->abort.callback = cb;
1525  mem_obj->abort.data = cbdataReference(data);
1526 }
1527 
1528 void
1530 {
1531  assert(mem_obj);
1532  if (mem_obj->abort.callback) {
1535  }
1536 }
1537 
1538 void
1539 StoreEntry::dump(int l) const
1540 {
1541  debugs(20, l, "StoreEntry->key: " << getMD5Text());
1542  debugs(20, l, "StoreEntry->next: " << next);
1543  debugs(20, l, "StoreEntry->mem_obj: " << mem_obj);
1544  debugs(20, l, "StoreEntry->timestamp: " << timestamp);
1545  debugs(20, l, "StoreEntry->lastref: " << lastref);
1546  debugs(20, l, "StoreEntry->expires: " << expires);
1547  debugs(20, l, "StoreEntry->lastModified_: " << lastModified_);
1548  debugs(20, l, "StoreEntry->swap_file_sz: " << swap_file_sz);
1549  debugs(20, l, "StoreEntry->refcount: " << refcount);
1550  debugs(20, l, "StoreEntry->flags: " << storeEntryFlags(this));
1551  debugs(20, l, "StoreEntry->swap_dirn: " << swap_dirn);
1552  debugs(20, l, "StoreEntry->swap_filen: " << swap_filen);
1553  debugs(20, l, "StoreEntry->lock_count: " << lock_count);
1554  debugs(20, l, "StoreEntry->mem_status: " << mem_status);
1555  debugs(20, l, "StoreEntry->ping_status: " << ping_status);
1556  debugs(20, l, "StoreEntry->store_status: " << store_status);
1557  debugs(20, l, "StoreEntry->swap_status: " << swap_status);
1558 }
1559 
1560 /*
1561  * NOTE, this function assumes only two mem states
1562  */
1563 void
1565 {
1566  if (new_status == mem_status)
1567  return;
1568 
1569  // are we using a shared memory cache?
1570  if (MemStore::Enabled()) {
1571  // This method was designed to update replacement policy, not to
1572  // actually purge something from the memory cache (TODO: rename?).
1573  // Shared memory cache does not have a policy that needs updates.
1574  mem_status = new_status;
1575  return;
1576  }
1577 
1578  assert(mem_obj != NULL);
1579 
1580  if (new_status == IN_MEMORY) {
1581  assert(mem_obj->inmem_lo == 0);
1582 
1583  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1584  debugs(20, 4, "not inserting special " << *this << " into policy");
1585  } else {
1586  mem_policy->Add(mem_policy, this, &mem_obj->repl);
1587  debugs(20, 4, "inserted " << *this << " key: " << getMD5Text());
1588  }
1589 
1590  ++hot_obj_count; // TODO: maintain for the shared hot cache as well
1591  } else {
1592  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1593  debugs(20, 4, "not removing special " << *this << " from policy");
1594  } else {
1596  debugs(20, 4, "removed " << *this);
1597  }
1598 
1599  --hot_obj_count;
1600  }
1601 
1602  mem_status = new_status;
1603 }
1604 
1605 const char *
1607 {
1608  if (mem_obj == NULL)
1609  return "[null_mem_obj]";
1610  else
1611  return mem_obj->storeId();
1612 }
1613 
1614 void
1616 {
1617  assert(!mem_obj);
1618  mem_obj = new MemObject();
1619 }
1620 
1621 void
1622 StoreEntry::createMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1623 {
1624  assert(!mem_obj);
1625  ensureMemObject(aUrl, aLogUrl, aMethod);
1626 }
1627 
1628 void
1629 StoreEntry::ensureMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1630 {
1631  if (!mem_obj)
1632  mem_obj = new MemObject();
1633  mem_obj->setUris(aUrl, aLogUrl, aMethod);
1634 }
1635 
1640 void
1642 {
1644 }
1645 
1651 void
1653 {
1654  if (EBIT_TEST(flags, DELAY_SENDING)) {
1656  invokeHandlers();
1657  }
1658 }
1659 
1660 int64_t
1662 {
1663  assert(mem_obj != NULL);
1664  return mem_obj->object_sz;
1665 }
1666 
1667 int64_t
1669 {
1670  assert(mem_obj != NULL);
1671  assert(getReply() != NULL);
1672  return objectLen() - getReply()->hdr_sz;
1673 }
1674 
1675 HttpReply const *
1677 {
1678  return (mem_obj ? mem_obj->getReply().getRaw() : nullptr);
1679 }
1680 
1681 void
1683 {
1684  assert (mem_obj);
1685  debugs(20, 3, url());
1686  mem_obj->reset();
1687  expires = lastModified_ = timestamp = -1;
1688 }
1689 
1690 /*
1691  * storeFsInit
1692  *
1693  * This routine calls the SETUP routine for each fs type.
1694  * I don't know where the best place for this is, and I'm not going to shuffle
1695  * around large chunks of code right now (that can be done once its working.)
1696  */
1697 void
1699 {
1700  storeReplSetup();
1701 }
1702 
1703 /*
1704  * called to add another store removal policy module
1705  */
1706 void
1707 storeReplAdd(const char *type, REMOVALPOLICYCREATE * create)
1708 {
1709  int i;
1710 
1711  /* find the number of currently known repl types */
1712  for (i = 0; storerepl_list && storerepl_list[i].typestr; ++i) {
1713  if (strcmp(storerepl_list[i].typestr, type) == 0) {
1714  debugs(20, DBG_IMPORTANT, "WARNING: Trying to load store replacement policy " << type << " twice.");
1715  return;
1716  }
1717  }
1718 
1719  /* add the new type */
1720  storerepl_list = static_cast<storerepl_entry_t *>(xrealloc(storerepl_list, (i + 2) * sizeof(storerepl_entry_t)));
1721 
1722  memset(&storerepl_list[i + 1], 0, sizeof(storerepl_entry_t));
1723 
1724  storerepl_list[i].typestr = type;
1725 
1726  storerepl_list[i].create = create;
1727 }
1728 
1729 /*
1730  * Create a removal policy instance
1731  */
1732 RemovalPolicy *
1734 {
1735  storerepl_entry_t *r;
1736 
1737  for (r = storerepl_list; r && r->typestr; ++r) {
1738  if (strcmp(r->typestr, settings->type) == 0)
1739  return r->create(settings->args);
1740  }
1741 
1742  debugs(20, DBG_IMPORTANT, "ERROR: Unknown policy " << settings->type);
1743  debugs(20, DBG_IMPORTANT, "ERROR: Be sure to have set cache_replacement_policy");
1744  debugs(20, DBG_IMPORTANT, "ERROR: and memory_replacement_policy in squid.conf!");
1745  fatalf("ERROR: Unknown policy %s\n", settings->type);
1746  return NULL; /* NOTREACHED */
1747 }
1748 
1749 #if 0
1750 void
1752 {
1753  if (e->swap_file_number == filn)
1754  return;
1755 
1756  if (filn < 0) {
1757  assert(-1 == filn);
1758  storeDirMapBitReset(e->swap_file_number);
1759  storeDirLRUDelete(e);
1760  e->swap_file_number = -1;
1761  } else {
1762  assert(-1 == e->swap_file_number);
1763  storeDirMapBitSet(e->swap_file_number = filn);
1764  storeDirLRUAdd(e);
1765  }
1766 }
1767 
1768 #endif
1769 
1770 void
1772 {
1773  lock("StoreEntry::storeErrorResponse");
1774  buffer();
1775  replaceHttpReply(reply);
1776  flush();
1777  complete();
1778  negativeCache();
1779  releaseRequest(false); // if it is safe to negatively cache, sharing is OK
1780  unlock("StoreEntry::storeErrorResponse");
1781 }
1782 
1783 /*
1784  * Replace a store entry with
1785  * a new reply. This eats the reply.
1786  */
1787 void
1788 StoreEntry::replaceHttpReply(HttpReply *rep, bool andStartWriting)
1789 {
1790  debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1791 
1792  if (!mem_obj) {
1793  debugs(20, DBG_CRITICAL, "Attempt to replace object with no in-memory representation");
1794  return;
1795  }
1796 
1798 
1799  if (andStartWriting)
1800  startWriting();
1801 }
1802 
1803 void
1805 {
1806  /* TODO: when we store headers separately remove the header portion */
1807  /* TODO: mark the length of the headers ? */
1808  /* We ONLY want the headers */
1809  assert (isEmpty());
1810  assert(mem_obj);
1811 
1812  const HttpReply *rep = getReply();
1813  assert(rep);
1814 
1815  buffer();
1816  rep->packHeadersUsingSlowPacker(*this);
1818 
1819  rep->body.packInto(this);
1820  flush();
1821 
1822  // The entry headers are written, new clients
1823  // should not collapse anymore.
1824  if (hittingRequiresCollapsing()) {
1825  setCollapsingRequirement(false);
1827  }
1828 }
1829 
1830 char const *
1832 {
1833  StoreMeta *tlv_list = storeSwapMetaBuild(this);
1834  int swap_hdr_sz;
1835  char *result = storeSwapMetaPack(tlv_list, &swap_hdr_sz);
1836  storeSwapTLVFree(tlv_list);
1837  assert (swap_hdr_sz >= 0);
1838  mem_obj->swap_hdr_sz = (size_t) swap_hdr_sz;
1839  return result;
1840 }
1841 
1848 void
1850 {
1851  if (mem_obj && !Store::Root().transientsReader(*this) && // this worker is responsible
1852  hasTransients() && // other workers may be interested
1853  !hasMemStore() && // rejected by the shared memory cache
1855  debugs(20, 7, "cannot be shared: " << *this);
1856  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1857  Store::Root().stopSharing(*this);
1858  }
1859 }
1860 
1861 void
1863 {
1865 }
1866 
1867 void
1869 {
1870  // Abandon our transient entry if neither shared memory nor disk wants it.
1871  assert(mem_obj);
1872  mem_obj->swapout.decision = decision;
1874 }
1875 
1876 void
1877 StoreEntry::trimMemory(const bool preserveSwappable)
1878 {
1879  /*
1880  * DPW 2007-05-09
1881  * Bug #1943. We must not let go any data for IN_MEMORY
1882  * objects. We have to wait until the mem_status changes.
1883  */
1884  if (mem_status == IN_MEMORY)
1885  return;
1886 
1888  return; // cannot trim because we do not load them again
1889 
1890  if (preserveSwappable)
1892  else
1894 
1895  debugs(88, 7, *this << " inmem_lo=" << mem_obj->inmem_lo);
1896 }
1897 
1898 bool
1899 StoreEntry::modifiedSince(const time_t ims, const int imslen) const
1900 {
1901  int object_length;
1902  const time_t mod_time = lastModified();
1903 
1904  debugs(88, 3, "modifiedSince: '" << url() << "'");
1905 
1906  debugs(88, 3, "modifiedSince: mod_time = " << mod_time);
1907 
1908  if (mod_time < 0)
1909  return true;
1910 
1911  /* Find size of the object */
1912  object_length = getReply()->content_length;
1913 
1914  if (object_length < 0)
1915  object_length = contentLen();
1916 
1917  if (mod_time > ims) {
1918  debugs(88, 3, "--> YES: entry newer than client");
1919  return true;
1920  } else if (mod_time < ims) {
1921  debugs(88, 3, "--> NO: entry older than client");
1922  return false;
1923  } else if (imslen < 0) {
1924  debugs(88, 3, "--> NO: same LMT, no client length");
1925  return false;
1926  } else if (imslen == object_length) {
1927  debugs(88, 3, "--> NO: same LMT, same length");
1928  return false;
1929  } else {
1930  debugs(88, 3, "--> YES: same LMT, different length");
1931  return true;
1932  }
1933 }
1934 
1935 bool
1937 {
1938  if (const HttpReply *reply = getReply()) {
1939  etag = reply->header.getETag(Http::HdrType::ETAG);
1940  if (etag.str)
1941  return true;
1942  }
1943  return false;
1944 }
1945 
1946 bool
1948 {
1949  const String reqETags = request.header.getList(Http::HdrType::IF_MATCH);
1950  return hasOneOfEtags(reqETags, false);
1951 }
1952 
1953 bool
1955 {
1956  const String reqETags = request.header.getList(Http::HdrType::IF_NONE_MATCH);
1957  // weak comparison is allowed only for HEAD or full-body GET requests
1958  const bool allowWeakMatch = !request.flags.isRanged &&
1959  (request.method == Http::METHOD_GET || request.method == Http::METHOD_HEAD);
1960  return hasOneOfEtags(reqETags, allowWeakMatch);
1961 }
1962 
1964 bool
1965 StoreEntry::hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
1966 {
1967  const ETag repETag = getReply()->header.getETag(Http::HdrType::ETAG);
1968  if (!repETag.str) {
1969  static SBuf asterisk("*", 1);
1970  return strListIsMember(&reqETags, asterisk, ',');
1971  }
1972 
1973  bool matched = false;
1974  const char *pos = NULL;
1975  const char *item;
1976  int ilen;
1977  while (!matched && strListGetItem(&reqETags, ',', &item, &ilen, &pos)) {
1978  if (!strncmp(item, "*", ilen))
1979  matched = true;
1980  else {
1981  String str;
1982  str.append(item, ilen);
1983  ETag reqETag;
1984  if (etagParseInit(&reqETag, str.termedBuf())) {
1985  matched = allowWeakMatch ? etagIsWeakEqual(repETag, reqETag) :
1986  etagIsStrongEqual(repETag, reqETag);
1987  }
1988  }
1989  }
1990  return matched;
1991 }
1992 
1993 Store::Disk &
1995 {
1996  assert(hasDisk());
1998  assert(sd);
1999  return *sd;
2000 }
2001 
2002 bool
2003 StoreEntry::hasDisk(const sdirno dirn, const sfileno filen) const
2004 {
2005  checkDisk();
2006  if (dirn < 0 && filen < 0)
2007  return swap_dirn >= 0;
2008  Must(dirn >= 0);
2009  const bool matchingDisk = (swap_dirn == dirn);
2010  return filen < 0 ? matchingDisk : (matchingDisk && swap_filen == filen);
2011 }
2012 
2013 void
2014 StoreEntry::attachToDisk(const sdirno dirn, const sfileno fno, const swap_status_t status)
2015 {
2016  debugs(88, 3, "attaching entry with key " << getMD5Text() << " : " <<
2017  swapStatusStr[status] << " " << dirn << " " <<
2018  std::hex << std::setw(8) << std::setfill('0') <<
2019  std::uppercase << fno);
2020  checkDisk();
2021  swap_dirn = dirn;
2022  swap_filen = fno;
2023  swap_status = status;
2024  checkDisk();
2025 }
2026 
2027 void
2029 {
2030  swap_dirn = -1;
2031  swap_filen = -1;
2033 }
2034 
2035 void
2037 {
2038  try {
2039  if (swap_dirn < 0) {
2040  Must(swap_filen < 0);
2042  } else {
2043  Must(swap_filen >= 0);
2045  if (swapoutFailed()) {
2047  } else {
2048  Must(swappingOut() || swappedOut());
2049  }
2050  }
2051  } catch (...) {
2052  debugs(88, DBG_IMPORTANT, "ERROR: inconsistent disk entry state " <<
2053  *this << "; problem: " << CurrentException);
2054  throw;
2055  }
2056 }
2057 
2058 /*
2059  * return true if the entry is in a state where
2060  * it can accept more data (ie with write() method)
2061  */
2062 bool
2064 {
2065  if (STORE_PENDING != store_status)
2066  return false;
2067 
2069  return false;
2070 
2071  return true;
2072 }
2073 
2074 const char *
2076 {
2077  LOCAL_ARRAY(char, buf, 256);
2078  snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
2079  static_cast<int>(timestamp),
2080  static_cast<int>(lastref),
2081  static_cast<int>(lastModified_),
2082  static_cast<int>(expires));
2083  return buf;
2084 }
2085 
2086 void
2088 {
2089  if (required)
2091  else
2093 }
2094 
2095 static std::ostream &
2096 operator <<(std::ostream &os, const Store::IoStatus &io)
2097 {
2098  switch (io) {
2099  case Store::ioUndecided:
2100  os << 'u';
2101  break;
2102  case Store::ioReading:
2103  os << 'r';
2104  break;
2105  case Store::ioWriting:
2106  os << 'w';
2107  break;
2108  case Store::ioDone:
2109  os << 'o';
2110  break;
2111  }
2112  return os;
2113 }
2114 
2115 std::ostream &operator <<(std::ostream &os, const StoreEntry &e)
2116 {
2117  os << "e:";
2118 
2119  if (e.hasTransients()) {
2120  const auto &xitTable = e.mem_obj->xitTable;
2121  os << 't' << xitTable.io << xitTable.index;
2122  }
2123 
2124  if (e.hasMemStore()) {
2125  const auto &memCache = e.mem_obj->memCache;
2126  os << 'm' << memCache.io << memCache.index << '@' << memCache.offset;
2127  }
2128 
2129  // Do not use e.hasDisk() here because its checkDisk() call may calls us.
2130  if (e.swap_filen > -1 || e.swap_dirn > -1)
2131  os << 'd' << e.swap_filen << '@' << e.swap_dirn;
2132 
2133  os << '=';
2134 
2135  // print only non-default status values, using unique letters
2136  if (e.mem_status != NOT_IN_MEMORY ||
2137  e.store_status != STORE_PENDING ||
2138  e.swap_status != SWAPOUT_NONE ||
2139  e.ping_status != PING_NONE) {
2140  if (e.mem_status != NOT_IN_MEMORY) os << 'm';
2141  if (e.store_status != STORE_PENDING) os << 's';
2142  if (e.swap_status != SWAPOUT_NONE) os << 'w' << e.swap_status;
2143  if (e.ping_status != PING_NONE) os << 'p' << e.ping_status;
2144  }
2145 
2146  // print only set flags, using unique letters
2147  if (e.flags) {
2148  if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) os << 'S';
2149  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_ALWAYS)) os << 'R';
2150  if (EBIT_TEST(e.flags, DELAY_SENDING)) os << 'P';
2151  if (EBIT_TEST(e.flags, RELEASE_REQUEST)) os << 'X';
2152  if (EBIT_TEST(e.flags, REFRESH_REQUEST)) os << 'F';
2153  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_STALE)) os << 'E';
2154  if (EBIT_TEST(e.flags, KEY_PRIVATE)) {
2155  os << 'I';
2156  if (e.shareableWhenPrivate)
2157  os << 'H';
2158  }
2159  if (EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT)) os << 'W';
2160  if (EBIT_TEST(e.flags, ENTRY_NEGCACHED)) os << 'N';
2161  if (EBIT_TEST(e.flags, ENTRY_VALIDATED)) os << 'V';
2162  if (EBIT_TEST(e.flags, ENTRY_BAD_LENGTH)) os << 'L';
2163  if (EBIT_TEST(e.flags, ENTRY_ABORTED)) os << 'A';
2164  }
2165 
2166  return os << '/' << &e << '*' << e.locks();
2167 }
2168 
2169 void
2171 {
2173  entry_->releaseRequest(false);
2174  entry_->unlock(context_);
2175  });
2176 }
2177 
const char * getMD5Text() const
Definition: store.cc:185
AsyncCall::Pointer callback
Definition: CommRead.h:28
int max_open_disk_fds
Definition: SquidConfig.h:455
HierarchyLogEntry hier
Definition: HttpRequest.h:157
sdirno swap_dirn
Definition: Store.h:216
static int getKeyCounter(void)
Definition: store.cc:546
bool shareableWhenPrivate
Definition: Store.h:309
REMOVALPOLICYCREATE * create
Definition: store.cc:99
void storeReplAdd(const char *type, REMOVALPOLICYCREATE *create)
Definition: store.cc:1707
void detachFromDisk()
Definition: store.cc:2028
void replaceReply(const HttpReplyPointer &r)
Definition: MemObject.h:58
static int store_dirs_rebuilding
the number of cache_dirs being rebuilt; TODO: move to Disks::Rebuilding
Definition: Controller.h:139
hash_table * store_table
int strListGetItem(const String *str, char del, const char **item, int *ilen, const char **pos)
Definition: StrList.cc:77
#define fd_table
Definition: fde.h:157
Io io
current I/O state
Definition: MemObject.h:138
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:281
const char * pingStatusStr[]
Definition: store.cc:73
StatCounters statCounter
Definition: StatCounters.cc:12
void makePrivate(const bool shareable)
Definition: store.cc:152
#define assert(EX)
Definition: assert.h:17
RemovalPolicy * createRemovalPolicy(RemovalPolicySettings *settings)
Definition: store.cc:1733
RemovalPolicyNode repl
Definition: MemObject.h:166
Decision decision
current decision state
Definition: MemObject.h:121
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1899
void const char HLPCB * callback
Definition: stub_helper.cc:16
bool hasEtag(ETag &etag) const
whether this entry has an ETag; if yes, puts ETag value into parameter
Definition: store.cc:1936
void touch()
update last reference timestamp and related Store metadata
Definition: store.cc:446
bool hierarchical
Definition: RequestFlags.h:34
static void getPublicByRequestMethod(StoreClient *aClient, HttpRequest *request, const HttpRequestMethod &method)
Definition: store.cc:501
int neighbors_do_private_keys
bool hasTransients() const
whether there is a corresponding locked transients table entry
Definition: Store.h:189
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
struct _store_check_cachable_hist store_check_cachable_hist
const char * typestr
Definition: store.cc:98
void release(const bool shareable=false)
Definition: store.cc:1195
int unlock(const char *context)
Definition: store.cc:463
void storeAppendVPrintf(StoreEntry *e, const char *fmt, va_list vargs)
Definition: store.cc:891
time_t lastModified() const
Definition: Store.h:161
size_t swap_hdr_sz
Definition: MemObject.h:169
bool etagIsStrongEqual(const ETag &tag1, const ETag &tag2)
whether etags are strong-equal
Definition: ETag.cc:49
Definition: ETag.h:17
int getInt(Http::HdrType id) const
Definition: HttpHeader.cc:1135
SBuf vary_headers
The variant second-stage cache key. Generated from Vary header pattern for this request.
Definition: HttpRequest.h:171
int storePendingNClients(const StoreEntry *e)
int hdr_sz
Definition: Message.h:82
StoreEntry * find(const cache_key *)
Definition: Controller.cc:325
int type
Definition: errorpage.cc:152
bool timestampsSet()
Definition: store.cc:1460
Definition: SBuf.h:86
void storeDirSwapLog(const StoreEntry *e, int op)
Definition: Disks.cc:733
bool hasDisk(const sdirno dirn=-1, const sfileno filen=-1) const
Definition: store.cc:2003
int locks() const
returns a local concurrent use counter, for debugging
Definition: Store.h:250
void storeLog(int tag, const StoreEntry *e)
Definition: store_log.cc:38
virtual void append(char const *, int)
Appends a c-string to existing packed data.
Definition: store.cc:829
const char * storeId() const
Definition: MemObject.cc:54
int etagParseInit(ETag *etag, const char *str)
Definition: ETag.cc:29
unsigned char cache_key
Store key.
Definition: forward.h:29
int64_t endOffset() const
Definition: MemObject.cc:218
int64_t objectLen() const
Definition: store.cc:1661
char const * getSerialisedMetaData()
Definition: store.cc:1831
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:828
cache_key * storeKeyDup(const cache_key *key)
HttpRequestMethod method
Definition: HttpRequest.h:114
RefCount< HttpReply > HttpReplyPointer
Definition: forward.h:34
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
int i
Definition: membanger.c:49
static void storeRegisterWithCacheManager(void)
Definition: store.cc:1316
static DeferredRead::DeferrableRead DeferReader
Definition: Store.h:45
void attachToDisk(const sdirno, const sfileno, const swap_status_t)
Definition: store.cc:2014
RemovalPolicy * mem_policy
Definition: MemObject.cc:45
void stopSharing(StoreEntry &)
stop any current (and prevent any future) SMP sharing of the given entry
Definition: Controller.cc:592
virtual ~StoreEntry()
Definition: store.cc:351
virtual void buffer()
Definition: store.cc:1641
int aborted_requests
Definition: StatCounters.h:152
void expireNow()
Definition: store.cc:796
int64_t store_maxobjsize
void Stats(StoreEntry *output)
Definition: store.cc:118
virtual void disconnect(StoreEntry &)
called when the entry is about to forget its association with cache_dir
Definition: Disk.h:71
static size_t inUseCount()
Definition: store.cc:177
const char * storeKeyText(const cache_key *key)
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:1629
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition: MemObject.cc:77
int locked() const
Definition: store.cc:1255
Definition: Range.h:18
Io io
current I/O state
Definition: MemObject.h:149
int validToSend() const
Definition: store.cc:1420
void freeMemorySpace(const int spaceRequired)
Definition: Controller.cc:497
const char * memStatusStr[]
Definition: store.cc:68
const cache_key * storeKeyPublicByRequestMethod(HttpRequest *request, const HttpRequestMethod &method, const KeyScope keyScope)
bool hasMemStore() const
whether there is a corresponding locked shared memory table entry
Definition: Store.h:191
virtual void flush()
Definition: store.cc:1652
STABH * callback
Definition: MemObject.h:163
void storeReplSetup(void)
SQUIDCEXTERN void hash_join(hash_table *, hash_link *)
Definition: hash.cc:132
void clear()
Definition: SBuf.cc:178
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
bool isEmpty() const
Definition: SBuf.h:420
HttpReply const * getReply() const
Definition: store.cc:1676
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:528
bool isAccepting() const
Definition: store.cc:2063
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:214
#define DBG_CRITICAL
Definition: Debug.h:45
void packInto(Packable *) const
Definition: HttpBody.cc:16
void delayAwareRead(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer callback)
Definition: store.cc:203
void OBJH(StoreEntry *)
Definition: forward.h:44
int conn
the current server connection FD
Definition: Transport.cc:26
int strListIsMember(const String *list, const SBuf &m, char del)
Definition: StrList.cc:37
Controller & Root()
safely access controller singleton
Definition: Controller.cc:877
int fdNFree(void)
Definition: fd.cc:299
int storeTooManyDiskFilesOpen(void)
Definition: store.cc:917
time_t expires
Definition: Store.h:204
void forcePublicKey(const cache_key *newkey)
Definition: store.cc:650
struct timeval current_time
Definition: stub_time.cc:15
void memOutDecision(const bool willCacheInRam)
Definition: store.cc:1862
void destroyMemObject()
Definition: store.cc:378
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:522
MemCache memCache
current [shared] memory caching state for the entry
Definition: MemObject.h:151
XitTable xitTable
current [shared] memory caching state for the entry
Definition: MemObject.h:140
void trimUnSwappable()
Definition: MemObject.cc:382
void append(char const *buf, int len)
Definition: String.cc:161
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:608
void doAbandon(const char *context)
Definition: store.cc:480
time_t squid_curtime
Definition: stub_time.cc:17
time_t timestamp
Definition: Store.h:202
void replaceHttpReply(HttpReply *, bool andStartWriting=true)
Definition: store.cc:1788
void storeInit(void)
Definition: store.cc:1325
void updateLimits()
slowly calculate (and cache) hi/lo watermarks and similar limits
Definition: Controller.cc:198
struct SquidConfig::@111 onoff
#define SWALLOW_EXCEPTIONS(code)
Definition: TextException.h:73
static void getPublicByRequest(StoreClient *aClient, HttpRequest *request)
Definition: store.cc:508
void transientsDisconnect(StoreEntry &)
disassociates the entry from the intransit table
Definition: Controller.cc:620
CacheDigest * store_digest
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
RemovalPolicy * REMOVALPOLICYCREATE(wordlist *args)
Definition: RemovalPolicy.h:80
void complete()
Definition: store.cc:1064
int RESERVED_FD
void onException() noexcept
Definition: store.cc:2170
store_client_t storeClientType() const
Definition: store.cc:267
static void getPublic(StoreClient *aClient, const char *uri, const HttpRequestMethod &method)
Definition: store.cc:515
void invokeHandlers()
bool swappingOut() const
whether we are in the process of writing this entry to disk
Definition: Store.h:119
void hashDelete()
Definition: store.cc:427
void storeSwapFileNumberSet(StoreEntry *e, sfileno filn)
uint64_t swap_file_sz
Definition: Store.h:208
int shutting_down
const char * xstrerr(int error)
Definition: xstrerror.cc:83
ping_status_t ping_status
Definition: Store.h:220
void const char HLPCB void * data
Definition: stub_helper.cc:16
struct SquidConfig::@109 Store
int64_t offset
Definition: StoreIOBuffer.h:55
void hashInsert(const cache_key *)
Definition: store.cc:418
virtual void maintain() override
perform regular periodic maintenance; TODO: move to UFSSwapDir::Maintain
Definition: Controller.cc:93
store_client_t
Definition: enums.h:67
void storeKeyFree(const cache_key *key)
StoreEntry()
Definition: store.cc:330
#define memPoolCreate
Definition: Pool.h:325
int64_t content_length
Definition: Message.h:84
void EVH(void *)
Definition: event.h:19
ETag getETag(Http::HdrType id) const
Definition: HttpHeader.cc:1332
int64_t object_sz
Definition: MemObject.h:168
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
#define cbdataReference(var)
Definition: cbdata.h:341
HttpRequestMethod method
Definition: MemObject.h:102
int len
Definition: CommRead.h:27
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:161
const char * url() const
Definition: store.cc:1606
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:782
static bool Enabled()
whether Squid is correctly configured to use a shared memory cache
Definition: MemStore.h:68
#define DBG_IMPORTANT
Definition: Debug.h:46
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
void abort()
Definition: store.cc:1113
tlv * storeSwapMetaBuild(StoreEntry *e)
bool checkCachable()
Definition: store.cc:958
HASHCMP storeKeyHashCmp
void unlockAndReset(const char *resetContext=nullptr)
Definition: Store.h:358
void handleIdleEntry(StoreEntry &)
called when the entry is no longer needed by any transaction
Definition: Controller.cc:634
#define EBIT_CLR(flag, bit)
Definition: defines.h:106
mem_status_t mem_status
Definition: Store.h:218
time_t last_modified
Definition: HttpReply.h:46
IoStatus
cache "I/O" direction and status
Definition: forward.h:40
void * xrealloc(void *s, size_t sz)
Definition: xalloc.cc:137
bool etagIsWeakEqual(const ETag &tag1, const ETag &tag2)
whether etags are weak-equal
Definition: ETag.cc:55
SQUIDCEXTERN hash_link * hash_lookup(hash_table *, const void *)
Definition: hash.cc:147
int memory_cache_first
Definition: SquidConfig.h:338
void comm_read(const Comm::ConnectionPointer &conn, char *buf, int len, AsyncCall::Pointer &callback)
Definition: Read.h:59
bool isEmpty() const
Definition: Store.h:60
bool setPublicKey(const KeyScope keyScope=ksDefault)
Definition: store.cc:593
void abandon(const char *context)
Definition: Store.h:265
struct _store_check_cachable_hist::@143 yes
void fatal(const char *message)
Definition: fatal.cc:28
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:65
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
void releaseRequest(const bool shareable=false)
Definition: store.cc:452
Definition: store.cc:97
uint16_t flags
Definition: Store.h:210
void(* Add)(RemovalPolicy *policy, StoreEntry *entry, RemovalPolicyNode *node)
Definition: RemovalPolicy.h:46
virtual void vappendf(const char *, va_list)
Definition: store.cc:847
void setNoDelay(bool const)
Definition: store.cc:253
size_t size() const
Definition: stmem.cc:408
Http::StatusLine sline
Definition: HttpReply.h:60
void(* Remove)(RemovalPolicy *policy, StoreEntry *entry, RemovalPolicyNode *node)
Definition: RemovalPolicy.h:47
bool hittingRequiresCollapsing() const
whether this entry can feed collapsed requests and only them
Definition: Store.h:194
signed_int32_t sfileno
Definition: forward.h:22
MemObject * mem_obj
Definition: Store.h:199
time_t date
Definition: HttpReply.h:44
void markEndOfReplyHeaders()
Definition: MemObject.cc:224
const char * storeStatusStr[]
Definition: store.cc:79
#define LOCAL_ARRAY(type, name, size)
Definition: leakcheck.h:18
void storeSwapTLVFree(tlv *n)
void write(const StoreIOBuffer &buf)
Definition: MemObject.cc:136
const cache_key * storeKeyPrivate()
int64_t contentLen() const
Definition: store.cc:1668
friend std::ostream & operator<<(std::ostream &os, const StoreEntry &e)
Definition: store.cc:2115
#define INDEXSD(i)
Definition: SquidConfig.h:68
int64_t minObjectSize
Definition: SquidConfig.h:267
int checkTooSmall()
Definition: store.cc:929
char const * termedBuf() const
Definition: SquidString.h:91
C end
Definition: Range.h:25
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void destroyStoreEntry(void *data)
Definition: store.cc:396
uint16_t refcount
Definition: Store.h:209
void STABH(void *)
Definition: MemObject.h:28
void const char * buf
Definition: stub_helper.cc:16
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
void lengthWentBad(const char *reason)
flags [truncated or too big] entry with ENTRY_BAD_LENGTH and releases it
Definition: store.cc:1056
void Maintain(void *unused)
Definition: store.cc:1181
virtual void created(StoreEntry *)=0
static OBJH storeCheckCachableStats
Definition: store.cc:108
time_t negativeTtl
Definition: SquidConfig.h:96
bool swappedOut() const
whether the entire entry is now on disk (possibly marked for deletion)
Definition: Store.h:121
void storeGetMemSpace(int size)
Definition: store.cc:1167
AsyncCall::Pointer deferredProducer
producer callback registered with deferProducer
Definition: Store.h:313
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:114
void setCollapsingRequirement(const bool required)
allow or forbid collapsed requests feeding
Definition: store.cc:2087
signed int sdirno
Definition: forward.h:23
unsigned short lock_count
Definition: Store.h:302
HttpHeader header
Definition: Message.h:75
SwapOut swapout
Definition: MemObject.h:124
const cache_key * calcPublicKey(const KeyScope keyScope)
Definition: store.cc:676
bool makePublic(const KeyScope keyScope=ksDefault)
Definition: store.cc:145
Definition: enums.h:46
SBuf vary_headers
Definition: MemObject.h:174
static std::stack< StoreEntry * > LateReleaseStack
Definition: store.cc:114
void dump(int debug_lvl) const
Definition: store.cc:1539
void storeFreeMemory(void)
Definition: store.cc:1401
void memoryDisconnect(StoreEntry &)
disassociates the entry from the memory cache, preserving cached data
Definition: Controller.cc:584
void eventAdd(const char *name, EVH *func, void *arg, double when, int weight, bool cbdata)
Definition: event.cc:109
void storeFsInit(void)
Definition: store.cc:1698
Store::Disk & disk() const
the disk this entry is [being] cached on; asserts for entries w/o a disk
Definition: store.cc:1994
struct _store_check_cachable_hist::@142 no
RequestFlags flags
Definition: HttpRequest.h:141
#define EBIT_SET(flag, bit)
Definition: defines.h:105
store_status_t store_status
Definition: Store.h:222
prohibits making the key public
Definition: enums.h:94
void storeLogOpen(void)
Definition: store_log.cc:123
struct timeval store_complete_stop
bool hasIfNoneMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-None-Match etags
Definition: store.cc:1954
void swapOutDecision(const MemObject::SwapOut::Decision &decision)
Definition: store.cc:1868
int checkNegativeHit() const
Definition: store.cc:1366
void swapOutFileClose(int how)
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1038
char * storeSwapMetaPack(tlv *tlv_list, int *length)
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:71
#define ScheduleCallHere(call)
Definition: AsyncCall.h:166
void storeDigestInit(void)
bool cacheNegatively()
Definition: store.cc:166
HttpBody body
Definition: HttpReply.h:62
void write(StoreIOBuffer)
Definition: store.cc:803
#define PROF_start(probename)
Definition: Profiler.h:62
void addWriting(StoreEntry *, const cache_key *)
Definition: Controller.cc:722
void FreeMemory()
undo Init()
Definition: Controller.cc:890
struct MemObject::abort_ abort
virtual void evictCached(StoreEntry &) override
Definition: Controller.cc:457
bool memoryCachable()
checkCachable() and can be cached in memory
Definition: store.cc:1345
bool swapoutFailed() const
whether we failed to write this entry to disk
Definition: Store.h:123
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:264
bool checkTooBig() const
Definition: store.cc:945
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:422
int store_open_disk_fd
void storeConfigure(void)
Definition: store.cc:1339
bool checkDeferRead(int fd) const
Definition: store.cc:247
KeyScope
Definition: store_key_md5.h:18
swap_status_t
StoreEntry relationship with a disk cache.
Definition: enums.h:51
StoreEntry * storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod &method)
Definition: store.cc:764
C * getRaw() const
Definition: RefCount.h:74
void reset()
Definition: MemObject.cc:259
char * buf
Definition: CommRead.h:26
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:112
static Pointer Create(const CommandPointer &cmd)
int const char size_t
Definition: stub_liblog.cc:86
SQUIDCEXTERN void hash_remove_link(hash_table *, hash_link *)
Definition: hash.cc:224
StoreEntry * adjustVary()
Definition: store.cc:689
bool peerResponseTime(struct timeval &responseTime)
Definition: access_log.cc:317
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:55
void storeRebuildStart(void)
int nclients
Definition: MemObject.h:111
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
swap_status_t swap_status
Definition: Store.h:224
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition: MemObject.h:120
const char * str
quoted-string
Definition: ETag.h:20
void registerAbort(STABH *cb, void *)
Definition: store.cc:1520
#define INT_MAX
Definition: types.h:76
int hot_obj_count
void clearPublicKeyScope()
Definition: store.cc:633
void storeErrorResponse(HttpReply *reply)
Store a prepared error response. MemObject locks the reply object.
Definition: store.cc:1771
virtual void init() override
Definition: Controller.cc:59
void deferProducer(const AsyncCall::Pointer &producer)
call back producer when more buffer space is available
Definition: store.cc:358
void clearPrivate()
Definition: store.cc:158
const cache_key * storeKeyPublicByRequest(HttpRequest *request, const KeyScope keyScope)
void clean()
Definition: String.cc:125
time_t lastModified_
received Last-Modified value or -1; use lastModified()
Definition: Store.h:206
#define PROF_stop(probename)
Definition: Profiler.h:63
void startWriting()
Definition: store.cc:1804
failure: caller left before swapping out everything
Definition: StoreIOState.h:71
time_t expires
Definition: HttpReply.h:48
bool hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
whether at least one of the request ETags matches entity ETag
Definition: store.cc:1965
void unregisterAbort()
Definition: store.cc:1529
time_t lastref
Definition: Store.h:203
enum _mem_status_t mem_status_t
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:534
mem_hdr data_hdr
Definition: MemObject.h:103
void storeKeyInit(void)
int expiresMoreThan(time_t expires, time_t when)
Definition: store.cc:1411
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1947
void trimSwappable()
Definition: MemObject.cc:357
void reset()
Definition: store.cc:1682
void setPrivateKey(const bool shareable, const bool permanent)
Definition: store.cc:566
void transientsClearCollapsingRequirement(StoreEntry &e)
removes collapsing requirement (for future hits)
Definition: Controller.cc:627
void transientsAbandonmentCheck()
Definition: store.cc:1849
const char * swapStatusStr[]
Definition: store.cc:84
const cache_key * storeKeyPublic(const char *url, const HttpRequestMethod &method, const KeyScope keyScope)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:881
Comm::ConnectionPointer conn
Definition: CommRead.h:25
size_type size() const
Definition: SquidString.h:72
const char * storeEntryFlags(const StoreEntry *entry)
Definition: stat.cc:276
bool validLength() const
Definition: store.cc:1272
const char * describeTimestamps() const
Definition: store.cc:2075
void negativeCache()
Definition: store.cc:1387
HttpRequestPointer request
Definition: MemObject.h:155
#define EBIT_TEST(flag, bit)
Definition: defines.h:107
virtual void stat(StoreEntry &) const override
Definition: Controller.cc:141
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
void checkDisk() const
does nothing except throwing if disk-associated data members are inconsistent
Definition: store.cc:2036
A StoreEntry::getPublic*() caller.
Definition: StoreClient.h:23
int size
Definition: ModDevPoll.cc:77
void trimMemory(const bool preserveSwappable)
Definition: store.cc:1877
size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:229
int64_t inmem_lo
Definition: MemObject.h:104
#define false
Definition: GnuRegex.c:233
static EVH storeLateRelease
Definition: store.cc:109
void packHeadersUsingSlowPacker(Packable &p) const
same as packHeadersUsingFastPacker() but assumes that p cannot quickly process small additions ...
Definition: HttpReply.cc:94
const HttpReplyPointer & getReply() const
Definition: MemObject.h:57
RemovalPolicySettings * memPolicy
Definition: SquidConfig.h:94
void kickProducer()
calls back producer registered with deferProducer
Definition: store.cc:368
manages a single cache_dir
Definition: Disk.h:21
void setMemStatus(mem_status_t)
Definition: store.cc:1564
void lock(const char *context)
Definition: store.cc:439
void createMemObject()
Definition: store.cc:1615

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors