]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
When searching for a hit, ask each cache_dir after checking in store_table.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 30 Jan 2011 02:21:30 +0000 (19:21 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 30 Jan 2011 02:21:30 +0000 (19:21 -0700)
This allows SMP cache_dirs to share their contents without constantly worrying
about keeping the worker-specific store_table in sync among workers.

src/SwapDir.cc
src/fs/rock/RockSwapDir.h
src/store_dir.cc

index f91db78408f09cbf50c4486215da3636bb80d23f..95fc5736f3bfdee3539ac528ea6d1488fd9b658c 100644 (file)
@@ -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
index a70d21f2ee10c2c2ac02ac6448b606e21121568e..67c5ffaf8ed463e5a5b6305a0b02c588be26d334 100644 (file)
@@ -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 */
index a7c90008fbe157bfe249e15991219e68f5eec170..a197807bdd4913731fcc583de175505b2a3f78a9 100644 (file)
@@ -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<SwapDir*>(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