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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors