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 (auto memObj = mem_obj) {
390  mem_obj = NULL;
391  delete memObj;
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  const auto &reply = mem_obj->freshestReply();
698 
699  if (mem_obj->vary_headers.isEmpty()) {
700  /* First handle the case where the object no longer varies */
701  request->vary_headers.clear();
702  } else {
703  if (!request->vary_headers.isEmpty() && request->vary_headers.cmp(mem_obj->vary_headers) != 0) {
704  /* Oops.. the variance has changed. Kill the base object
705  * to record the new variance key
706  */
707  request->vary_headers.clear(); /* free old "bad" variance key */
709  pe->release(true);
710  }
711 
712  /* Make sure the request knows the variance status */
713  if (request->vary_headers.isEmpty())
714  request->vary_headers = httpMakeVaryMark(request.getRaw(), &reply);
715  }
716 
717  // TODO: storeGetPublic() calls below may create unlocked entries.
718  // We should add/use storeHas() API or lock/unlock those entries.
720  /* Create "vary" base object */
721  StoreEntry *pe = storeCreateEntry(mem_obj->storeId(), mem_obj->logUri(), request->flags, request->method);
722  // XXX: storeCreateEntry() already tries to make `pe` public under
723  // certain conditions. If those conditions do not apply to Vary markers,
724  // then refactor to call storeCreatePureEntry() above. Otherwise,
725  // refactor to simply check whether `pe` is already public below.
726  if (!pe->makePublic()) {
727  pe->unlock("StoreEntry::adjustVary+failed_makePublic");
728  throw TexcHere("failed to make Vary marker public");
729  }
730  /* We are allowed to do this typecast */
731  const HttpReplyPointer rep(new HttpReply);
732  rep->setHeaders(Http::scOkay, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
733  auto vary = reply.header.getList(Http::HdrType::VARY);
734 
735  if (vary.size()) {
736  /* Again, we own this structure layout */
737  rep->header.putStr(Http::HdrType::VARY, vary.termedBuf());
738  vary.clean();
739  }
740 
741 #if X_ACCELERATOR_VARY
742  vary = reply.header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY);
743 
744  if (vary.size() > 0) {
745  /* Again, we own this structure layout */
746  rep->header.putStr(Http::HdrType::HDR_X_ACCELERATOR_VARY, vary.termedBuf());
747  vary.clean();
748  }
749 
750 #endif
751  pe->replaceHttpReply(rep, false); // no write until timestampsSet()
752 
753  pe->timestampsSet();
754 
755  pe->startWriting(); // after timestampsSet()
756 
757  pe->complete();
758 
759  return pe;
760  }
761  return nullptr;
762 }
763 
764 StoreEntry *
765 storeCreatePureEntry(const char *url, const char *log_url, const HttpRequestMethod& method)
766 {
767  StoreEntry *e = NULL;
768  debugs(20, 3, "storeCreateEntry: '" << url << "'");
769 
770  e = new StoreEntry();
771  e->createMemObject(url, log_url, method);
772 
774  e->refcount = 0;
775  e->lastref = squid_curtime;
776  e->timestamp = -1; /* set in StoreEntry::timestampsSet() */
777  e->ping_status = PING_NONE;
779  return e;
780 }
781 
782 StoreEntry *
783 storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod& method)
784 {
785  StoreEntry *e = storeCreatePureEntry(url, logUrl, method);
786  e->lock("storeCreateEntry");
787 
788  if (!neighbors_do_private_keys && flags.hierarchical && flags.cachable && e->setPublicKey())
789  return e;
790 
791  e->setPrivateKey(false, !flags.cachable);
792  return e;
793 }
794 
795 /* Mark object as expired */
796 void
798 {
799  debugs(20, 3, "StoreEntry::expireNow: '" << getMD5Text() << "'");
801 }
802 
803 void
805 {
806  assert(mem_obj != NULL);
807  /* This assert will change when we teach the store to update */
808  PROF_start(StoreEntry_write);
810 
811  // XXX: caller uses content offset, but we also store headers
812  writeBuffer.offset += mem_obj->baseReply().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() - mem_obj->baseReply().hdr_sz;
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 
939  const auto clen = mem().baseReply().content_length;
940  if (clen >= 0 && clen < Config.Store.minObjectSize)
941  return 1;
942  return 0;
943 }
944 
945 bool
947 {
949  return true;
950 
951  const auto clen = mem_obj->baseReply().content_length;
952  return (clen >= 0 && clen > store_maxobjsize);
953 }
954 
955 // TODO: move "too many open..." checks outside -- we are called too early/late
956 bool
958 {
959  // XXX: This method is used for both memory and disk caches, but some
960  // checks are specific to disk caches. Move them to mayStartSwapOut().
961 
962  // XXX: This method may be called several times, sometimes with different
963  // outcomes, making store_check_cachable_hist counters misleading.
964 
965  // check this first to optimize handling of repeated calls for uncachables
967  debugs(20, 2, "StoreEntry::checkCachable: NO: not cachable");
969  return 0; // avoid rerequesting release below
970  }
971 
972 #if CACHE_ALL_METHODS
973 
974  if (mem_obj->method != Http::METHOD_GET) {
975  debugs(20, 2, "StoreEntry::checkCachable: NO: non-GET method");
977  } else
978 #endif
980  debugs(20, 2, "StoreEntry::checkCachable: NO: wrong content-length");
982  } else if (EBIT_TEST(flags, ENTRY_NEGCACHED)) {
983  debugs(20, 3, "StoreEntry::checkCachable: NO: negative cached");
985  return 0; /* avoid release call below */
986  } else if (!mem_obj) {
987  // XXX: In bug 4131, we forgetHit() without mem_obj, so we need
988  // this segfault protection, but how can we get such a HIT?
989  debugs(20, 2, "StoreEntry::checkCachable: NO: missing parts: " << *this);
991  } else if (checkTooBig()) {
992  debugs(20, 2, "StoreEntry::checkCachable: NO: too big");
994  } else if (checkTooSmall()) {
995  debugs(20, 2, "StoreEntry::checkCachable: NO: too small");
997  } else if (EBIT_TEST(flags, KEY_PRIVATE)) {
998  debugs(20, 3, "StoreEntry::checkCachable: NO: private key");
1000  } else if (hasDisk()) {
1001  /*
1002  * the remaining cases are only relevant if we haven't
1003  * started swapping out the object yet.
1004  */
1005  return 1;
1006  } else if (storeTooManyDiskFilesOpen()) {
1007  debugs(20, 2, "StoreEntry::checkCachable: NO: too many disk files open");
1009  } else if (fdNFree() < RESERVED_FD) {
1010  debugs(20, 2, "StoreEntry::checkCachable: NO: too many FD's open");
1012  } else {
1014  return 1;
1015  }
1016 
1017  releaseRequest();
1018  return 0;
1019 }
1020 
1021 void
1023 {
1024  storeAppendPrintf(sentry, "Category\t Count\n");
1025 
1026 #if CACHE_ALL_METHODS
1027 
1028  storeAppendPrintf(sentry, "no.non_get\t%d\n",
1030 #endif
1031 
1032  storeAppendPrintf(sentry, "no.not_entry_cachable\t%d\n",
1034  storeAppendPrintf(sentry, "no.wrong_content_length\t%d\n",
1036  storeAppendPrintf(sentry, "no.negative_cached\t%d\n",
1038  storeAppendPrintf(sentry, "no.missing_parts\t%d\n",
1040  storeAppendPrintf(sentry, "no.too_big\t%d\n",
1042  storeAppendPrintf(sentry, "no.too_small\t%d\n",
1044  storeAppendPrintf(sentry, "no.private_key\t%d\n",
1046  storeAppendPrintf(sentry, "no.too_many_open_files\t%d\n",
1048  storeAppendPrintf(sentry, "no.too_many_open_fds\t%d\n",
1050  storeAppendPrintf(sentry, "yes.default\t%d\n",
1052 }
1053 
1054 void
1055 StoreEntry::lengthWentBad(const char *reason)
1056 {
1057  debugs(20, 3, "because " << reason << ": " << *this);
1059  releaseRequest();
1060 }
1061 
1062 void
1064 {
1065  debugs(20, 3, "storeComplete: '" << getMD5Text() << "'");
1066 
1067  // To preserve forwarding retries, call FwdState::complete() instead.
1069 
1070  if (store_status != STORE_PENDING) {
1071  /*
1072  * if we're not STORE_PENDING, then probably we got aborted
1073  * and there should be NO clients on this entry
1074  */
1076  assert(mem_obj->nclients == 0);
1077  return;
1078  }
1079 
1081 
1083 
1085 
1087  lengthWentBad("!validLength() in complete()");
1088 
1089 #if USE_CACHE_DIGESTS
1090  if (mem_obj->request)
1092 
1093 #endif
1094  /*
1095  * We used to call invokeHandlers, then storeSwapOut. However,
1096  * Madhukar Reddy <myreddy@persistence.com> reported that
1097  * responses without content length would sometimes get released
1098  * in client_side, thinking that the response is incomplete.
1099  */
1100  invokeHandlers();
1101 }
1102 
1103 /*
1104  * Someone wants to abort this transfer. Set the reason in the
1105  * request structure, call the callback and mark the
1106  * entry for releasing
1107  */
1108 void
1110 {
1113  assert(mem_obj != NULL);
1114  debugs(20, 6, "storeAbort: " << getMD5Text());
1115 
1116  lock("StoreEntry::abort"); /* lock while aborting */
1117  negativeCache();
1118 
1119  releaseRequest();
1120 
1122 
1123  // allow the Store clients to be told about the problem
1125 
1127 
1129 
1130  /* Notify the server side */
1131 
1132  /*
1133  * DPW 2007-05-07
1134  * Should we check abort.data for validity?
1135  */
1136  if (mem_obj->abort.callback) {
1138  debugs(20, DBG_IMPORTANT,HERE << "queueing event when abort.data is not valid");
1139  eventAdd("mem_obj->abort.callback",
1141  mem_obj->abort.data,
1142  0.0,
1143  true);
1144  unregisterAbort();
1145  }
1146 
1147  /* XXX Should we reverse these two, so that there is no
1148  * unneeded disk swapping triggered?
1149  */
1150  /* Notify the client side */
1151  invokeHandlers();
1152 
1153  // abort swap out, invalidating what was created so far (release follows)
1155 
1156  unlock("StoreEntry::abort"); /* unlock */
1157 }
1158 
1162 void
1164 {
1166  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1167  Store::Root().freeMemorySpace(size);
1169 }
1170 
1171 /* thunk through to Store::Root().maintain(). Note that this would be better still
1172  * if registered against the root store itself, but that requires more complex
1173  * update logic - bigger fish to fry first. Long term each store when
1174  * it becomes active will self register
1175  */
1176 void
1178 {
1179  Store::Root().maintain();
1180 
1181  /* Reregister a maintain event .. */
1182  eventAdd("MaintainSwapSpace", Maintain, NULL, 1.0, 1);
1183 
1184 }
1185 
1186 /* The maximum objects to scan for maintain storage space */
1187 #define MAINTAIN_MAX_SCAN 1024
1188 #define MAINTAIN_MAX_REMOVE 64
1189 
1190 void
1191 StoreEntry::release(const bool shareable)
1192 {
1193  PROF_start(storeRelease);
1194  debugs(20, 3, shareable << ' ' << *this << ' ' << getMD5Text());
1195  /* If, for any reason we can't discard this object because of an
1196  * outstanding request, mark it for pending release */
1197 
1198  if (locked()) {
1199  releaseRequest(shareable);
1200  PROF_stop(storeRelease);
1201  return;
1202  }
1203 
1205  /* TODO: Teach disk stores to handle releases during rebuild instead. */
1206 
1207  // lock the entry until rebuilding is done
1208  lock("storeLateRelease");
1209  releaseRequest(shareable);
1210  LateReleaseStack.push(this);
1211  PROF_stop(storeRelease);
1212  return;
1213  }
1214 
1215  storeLog(STORE_LOG_RELEASE, this);
1216  Store::Root().evictCached(*this);
1217  destroyStoreEntry(static_cast<hash_link *>(this));
1218  PROF_stop(storeRelease);
1219 }
1220 
1221 static void
1223 {
1224  StoreEntry *e;
1225  static int n = 0;
1226 
1228  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1229  return;
1230  }
1231 
1232  // TODO: this works but looks unelegant.
1233  for (int i = 0; i < 10; ++i) {
1234  if (LateReleaseStack.empty()) {
1235  debugs(20, DBG_IMPORTANT, "storeLateRelease: released " << n << " objects");
1236  return;
1237  } else {
1238  e = LateReleaseStack.top();
1239  LateReleaseStack.pop();
1240  }
1241 
1242  e->unlock("storeLateRelease");
1243  ++n;
1244  }
1245 
1246  eventAdd("storeLateRelease", storeLateRelease, NULL, 0.0, 1);
1247 }
1248 
1252 bool
1254 {
1255  int64_t diff;
1256  assert(mem_obj != NULL);
1257  const auto reply = &mem_obj->baseReply();
1258  debugs(20, 3, "storeEntryValidLength: Checking '" << getMD5Text() << "'");
1259  debugs(20, 5, "storeEntryValidLength: object_len = " <<
1260  objectLen());
1261  debugs(20, 5, "storeEntryValidLength: hdr_sz = " << reply->hdr_sz);
1262  debugs(20, 5, "storeEntryValidLength: content_length = " << reply->content_length);
1263 
1264  if (reply->content_length < 0) {
1265  debugs(20, 5, "storeEntryValidLength: Unspecified content length: " << getMD5Text());
1266  return 1;
1267  }
1268 
1269  if (reply->hdr_sz == 0) {
1270  debugs(20, 5, "storeEntryValidLength: Zero header size: " << getMD5Text());
1271  return 1;
1272  }
1273 
1274  if (mem_obj->method == Http::METHOD_HEAD) {
1275  debugs(20, 5, "storeEntryValidLength: HEAD request: " << getMD5Text());
1276  return 1;
1277  }
1278 
1279  if (reply->sline.status() == Http::scNotModified)
1280  return 1;
1281 
1282  if (reply->sline.status() == Http::scNoContent)
1283  return 1;
1284 
1285  diff = reply->hdr_sz + reply->content_length - objectLen();
1286 
1287  if (diff == 0)
1288  return 1;
1289 
1290  debugs(20, 3, "storeEntryValidLength: " << (diff < 0 ? -diff : diff) << " bytes too " << (diff < 0 ? "big" : "small") <<"; '" << getMD5Text() << "'" );
1291 
1292  return 0;
1293 }
1294 
1295 static void
1297 {
1298  Mgr::RegisterAction("storedir", "Store Directory Stats", Store::Stats, 0, 1);
1299  Mgr::RegisterAction("store_io", "Store IO Interface Stats", &Mgr::StoreIoAction::Create, 0, 1);
1300  Mgr::RegisterAction("store_check_cachable_stats", "storeCheckCachable() Stats",
1301  storeCheckCachableStats, 0, 1);
1302 }
1303 
1304 void
1306 {
1307  storeKeyInit();
1309  storeDigestInit();
1310  storeLogOpen();
1311  eventAdd("storeLateRelease", storeLateRelease, NULL, 1.0, 1);
1312  Store::Root().init();
1314 
1316 }
1317 
1318 void
1320 {
1322 }
1323 
1324 bool
1326 {
1327  if (!checkCachable())
1328  return 0;
1329 
1330  if (mem_obj == NULL)
1331  return 0;
1332 
1333  if (mem_obj->data_hdr.size() == 0)
1334  return 0;
1335 
1336  if (mem_obj->inmem_lo != 0)
1337  return 0;
1338 
1340  return 0;
1341 
1342  return 1;
1343 }
1344 
1345 int
1347 {
1349  return 0;
1350 
1351  if (expires <= squid_curtime)
1352  return 0;
1353 
1354  if (store_status != STORE_OK)
1355  return 0;
1356 
1357  return 1;
1358 }
1359 
1366 void
1368 {
1369  // XXX: should make the default for expires 0 instead of -1
1370  // so we can distinguish "Expires: -1" from nothing.
1371  if (expires <= 0)
1372 #if USE_HTTP_VIOLATIONS
1374 #else
1376 #endif
1378 }
1379 
1380 void
1382 {
1384 #if USE_CACHE_DIGESTS
1385  delete store_digest;
1386 #endif
1387  store_digest = NULL;
1388 }
1389 
1390 int
1391 expiresMoreThan(time_t expires, time_t when)
1392 {
1393  if (expires < 0) /* No Expires given */
1394  return 1;
1395 
1396  return (expires > (squid_curtime + when));
1397 }
1398 
1399 int
1401 {
1403  return 0;
1404 
1406  if (expires <= squid_curtime)
1407  return 0;
1408 
1410  return 0;
1411 
1412  // now check that the entry has a cache backing or is collapsed
1413  if (hasDisk()) // backed by a disk cache
1414  return 1;
1415 
1416  if (swappingOut()) // will be backed by a disk cache
1417  return 1;
1418 
1419  if (!mem_obj) // not backed by a memory cache and not collapsed
1420  return 0;
1421 
1422  // StoreEntry::storeClientType() assumes DISK_CLIENT here, but there is no
1423  // disk cache backing that store_client constructor will assert. XXX: This
1424  // is wrong for range requests (that could feed off nibbled memory) and for
1425  // entries backed by the shared memory cache (that could, in theory, get
1426  // nibbled bytes from that cache, but there is no such "memoryIn" code).
1427  if (mem_obj->inmem_lo) // in memory cache, but got nibbled at
1428  return 0;
1429 
1430  // The following check is correct but useless at this position. TODO: Move
1431  // it up when the shared memory cache can either replenish locally nibbled
1432  // bytes or, better, does not use local RAM copy at all.
1433  // if (mem_obj->memCache.index >= 0) // backed by a shared memory cache
1434  // return 1;
1435 
1436  return 1;
1437 }
1438 
1439 bool
1441 {
1442  debugs(20, 7, *this << " had " << describeTimestamps());
1443 
1444  // TODO: Remove change-reducing "&" before the official commit.
1445  const auto reply = &mem().freshestReply();
1446 
1447  time_t served_date = reply->date;
1448  int age = reply->header.getInt(Http::HdrType::AGE);
1449  /* Compute the timestamp, mimicking RFC2616 section 13.2.3. */
1450  /* make sure that 0 <= served_date <= squid_curtime */
1451 
1452  if (served_date < 0 || served_date > squid_curtime)
1453  served_date = squid_curtime;
1454 
1455  /* Bug 1791:
1456  * If the returned Date: is more than 24 hours older than
1457  * the squid_curtime, then one of us needs to use NTP to set our
1458  * clock. We'll pretend that our clock is right.
1459  */
1460  else if (served_date < (squid_curtime - 24 * 60 * 60) )
1461  served_date = squid_curtime;
1462 
1463  /*
1464  * Compensate with Age header if origin server clock is ahead
1465  * of us and there is a cache in between us and the origin
1466  * server. But DONT compensate if the age value is larger than
1467  * squid_curtime because it results in a negative served_date.
1468  */
1469  if (age > squid_curtime - served_date)
1470  if (squid_curtime > age)
1471  served_date = squid_curtime - age;
1472 
1473  // compensate for Squid-to-server and server-to-Squid delays
1474  if (mem_obj && mem_obj->request) {
1475  struct timeval responseTime;
1476  if (mem_obj->request->hier.peerResponseTime(responseTime))
1477  served_date -= responseTime.tv_sec;
1478  }
1479 
1480  time_t exp = 0;
1481  if (reply->expires > 0 && reply->date > -1)
1482  exp = served_date + (reply->expires - reply->date);
1483  else
1484  exp = reply->expires;
1485 
1486  if (timestamp == served_date && expires == exp) {
1487  // if the reply lacks LMT, then we now know that our effective
1488  // LMT (i.e., timestamp) will stay the same, otherwise, old and
1489  // new modification times must match
1490  if (reply->last_modified < 0 || reply->last_modified == lastModified())
1491  return false; // nothing has changed
1492  }
1493 
1494  expires = exp;
1495 
1496  lastModified_ = reply->last_modified;
1497 
1498  timestamp = served_date;
1499 
1500  debugs(20, 5, *this << " has " << describeTimestamps());
1501  return true;
1502 }
1503 
1504 bool
1506 {
1507  assert(mem_obj);
1508  assert(e304.mem_obj);
1509 
1510  // update reply before calling timestampsSet() below
1511  const auto &oldReply = mem_obj->freshestReply();
1512  const auto updatedReply = oldReply.recreateOnNotModified(e304.mem_obj->baseReply());
1513  if (updatedReply) // HTTP 304 brought in new information
1514  mem_obj->updateReply(*updatedReply);
1515  // else continue to use the previous update, if any
1516 
1517  if (!timestampsSet() && !updatedReply)
1518  return false;
1519 
1520  // Keep the old mem_obj->vary_headers; see HttpHeader::skipUpdateHeader().
1521 
1522  debugs(20, 5, "updated basics in " << *this << " with " << e304);
1523  mem_obj->appliedUpdates = true; // helps in triage; may already be true
1524  return true;
1525 }
1526 
1527 void
1529 {
1530  assert(mem_obj);
1532  mem_obj->abort.callback = cb;
1533  mem_obj->abort.data = cbdataReference(data);
1534 }
1535 
1536 void
1538 {
1539  assert(mem_obj);
1540  if (mem_obj->abort.callback) {
1543  }
1544 }
1545 
1546 void
1547 StoreEntry::dump(int l) const
1548 {
1549  debugs(20, l, "StoreEntry->key: " << getMD5Text());
1550  debugs(20, l, "StoreEntry->next: " << next);
1551  debugs(20, l, "StoreEntry->mem_obj: " << mem_obj);
1552  debugs(20, l, "StoreEntry->timestamp: " << timestamp);
1553  debugs(20, l, "StoreEntry->lastref: " << lastref);
1554  debugs(20, l, "StoreEntry->expires: " << expires);
1555  debugs(20, l, "StoreEntry->lastModified_: " << lastModified_);
1556  debugs(20, l, "StoreEntry->swap_file_sz: " << swap_file_sz);
1557  debugs(20, l, "StoreEntry->refcount: " << refcount);
1558  debugs(20, l, "StoreEntry->flags: " << storeEntryFlags(this));
1559  debugs(20, l, "StoreEntry->swap_dirn: " << swap_dirn);
1560  debugs(20, l, "StoreEntry->swap_filen: " << swap_filen);
1561  debugs(20, l, "StoreEntry->lock_count: " << lock_count);
1562  debugs(20, l, "StoreEntry->mem_status: " << mem_status);
1563  debugs(20, l, "StoreEntry->ping_status: " << ping_status);
1564  debugs(20, l, "StoreEntry->store_status: " << store_status);
1565  debugs(20, l, "StoreEntry->swap_status: " << swap_status);
1566 }
1567 
1568 /*
1569  * NOTE, this function assumes only two mem states
1570  */
1571 void
1573 {
1574  if (new_status == mem_status)
1575  return;
1576 
1577  // are we using a shared memory cache?
1578  if (MemStore::Enabled()) {
1579  // This method was designed to update replacement policy, not to
1580  // actually purge something from the memory cache (TODO: rename?).
1581  // Shared memory cache does not have a policy that needs updates.
1582  mem_status = new_status;
1583  return;
1584  }
1585 
1586  assert(mem_obj != NULL);
1587 
1588  if (new_status == IN_MEMORY) {
1589  assert(mem_obj->inmem_lo == 0);
1590 
1591  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1592  debugs(20, 4, "not inserting special " << *this << " into policy");
1593  } else {
1594  mem_policy->Add(mem_policy, this, &mem_obj->repl);
1595  debugs(20, 4, "inserted " << *this << " key: " << getMD5Text());
1596  }
1597 
1598  ++hot_obj_count; // TODO: maintain for the shared hot cache as well
1599  } else {
1600  if (EBIT_TEST(flags, ENTRY_SPECIAL)) {
1601  debugs(20, 4, "not removing special " << *this << " from policy");
1602  } else {
1604  debugs(20, 4, "removed " << *this);
1605  }
1606 
1607  --hot_obj_count;
1608  }
1609 
1610  mem_status = new_status;
1611 }
1612 
1613 const char *
1615 {
1616  if (mem_obj == NULL)
1617  return "[null_mem_obj]";
1618  else
1619  return mem_obj->storeId();
1620 }
1621 
1622 void
1624 {
1625  assert(!mem_obj);
1626  mem_obj = new MemObject();
1627 }
1628 
1629 void
1630 StoreEntry::createMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1631 {
1632  assert(!mem_obj);
1633  ensureMemObject(aUrl, aLogUrl, aMethod);
1634 }
1635 
1636 void
1637 StoreEntry::ensureMemObject(const char *aUrl, const char *aLogUrl, const HttpRequestMethod &aMethod)
1638 {
1639  if (!mem_obj)
1640  mem_obj = new MemObject();
1641  mem_obj->setUris(aUrl, aLogUrl, aMethod);
1642 }
1643 
1648 void
1650 {
1652 }
1653 
1659 void
1661 {
1662  if (EBIT_TEST(flags, DELAY_SENDING)) {
1664  invokeHandlers();
1665  }
1666 }
1667 
1668 void
1670 {
1671  debugs(20, 3, url());
1672  mem().reset();
1673  expires = lastModified_ = timestamp = -1;
1674 }
1675 
1676 /*
1677  * storeFsInit
1678  *
1679  * This routine calls the SETUP routine for each fs type.
1680  * I don't know where the best place for this is, and I'm not going to shuffle
1681  * around large chunks of code right now (that can be done once its working.)
1682  */
1683 void
1685 {
1686  storeReplSetup();
1687 }
1688 
1689 /*
1690  * called to add another store removal policy module
1691  */
1692 void
1693 storeReplAdd(const char *type, REMOVALPOLICYCREATE * create)
1694 {
1695  int i;
1696 
1697  /* find the number of currently known repl types */
1698  for (i = 0; storerepl_list && storerepl_list[i].typestr; ++i) {
1699  if (strcmp(storerepl_list[i].typestr, type) == 0) {
1700  debugs(20, DBG_IMPORTANT, "WARNING: Trying to load store replacement policy " << type << " twice.");
1701  return;
1702  }
1703  }
1704 
1705  /* add the new type */
1706  storerepl_list = static_cast<storerepl_entry_t *>(xrealloc(storerepl_list, (i + 2) * sizeof(storerepl_entry_t)));
1707 
1708  memset(&storerepl_list[i + 1], 0, sizeof(storerepl_entry_t));
1709 
1710  storerepl_list[i].typestr = type;
1711 
1712  storerepl_list[i].create = create;
1713 }
1714 
1715 /*
1716  * Create a removal policy instance
1717  */
1718 RemovalPolicy *
1720 {
1721  storerepl_entry_t *r;
1722 
1723  for (r = storerepl_list; r && r->typestr; ++r) {
1724  if (strcmp(r->typestr, settings->type) == 0)
1725  return r->create(settings->args);
1726  }
1727 
1728  debugs(20, DBG_IMPORTANT, "ERROR: Unknown policy " << settings->type);
1729  debugs(20, DBG_IMPORTANT, "ERROR: Be sure to have set cache_replacement_policy");
1730  debugs(20, DBG_IMPORTANT, "ERROR: and memory_replacement_policy in squid.conf!");
1731  fatalf("ERROR: Unknown policy %s\n", settings->type);
1732  return NULL; /* NOTREACHED */
1733 }
1734 
1735 #if 0
1736 void
1738 {
1739  if (e->swap_file_number == filn)
1740  return;
1741 
1742  if (filn < 0) {
1743  assert(-1 == filn);
1744  storeDirMapBitReset(e->swap_file_number);
1745  storeDirLRUDelete(e);
1746  e->swap_file_number = -1;
1747  } else {
1748  assert(-1 == e->swap_file_number);
1749  storeDirMapBitSet(e->swap_file_number = filn);
1750  storeDirLRUAdd(e);
1751  }
1752 }
1753 
1754 #endif
1755 
1756 void
1758 {
1759  lock("StoreEntry::storeErrorResponse");
1760  buffer();
1762  flush();
1763  complete();
1764  negativeCache();
1765  releaseRequest(false); // if it is safe to negatively cache, sharing is OK
1766  unlock("StoreEntry::storeErrorResponse");
1767 }
1768 
1769 /*
1770  * Replace a store entry with
1771  * a new reply. This eats the reply.
1772  */
1773 void
1774 StoreEntry::replaceHttpReply(const HttpReplyPointer &rep, const bool andStartWriting)
1775 {
1776  debugs(20, 3, "StoreEntry::replaceHttpReply: " << url());
1777 
1778  if (!mem_obj) {
1779  debugs(20, DBG_CRITICAL, "Attempt to replace object with no in-memory representation");
1780  return;
1781  }
1782 
1783  mem_obj->replaceBaseReply(rep);
1784 
1785  if (andStartWriting)
1786  startWriting();
1787 }
1788 
1789 void
1791 {
1792  /* TODO: when we store headers separately remove the header portion */
1793  /* TODO: mark the length of the headers ? */
1794  /* We ONLY want the headers */
1795  assert (isEmpty());
1796  assert(mem_obj);
1797 
1798  // Per MemObject replies definitions, we can only write our base reply.
1799  // Currently, all callers replaceHttpReply() first, so there is no updated
1800  // reply here anyway. Eventually, we may need to support the
1801  // updateOnNotModified(),startWriting() sequence as well.
1803  const auto rep = &mem_obj->baseReply();
1804 
1805  buffer();
1806  rep->packHeadersUsingSlowPacker(*this);
1808 
1809  rep->body.packInto(this);
1810  flush();
1811 
1812  // The entry headers are written, new clients
1813  // should not collapse anymore.
1814  if (hittingRequiresCollapsing()) {
1815  setCollapsingRequirement(false);
1817  }
1818 }
1819 
1820 char const *
1822 {
1823  StoreMeta *tlv_list = storeSwapMetaBuild(this);
1824  int swap_hdr_sz;
1825  char *result = storeSwapMetaPack(tlv_list, &swap_hdr_sz);
1826  storeSwapTLVFree(tlv_list);
1827  assert (swap_hdr_sz >= 0);
1828  length = static_cast<size_t>(swap_hdr_sz);
1829  return result;
1830 }
1831 
1838 void
1840 {
1841  if (mem_obj && !Store::Root().transientsReader(*this) && // this worker is responsible
1842  hasTransients() && // other workers may be interested
1843  !hasMemStore() && // rejected by the shared memory cache
1845  debugs(20, 7, "cannot be shared: " << *this);
1846  if (!shutting_down) // Store::Root() is FATALly missing during shutdown
1847  Store::Root().stopSharing(*this);
1848  }
1849 }
1850 
1851 void
1853 {
1855 }
1856 
1857 void
1859 {
1860  // Abandon our transient entry if neither shared memory nor disk wants it.
1861  assert(mem_obj);
1862  mem_obj->swapout.decision = decision;
1864 }
1865 
1866 void
1867 StoreEntry::trimMemory(const bool preserveSwappable)
1868 {
1869  /*
1870  * DPW 2007-05-09
1871  * Bug #1943. We must not let go any data for IN_MEMORY
1872  * objects. We have to wait until the mem_status changes.
1873  */
1874  if (mem_status == IN_MEMORY)
1875  return;
1876 
1878  return; // cannot trim because we do not load them again
1879 
1880  if (preserveSwappable)
1882  else
1884 
1885  debugs(88, 7, *this << " inmem_lo=" << mem_obj->inmem_lo);
1886 }
1887 
1888 bool
1889 StoreEntry::modifiedSince(const time_t ims, const int imslen) const
1890 {
1891  const time_t mod_time = lastModified();
1892 
1893  debugs(88, 3, "modifiedSince: '" << url() << "'");
1894 
1895  debugs(88, 3, "modifiedSince: mod_time = " << mod_time);
1896 
1897  if (mod_time < 0)
1898  return true;
1899 
1900  assert(imslen < 0); // TODO: Either remove imslen or support it properly.
1901 
1902  if (mod_time > ims) {
1903  debugs(88, 3, "--> YES: entry newer than client");
1904  return true;
1905  } else if (mod_time < ims) {
1906  debugs(88, 3, "--> NO: entry older than client");
1907  return false;
1908  } else {
1909  debugs(88, 3, "--> NO: same LMT");
1910  return false;
1911  }
1912 }
1913 
1914 bool
1916 {
1917  if (const auto reply = hasFreshestReply()) {
1918  etag = reply->header.getETag(Http::HdrType::ETAG);
1919  if (etag.str)
1920  return true;
1921  }
1922  return false;
1923 }
1924 
1925 bool
1927 {
1928  const String reqETags = request.header.getList(Http::HdrType::IF_MATCH);
1929  return hasOneOfEtags(reqETags, false);
1930 }
1931 
1932 bool
1934 {
1935  const String reqETags = request.header.getList(Http::HdrType::IF_NONE_MATCH);
1936  // weak comparison is allowed only for HEAD or full-body GET requests
1937  const bool allowWeakMatch = !request.flags.isRanged &&
1938  (request.method == Http::METHOD_GET || request.method == Http::METHOD_HEAD);
1939  return hasOneOfEtags(reqETags, allowWeakMatch);
1940 }
1941 
1943 bool
1944 StoreEntry::hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
1945 {
1946  const auto repETag = mem().freshestReply().header.getETag(Http::HdrType::ETAG);
1947  if (!repETag.str) {
1948  static SBuf asterisk("*", 1);
1949  return strListIsMember(&reqETags, asterisk, ',');
1950  }
1951 
1952  bool matched = false;
1953  const char *pos = NULL;
1954  const char *item;
1955  int ilen;
1956  while (!matched && strListGetItem(&reqETags, ',', &item, &ilen, &pos)) {
1957  if (!strncmp(item, "*", ilen))
1958  matched = true;
1959  else {
1960  String str;
1961  str.append(item, ilen);
1962  ETag reqETag;
1963  if (etagParseInit(&reqETag, str.termedBuf())) {
1964  matched = allowWeakMatch ? etagIsWeakEqual(repETag, reqETag) :
1965  etagIsStrongEqual(repETag, reqETag);
1966  }
1967  }
1968  }
1969  return matched;
1970 }
1971 
1972 Store::Disk &
1974 {
1975  assert(hasDisk());
1977  assert(sd);
1978  return *sd;
1979 }
1980 
1981 bool
1982 StoreEntry::hasDisk(const sdirno dirn, const sfileno filen) const
1983 {
1984  checkDisk();
1985  if (dirn < 0 && filen < 0)
1986  return swap_dirn >= 0;
1987  Must(dirn >= 0);
1988  const bool matchingDisk = (swap_dirn == dirn);
1989  return filen < 0 ? matchingDisk : (matchingDisk && swap_filen == filen);
1990 }
1991 
1992 void
1993 StoreEntry::attachToDisk(const sdirno dirn, const sfileno fno, const swap_status_t status)
1994 {
1995  debugs(88, 3, "attaching entry with key " << getMD5Text() << " : " <<
1996  swapStatusStr[status] << " " << dirn << " " <<
1997  std::hex << std::setw(8) << std::setfill('0') <<
1998  std::uppercase << fno);
1999  checkDisk();
2000  swap_dirn = dirn;
2001  swap_filen = fno;
2002  swap_status = status;
2003  checkDisk();
2004 }
2005 
2006 void
2008 {
2009  swap_dirn = -1;
2010  swap_filen = -1;
2012 }
2013 
2014 void
2016 {
2017  try {
2018  if (swap_dirn < 0) {
2019  Must(swap_filen < 0);
2021  } else {
2022  Must(swap_filen >= 0);
2024  if (swapoutFailed()) {
2026  } else {
2027  Must(swappingOut() || swappedOut());
2028  }
2029  }
2030  } catch (...) {
2031  debugs(88, DBG_IMPORTANT, "ERROR: inconsistent disk entry state " <<
2032  *this << "; problem: " << CurrentException);
2033  throw;
2034  }
2035 }
2036 
2037 /*
2038  * return true if the entry is in a state where
2039  * it can accept more data (ie with write() method)
2040  */
2041 bool
2043 {
2044  if (STORE_PENDING != store_status)
2045  return false;
2046 
2048  return false;
2049 
2050  return true;
2051 }
2052 
2053 const char *
2055 {
2056  LOCAL_ARRAY(char, buf, 256);
2057  snprintf(buf, 256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
2058  static_cast<int>(timestamp),
2059  static_cast<int>(lastref),
2060  static_cast<int>(lastModified_),
2061  static_cast<int>(expires));
2062  return buf;
2063 }
2064 
2065 void
2067 {
2068  if (required)
2070  else
2072 }
2073 
2074 static std::ostream &
2075 operator <<(std::ostream &os, const Store::IoStatus &io)
2076 {
2077  switch (io) {
2078  case Store::ioUndecided:
2079  os << 'u';
2080  break;
2081  case Store::ioReading:
2082  os << 'r';
2083  break;
2084  case Store::ioWriting:
2085  os << 'w';
2086  break;
2087  case Store::ioDone:
2088  os << 'o';
2089  break;
2090  }
2091  return os;
2092 }
2093 
2094 std::ostream &operator <<(std::ostream &os, const StoreEntry &e)
2095 {
2096  os << "e:";
2097 
2098  if (e.hasTransients()) {
2099  const auto &xitTable = e.mem_obj->xitTable;
2100  os << 't' << xitTable.io << xitTable.index;
2101  }
2102 
2103  if (e.hasMemStore()) {
2104  const auto &memCache = e.mem_obj->memCache;
2105  os << 'm' << memCache.io << memCache.index << '@' << memCache.offset;
2106  }
2107 
2108  // Do not use e.hasDisk() here because its checkDisk() call may calls us.
2109  if (e.swap_filen > -1 || e.swap_dirn > -1)
2110  os << 'd' << e.swap_filen << '@' << e.swap_dirn;
2111 
2112  os << '=';
2113 
2114  // print only non-default status values, using unique letters
2115  if (e.mem_status != NOT_IN_MEMORY ||
2116  e.store_status != STORE_PENDING ||
2117  e.swap_status != SWAPOUT_NONE ||
2118  e.ping_status != PING_NONE) {
2119  if (e.mem_status != NOT_IN_MEMORY) os << 'm';
2120  if (e.store_status != STORE_PENDING) os << 's';
2121  if (e.swap_status != SWAPOUT_NONE) os << 'w' << e.swap_status;
2122  if (e.ping_status != PING_NONE) os << 'p' << e.ping_status;
2123  }
2124 
2125  // print only set flags, using unique letters
2126  if (e.flags) {
2127  if (EBIT_TEST(e.flags, ENTRY_SPECIAL)) os << 'S';
2128  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_ALWAYS)) os << 'R';
2129  if (EBIT_TEST(e.flags, DELAY_SENDING)) os << 'P';
2130  if (EBIT_TEST(e.flags, RELEASE_REQUEST)) os << 'X';
2131  if (EBIT_TEST(e.flags, REFRESH_REQUEST)) os << 'F';
2132  if (EBIT_TEST(e.flags, ENTRY_REVALIDATE_STALE)) os << 'E';
2133  if (EBIT_TEST(e.flags, KEY_PRIVATE)) {
2134  os << 'I';
2135  if (e.shareableWhenPrivate)
2136  os << 'H';
2137  }
2138  if (EBIT_TEST(e.flags, ENTRY_FWD_HDR_WAIT)) os << 'W';
2139  if (EBIT_TEST(e.flags, ENTRY_NEGCACHED)) os << 'N';
2140  if (EBIT_TEST(e.flags, ENTRY_VALIDATED)) os << 'V';
2141  if (EBIT_TEST(e.flags, ENTRY_BAD_LENGTH)) os << 'L';
2142  if (EBIT_TEST(e.flags, ENTRY_ABORTED)) os << 'A';
2143  if (EBIT_TEST(e.flags, ENTRY_REQUIRES_COLLAPSING)) os << 'C';
2144  }
2145 
2146  return os << '/' << &e << '*' << e.locks();
2147 }
2148 
2149 void
2151 {
2153  entry_->releaseRequest(false);
2154  entry_->unlock(context_);
2155  });
2156 }
2157 
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:226
static int getKeyCounter(void)
Definition: store.cc:546
bool shareableWhenPrivate
Definition: Store.h:319
REMOVALPOLICYCREATE * create
Definition: store.cc:99
void storeReplAdd(const char *type, REMOVALPOLICYCREATE *create)
Definition: store.cc:1693
void detachFromDisk()
Definition: store.cc:2007
const HttpReply * hasFreshestReply() const
Definition: Store.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:182
bool updateOnNotModified(const StoreEntry &e304)
Definition: store.cc:1505
Io io
current I/O state
Definition: MemObject.h:174
bool readAheadPolicyCanRead() const
Definition: MemObject.cc:309
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:1719
RemovalPolicyNode repl
Definition: MemObject.h:200
Decision decision
current decision state
Definition: MemObject.h:157
bool modifiedSince(const time_t ims, const int imslen=-1) const
Definition: store.cc:1889
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:1915
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:199
#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:1191
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:166
bool etagIsStrongEqual(const ETag &tag1, const ETag &tag2)
whether etags are strong-equal
Definition: ETag.cc:49
Definition: ETag.h:17
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
void updateReply(const HttpReply &r)
(re)sets updated reply;
Definition: MemObject.h:85
bool timestampsSet()
Definition: store.cc:1440
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:1982
int locks() const
returns a local concurrent use counter, for debugging
Definition: Store.h:260
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:235
int64_t objectLen() const
Definition: Store.h:248
String getList(Http::HdrType id) const
Definition: HttpHeader.cc:831
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:1296
static DeferredRead::DeferrableRead DeferReader
Definition: Store.h:45
void attachToDisk(const sdirno, const sfileno, const swap_status_t)
Definition: store.cc:1993
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:1649
int aborted_requests
Definition: StatCounters.h:152
void expireNow()
Definition: store.cc:797
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:1637
void setUris(char const *aStoreId, char const *aLogUri, const HttpRequestMethod &aMethod)
Definition: MemObject.cc:77
int locked() const
Definition: Store.h:136
Definition: Range.h:18
Io io
current I/O state
Definition: MemObject.h:185
int validToSend() const
Definition: store.cc:1400
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:201
virtual void flush()
Definition: store.cc:1660
STABH * callback
Definition: MemObject.h:197
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
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:528
bool isAccepting() const
Definition: store.cc:2042
struct SquidConfig::@110 Store
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:224
#define DBG_CRITICAL
Definition: Debug.h:45
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:893
int fdNFree(void)
Definition: fd.cc:295
int storeTooManyDiskFilesOpen(void)
Definition: store.cc:917
time_t expires
Definition: Store.h:214
void forcePublicKey(const cache_key *newkey)
Definition: store.cc:650
struct timeval current_time
Definition: stub_time.cc:15
const HttpReply & baseReply() const
Definition: MemObject.h:60
void replaceBaseReply(const HttpReplyPointer &r)
Definition: MemObject.cc:143
void memOutDecision(const bool willCacheInRam)
Definition: store.cc:1852
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:187
XitTable xitTable
current [shared] memory caching state for the entry
Definition: MemObject.h:176
void trimUnSwappable()
Definition: MemObject.cc:411
void append(char const *buf, int len)
Definition: String.cc:161
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:609
void doAbandon(const char *context)
Definition: store.cc:480
time_t squid_curtime
Definition: stub_time.cc:17
time_t timestamp
Definition: Store.h:212
void storeInit(void)
Definition: store.cc:1305
void updateLimits()
slowly calculate (and cache) hi/lo watermarks and similar limits
Definition: Controller.cc:198
bool appliedUpdates
Definition: MemObject.h:90
#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:1063
int RESERVED_FD
void onException() noexcept
Definition: store.cc:2150
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:124
void hashDelete()
Definition: store.cc:427
void storeSwapFileNumberSet(StoreEntry *e, sfileno filn)
uint64_t swap_file_sz
Definition: Store.h:218
int shutting_down
const char * xstrerr(int error)
Definition: xstrerror.cc:83
ping_status_t ping_status
Definition: Store.h:230
void const char HLPCB void * data
Definition: stub_helper.cc:16
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:1338
int64_t object_sz
Definition: MemObject.h:202
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
MemObject & mem()
Definition: Store.h:52
#define cbdataReference(var)
Definition: cbdata.h:341
HttpRequestMethod method
Definition: MemObject.h:138
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:168
const char * url() const
Definition: store.cc:1614
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:783
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
Pointer recreateOnNotModified(const HttpReply &reply304) const
Definition: HttpReply.cc:263
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:1109
tlv * storeSwapMetaBuild(const StoreEntry *e)
bool checkCachable()
Definition: store.cc:957
HASHCMP storeKeyHashCmp
void unlockAndReset(const char *resetContext=nullptr)
Definition: Store.h:368
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:228
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:67
bool setPublicKey(const KeyScope keyScope=ksDefault)
Definition: store.cc:593
void abandon(const char *context)
Definition: Store.h:275
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:220
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
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1774
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:204
signed_int32_t sfileno
Definition: forward.h:22
MemObject * mem_obj
Definition: Store.h:209
time_t date
Definition: HttpReply.h:44
void markEndOfReplyHeaders()
sets baseReply().hdr_sz (i.e. written reply headers size) to endOffset()
Definition: MemObject.cc:241
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:151
const cache_key * storeKeyPrivate()
friend std::ostream & operator<<(std::ostream &os, const StoreEntry &e)
Definition: store.cc:2094
#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
struct _store_check_cachable_hist::@145 yes
uint16_t refcount
Definition: Store.h:219
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:157
void lengthWentBad(const char *reason)
flags [truncated or too big] entry with ENTRY_BAD_LENGTH and releases it
Definition: store.cc:1055
void Maintain(void *unused)
Definition: store.cc:1177
virtual void created(StoreEntry *)=0
static OBJH storeCheckCachableStats
Definition: store.cc:108
time_t negativeTtl
Definition: SquidConfig.h:96
struct SquidConfig::@112 onoff
bool swappedOut() const
whether the entire entry is now on disk (possibly marked for deletion)
Definition: Store.h:126
void storeGetMemSpace(int size)
Definition: store.cc:1163
AsyncCall::Pointer deferredProducer
producer callback registered with deferProducer
Definition: Store.h:323
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:110
void setCollapsingRequirement(const bool required)
allow or forbid collapsed requests feeding
Definition: store.cc:2066
signed int sdirno
Definition: forward.h:23
unsigned short lock_count
Definition: Store.h:312
HttpHeader header
Definition: Message.h:75
SwapOut swapout
Definition: MemObject.h:160
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:208
static std::stack< StoreEntry * > LateReleaseStack
Definition: store.cc:114
void dump(int debug_lvl) const
Definition: store.cc:1547
void storeFreeMemory(void)
Definition: store.cc:1381
void memoryDisconnect(StoreEntry &)
disassociates the entry from the memory cache, preserving cached data
Definition: Controller.cc:584
const char * getSerialisedMetaData(size_t &length) const
Definition: store.cc:1821
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:1684
Store::Disk & disk() const
the disk this entry is [being] cached on; asserts for entries w/o a disk
Definition: store.cc:1973
RequestFlags flags
Definition: HttpRequest.h:141
#define EBIT_SET(flag, bit)
Definition: defines.h:105
store_status_t store_status
Definition: Store.h:232
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:1933
void swapOutDecision(const MemObject::SwapOut::Decision &decision)
Definition: store.cc:1858
int checkNegativeHit() const
Definition: store.cc:1346
void swapOutFileClose(int how)
void putStr(Http::HdrType id, const char *str)
Definition: HttpHeader.cc:1041
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:171
void storeDigestInit(void)
bool cacheNegatively()
Definition: store.cc:166
void write(StoreIOBuffer)
Definition: store.cc:804
#define PROF_start(probename)
Definition: Profiler.h:62
void addWriting(StoreEntry *, const cache_key *)
Definition: Controller.cc:738
void FreeMemory()
undo Init()
Definition: Controller.cc:906
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:1325
bool swapoutFailed() const
whether we failed to write this entry to disk
Definition: Store.h:128
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:264
bool checkTooBig() const
Definition: store.cc:946
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:422
int store_open_disk_fd
void storeConfigure(void)
Definition: store.cc:1319
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:765
C * getRaw() const
Definition: RefCount.h:80
void reset()
Definition: MemObject.cc:285
char * buf
Definition: CommRead.h:26
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:108
static Pointer Create(const CommandPointer &cmd)
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:147
int cbdataReferenceValid(const void *p)
Definition: cbdata.cc:412
swap_status_t swap_status
Definition: Store.h:234
Decision
Decision states for StoreEntry::swapoutPossible() and related code.
Definition: MemObject.h:156
const HttpReply & freshestReply() const
Definition: MemObject.h:68
const char * str
quoted-string
Definition: ETag.h:20
void registerAbort(STABH *cb, void *)
Definition: store.cc:1528
#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:1757
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)
time_t lastModified_
received Last-Modified value or -1; use lastModified()
Definition: Store.h:216
#define PROF_stop(probename)
Definition: Profiler.h:63
void startWriting()
Definition: store.cc:1790
failure: caller left before swapping out everything
Definition: StoreIOState.h:71
bool hasOneOfEtags(const String &reqETags, const bool allowWeakMatch) const
whether at least one of the request ETags matches entity ETag
Definition: store.cc:1944
void unregisterAbort()
Definition: store.cc:1537
time_t lastref
Definition: Store.h:213
enum _mem_status_t mem_status_t
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:534
struct _store_check_cachable_hist::@144 no
mem_hdr data_hdr
Definition: MemObject.h:139
void storeKeyInit(void)
int expiresMoreThan(time_t expires, time_t when)
Definition: store.cc:1391
bool hasIfMatchEtag(const HttpRequest &request) const
has ETag matching at least one of the If-Match etags
Definition: store.cc:1926
void trimSwappable()
Definition: MemObject.cc:386
void reset()
Definition: store.cc:1669
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:1839
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
const char * storeEntryFlags(const StoreEntry *entry)
Definition: stat.cc:276
bool validLength() const
Definition: store.cc:1253
const char * describeTimestamps() const
Definition: store.cc:2054
const HttpReplyPointer & updatedReply() const
Definition: MemObject.h:64
void negativeCache()
Definition: store.cc:1367
HttpRequestPointer request
Definition: MemObject.h:189
#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:2015
A StoreEntry::getPublic*() caller.
Definition: StoreClient.h:23
int size
Definition: ModDevPoll.cc:77
void trimMemory(const bool preserveSwappable)
Definition: store.cc:1867
size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:229
int64_t inmem_lo
Definition: MemObject.h:140
#define false
Definition: GnuRegex.c:233
static EVH storeLateRelease
Definition: store.cc:109
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:1572
void lock(const char *context)
Definition: store.cc:439
void createMemObject()
Definition: store.cc:1623

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors