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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors