]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/store_rebuild.cc
Removed squid-old.h
[thirdparty/squid.git] / src / store_rebuild.cc
index 0ae8ef17805a68ff4c1c1bce7327091a3af45d5f..e6cf618a81578dd05b3f4c4b9effd3ccdf9500a0 100644 (file)
 
 #include "squid.h"
 #include "event.h"
+#include "globals.h"
+#include "md5.h"
+#include "protos.h"
+#include "StatCounters.h"
 #include "Store.h"
 #include "SwapDir.h"
 #include "StoreSearch.h"
@@ -73,6 +77,7 @@ storeCleanup(void *datanotused)
 
     size_t statCount = 500;
 
+    // TODO: Avoid the loop (and ENTRY_VALIDATED) unless opt_store_doublecheck.
     while (statCount-- && !currentSearch->isDone() && currentSearch->next()) {
         StoreEntry *e;
 
@@ -90,7 +95,7 @@ storeCleanup(void *datanotused)
 
         if (opt_store_doublecheck)
             if (storeCleanupDoubleCheck(e))
-                store_errors++;
+                ++store_errors;
 
         EBIT_SET(e->flags, ENTRY_VALIDATED);
 
@@ -99,24 +104,24 @@ storeCleanup(void *datanotused)
          * otherwise, set it in the validation procedure
          */
 
-
-        if (e->swap_status == SWAPOUT_DONE)
-            e->store()->updateSize(e->swap_file_sz, 1);
-
         if ((++validated & 0x3FFFF) == 0)
             /* TODO format the int with with a stream operator */
-            debugs(20, 1, "  " << validated << " Entries Validated so far.");
+            debugs(20, DBG_IMPORTANT, "  " << validated << " Entries Validated so far.");
     }
 
     if (currentSearch->isDone()) {
-        debugs(20, 1, "  Completed Validation Procedure");
-        debugs(20, 1, "  Validated " << validated << " Entries");
-        debugs(20, 1, "  store_swap_size = " << store_swap_size);
-        StoreController::store_dirs_rebuilding--;
+        debugs(20, DBG_IMPORTANT, "  Completed Validation Procedure");
+        debugs(20, DBG_IMPORTANT, "  Validated " << validated << " Entries");
+        debugs(20, DBG_IMPORTANT, "  store_swap_size = " << Store::Root().currentSize() / 1024.0 << " KB");
+        --StoreController::store_dirs_rebuilding;
         assert(0 == StoreController::store_dirs_rebuilding);
 
-        if (opt_store_doublecheck)
-            assert(store_errors == 0);
+        if (opt_store_doublecheck && store_errors) {
+            fatalf("Quitting after finding %d cache index inconsistencies. " \
+                   "Removing cache index will force its slow rebuild. " \
+                   "Removing -S will let Squid start with an inconsistent " \
+                   "cache index (at your own risk).\n", store_errors);
+        }
 
         if (store_digest)
             storeDigestNoteStoreReady();
@@ -153,18 +158,18 @@ storeRebuildComplete(struct _store_rebuild_data *dc)
 
     dt = tvSubDsec(rebuild_start, current_time);
 
-    debugs(20, 1, "Finished rebuilding storage from disk.");
-    debugs(20, 1, "  " << std::setw(7) << counts.scancount  << " Entries scanned");
-    debugs(20, 1, "  " << std::setw(7) << counts.invalid  << " Invalid entries.");
-    debugs(20, 1, "  " << std::setw(7) << counts.badflags  << " With invalid flags.");
-    debugs(20, 1, "  " << std::setw(7) << counts.objcount  << " Objects loaded.");
-    debugs(20, 1, "  " << std::setw(7) << counts.expcount  << " Objects expired.");
-    debugs(20, 1, "  " << std::setw(7) << counts.cancelcount  << " Objects cancelled.");
-    debugs(20, 1, "  " << std::setw(7) << counts.dupcount  << " Duplicate URLs purged.");
-    debugs(20, 1, "  " << std::setw(7) << counts.clashcount  << " Swapfile clashes avoided.");
-    debugs(20, 1, "  Took "<< std::setw(3)<< std::setprecision(2) << dt << " seconds ("<< std::setw(6) <<
+    debugs(20, DBG_IMPORTANT, "Finished rebuilding storage from disk.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.scancount  << " Entries scanned");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.invalid  << " Invalid entries.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.badflags  << " With invalid flags.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.objcount  << " Objects loaded.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.expcount  << " Objects expired.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.cancelcount  << " Objects cancelled.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.dupcount  << " Duplicate URLs purged.");
+    debugs(20, DBG_IMPORTANT, "  " << std::setw(7) << counts.clashcount  << " Swapfile clashes avoided.");
+    debugs(20, DBG_IMPORTANT, "  Took "<< std::setw(3)<< std::setprecision(2) << dt << " seconds ("<< std::setw(6) <<
            ((double) counts.objcount / (dt > 0.0 ? dt : 1.0)) << " objects/sec).");
-    debugs(20, 1, "Beginning Validation Procedure");
+    debugs(20, DBG_IMPORTANT, "Beginning Validation Procedure");
 
     eventAdd("storeCleanup", storeCleanup, NULL, 0.0, 1);
 
@@ -225,12 +230,12 @@ storeRebuildProgress(int sd_index, int total, int sofar)
     if (squid_curtime - last_report < 15)
         return;
 
-    for (sd_index = 0; sd_index < Config.cacheSwap.n_configured; sd_index++) {
+    for (sd_index = 0; sd_index < Config.cacheSwap.n_configured; ++sd_index) {
         n += (double) RebuildProgress[sd_index].scanned;
         d += (double) RebuildProgress[sd_index].total;
     }
 
-    debugs(20, 1, "Store rebuilding is "<< std::setw(4)<< std::setprecision(2) << 100.0 * n / d << "% complete");
+    debugs(20, DBG_IMPORTANT, "Store rebuilding is "<< std::setw(4)<< std::setprecision(2) << 100.0 * n / d << "% complete");
     last_report = squid_curtime;
 }
 
@@ -257,8 +262,8 @@ struct InitStoreEntry : public unary_function<StoreMeta, void> {
                 time_t expires;
                 time_t lastmod;
                 size_t swap_file_sz;
-                u_short refcount;
-                u_short flags;
+                uint16_t refcount;
+                uint16_t flags;
             } *tmp;
             tmp = (struct old_metahdr *)x.value;
             assert(x.length == STORE_HDR_METASIZE_OLD);
@@ -295,11 +300,11 @@ storeRebuildLoadEntry(int fd, int diskIndex, MemBuf &buf,
     assert(buf.hasSpace()); // caller must allocate
 
     const int len = FD_READ_METHOD(fd, buf.space(), buf.spaceSize());
-    statCounter.syscalls.disk.reads++;
+    ++ statCounter.syscalls.disk.reads;
     if (len < 0) {
         const int xerrno = errno;
-        debugs(47, 1, "cache_dir[" << diskIndex << "]: " <<
-            "failed to read swap entry meta data: " << xstrerr(xerrno));
+        debugs(47, DBG_IMPORTANT, "WARNING: cache_dir[" << diskIndex << "]: " <<
+               "Ignoring cached entry after meta data read failure: " << xstrerr(xerrno));
         return false;
     }
 
@@ -320,13 +325,14 @@ storeRebuildParseEntry(MemBuf &buf, StoreEntry &tmpe, cache_key *key,
     }
 
     if (!aBuilder.isBufferSane()) {
-        debugs(47,1, "Warning: Ignoring malformed cache entry.");
+        debugs(47, DBG_IMPORTANT, "WARNING: Ignoring malformed cache entry.");
         return false;
     }
 
     StoreMeta *tlv_list = aBuilder.createStoreMeta();
     if (!tlv_list) {
-        debugs(47, 1, HERE << "failed to get swap entry meta data list");
+        debugs(47, DBG_IMPORTANT, "WARNING: Ignoring cache entry with invalid " <<
+               "meta data");
         return false;
     }
 
@@ -341,7 +347,7 @@ storeRebuildParseEntry(MemBuf &buf, StoreEntry &tmpe, cache_key *key,
     tlv_list = NULL;
 
     if (storeKeyNull(key)) {
-        debugs(47,1, HERE << "NULL swap entry key");
+        debugs(47, DBG_IMPORTANT, "WARNING: Ignoring keyless cache entry");
         return false;
     }
 
@@ -354,18 +360,18 @@ storeRebuildParseEntry(MemBuf &buf, StoreEntry &tmpe, cache_key *key,
         } else if (tmpe.swap_file_sz == (uint64_t)(expectedSize - swap_hdr_len)) {
             tmpe.swap_file_sz = expectedSize;
         } else if (tmpe.swap_file_sz != expectedSize) {
-            debugs(47, 1, HERE << "swap entry SIZE MISMATCH " <<
-                   tmpe.swap_file_sz << "!=" << expectedSize);
+            debugs(47, DBG_IMPORTANT, "WARNING: Ignoring cache entry due to a " <<
+                   "SIZE MISMATCH " << tmpe.swap_file_sz << "!=" << expectedSize);
             return false;
         }
-    } else
-    if (tmpe.swap_file_sz <= 0) {
-        debugs(47, 1, HERE << "missing swap entry size: " << tmpe);
+    } else if (tmpe.swap_file_sz <= 0) {
+        debugs(47, DBG_IMPORTANT, "WARNING: Ignoring cache entry with " <<
+               "unknown size: " << tmpe);
         return false;
     }
 
     if (EBIT_TEST(tmpe.flags, KEY_PRIVATE)) {
-        counts.badflags++;
+        ++ counts.badflags;
         return false;
     }
 
@@ -399,7 +405,7 @@ storeRebuildKeepEntry(const StoreEntry &tmpe, const cache_key *key,
         if (e->lastref >= tmpe.lastref) {
             /* key already exists, old entry is newer */
             /* keep old, ignore new */
-            counts.dupcount++;
+            ++counts.dupcount;
 
             // For some stores, get() creates/unpacks a store entry. Signal
             // such stores that we will no longer use the get() result:
@@ -411,7 +417,7 @@ storeRebuildKeepEntry(const StoreEntry &tmpe, const cache_key *key,
             /* URL already exists, this swapfile not being used */
             /* junk old, load new */
             e->release();      /* release old entry */
-            counts.dupcount++;
+            ++counts.dupcount;
         }
     }