From: Alex Rousskov Date: Sun, 30 Jan 2011 02:21:30 +0000 (-0700) Subject: When searching for a hit, ask each cache_dir after checking in store_table. X-Git-Tag: take01~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44def0f9e97f2ea527cdedb371abfc6d2b16edde;p=thirdparty%2Fsquid.git When searching for a hit, ask each cache_dir after checking in store_table. This allows SMP cache_dirs to share their contents without constantly worrying about keeping the worker-specific store_table in sync among workers. --- diff --git a/src/SwapDir.cc b/src/SwapDir.cc index f91db78408..95fc5736f3 100644 --- a/src/SwapDir.cc +++ b/src/SwapDir.cc @@ -279,13 +279,11 @@ SwapDir::optionObjectSizeDump(StoreEntry * e) const storeAppendPrintf(e, " max-size=%"PRId64, max_objsize); } -/* Swapdirs do not have an index of their own - thus they ask their parent.. - * but the parent child relationship isn't implemented yet - */ +// some SwapDirs may maintain their indexes and be able to lookup an entry key StoreEntry * SwapDir::get(const cache_key *key) { - return Store::Root().get(key); + return NULL; } void diff --git a/src/fs/rock/RockSwapDir.h b/src/fs/rock/RockSwapDir.h index a70d21f2ee..67c5ffaf8e 100644 --- a/src/fs/rock/RockSwapDir.h +++ b/src/fs/rock/RockSwapDir.h @@ -24,6 +24,7 @@ public: /* public ::SwapDir API */ virtual void reconfigure(int, char *); virtual StoreSearch *search(String const url, HttpRequest *); + virtual StoreEntry *get(const cache_key *key); protected: /* protected ::SwapDir API */ diff --git a/src/store_dir.cc b/src/store_dir.cc index a7c90008fb..a197807bdd 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -691,8 +691,33 @@ StoreController::dereference(StoreEntry & e) StoreEntry * StoreController::get(const cache_key *key) { + if (StoreEntry *e = swapDir->get(key)) { + debugs(20, 1, HERE << "got in-transit entry: " << *e); + return e; + } + + if (const int cacheDirs = Config.cacheSwap.n_configured) { + // ask each cache_dir until the entry is found; use static starting + // point to avoid asking the same subset of disks more often + // TODO: coordinate with put() to be able to guess the right disk often + static int idx = 0; + + for (int n = 0; n < cacheDirs; ++n) { + if (idx >= cacheDirs) + idx = 0; + + SwapDir *sd = dynamic_cast(INDEXSD(idx)); + if (StoreEntry *e = sd->get(key)) { + debugs(20, 1, HERE << "cache_dir " << idx << + " got cached entry: " << *e); + return e; + } + } + } - return swapDir->get(key); + debugs(20, 1, HERE << "none of " << Config.cacheSwap.n_configured << + " cache_dirs have " << storeKeyText(key)); + return NULL; } void