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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors