]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/store_dir.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / store_dir.cc
index a7449e873e69884d40170b360fff35659a8b5a50..b89b3e0dfb29a3454ddaca75f41c7b3a3cb02fca 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir.cc,v 1.156 2006/08/21 00:50:41 robertc Exp $
+ * $Id$
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 static STDIRSELECT storeDirSelectSwapDirRoundRobin;
 static STDIRSELECT storeDirSelectSwapDirLeastLoad;
 
-int StoreController::store_dirs_rebuilding = 0;
+/*
+ * store_dirs_rebuilding is initialized to _1_ as a hack so that
+ * storeDirWriteCleanLogs() doesn't try to do anything unless _all_
+ * cache_dirs have been read.  For example, without this hack, Squid
+ * will try to write clean log files if -kparse fails (becasue it
+ * calls fatal()).
+ */
+int StoreController::store_dirs_rebuilding = 1;
 
 StoreController::StoreController() : swapDir (new StoreHashIndex())
 {}
@@ -82,10 +89,10 @@ StoreController::init()
 
     if (0 == strcasecmp(Config.store_dir_select_algorithm, "round-robin")) {
         storeDirSelectSwapDir = storeDirSelectSwapDirRoundRobin;
-        debug(47, 1) ("Using Round Robin store dir selection\n");
+        debugs(47, 1, "Using Round Robin store dir selection");
     } else {
         storeDirSelectSwapDir = storeDirSelectSwapDirLeastLoad;
-        debug(47, 1) ("Using Least Load store dir selection\n");
+        debugs(47, 1, "Using Least Load store dir selection");
     }
 }
 
@@ -146,7 +153,7 @@ StoreController::create()
  * ie any-sized-object swapdirs. This is a good thing.
  */
 bool
-SwapDir::objectSizeIsAcceptable(ssize_t objsize) const
+SwapDir::objectSizeIsAcceptable(int64_t objsize) const
 {
     /*
      * If the swapdir's max_obj_size is -1, then it definitely can
@@ -181,7 +188,6 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
     int i;
     int load;
     RefCount<SwapDir> sd;
-    ssize_t objsize = (ssize_t) objectLen(e);
 
     for (i = 0; i <= Config.cacheSwap.n_configured; i++) {
         if (++dirn >= Config.cacheSwap.n_configured)
@@ -195,7 +201,7 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
         if (sd->cur_size > sd->max_size)
             continue;
 
-        if (!sd->objectSizeIsAcceptable(objsize))
+        if (!sd->objectSizeIsAcceptable(e->objectLen()))
             continue;
 
         /* check for error or overload condition */
@@ -216,7 +222,7 @@ storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
  *
  * Note: We should modify this later on to prefer sticking objects
  * in the *tightest fit* swapdir to conserve space, along with the
- * actual swapdir usage. But for now, this hack will do while  
+ * actual swapdir usage. But for now, this hack will do while
  * testing, so you should order your swapdirs in the config file
  * from smallest maxobjsize to unlimited (-1) maxobjsize.
  *
@@ -237,7 +243,7 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
     RefCount<SwapDir> SD;
 
     /* Calculate the object size */
-    objsize = (ssize_t) objectLen(e);
+    objsize = e->objectLen();
 
     if (objsize != -1)
         objsize += e->mem_obj->swap_hdr_sz;
@@ -314,23 +320,23 @@ storeDirSwapLog(const StoreEntry * e, int op)
 
     assert(op > SWAP_LOG_NOP && op < SWAP_LOG_MAX);
 
-    debug(20, 3) ("storeDirSwapLog: %s %s %d %08X\n",
-                  swap_log_op_str[op],
-                  e->getMD5Text(),
-                  e->swap_dirn,
-                  e->swap_filen);
+    debugs(20, 3, "storeDirSwapLog: " <<
+           swap_log_op_str[op] << " " <<
+           e->getMD5Text() << " " <<
+           e->swap_dirn << " " <<
+           std::hex << std::uppercase << std::setfill('0') << std::setw(8) << e->swap_filen);
 
     dynamic_cast<SwapDir *>(INDEXSD(e->swap_dirn))->logEntry(*e, op);
 }
 
 void
-StoreController::updateSize(size_t size, int sign)
+StoreController::updateSize(int64_t size, int sign)
 {
     fatal("StoreController has no independent size\n");
 }
 
 void
-SwapDir::updateSize(size_t size, int sign)
+SwapDir::updateSize(int64_t size, int sign)
 {
     int blks = (size + fs.blksize - 1) / fs.blksize;
     int k = (blks * fs.blksize >> 10) * sign;
@@ -404,7 +410,7 @@ storeDirCloseSwapLogs(void)
 
 /*
  *  storeDirWriteCleanLogs
- * 
+ *
  *  Writes a "clean" swap log file from in-memory metadata.
  *  This is a rewrite of the original function to troll each
  *  StoreDir and write the logs, and flush at the end of
@@ -424,12 +430,12 @@ storeDirWriteCleanLogs(int reopen)
     int notdone = 1;
 
     if (StoreController::store_dirs_rebuilding) {
-        debug(20, 1) ("Not currently OK to rewrite swap log.\n");
-        debug(20, 1) ("storeDirWriteCleanLogs: Operation aborted.\n");
+        debugs(20, 1, "Not currently OK to rewrite swap log.");
+        debugs(20, 1, "storeDirWriteCleanLogs: Operation aborted.");
         return 0;
     }
 
-    debug(20, 1) ("storeDirWriteCleanLogs: Starting...\n");
+    debugs(20, 1, "storeDirWriteCleanLogs: Starting...");
     getCurrentTime();
     start = current_time;
 
@@ -437,7 +443,7 @@ storeDirWriteCleanLogs(int reopen)
         sd = dynamic_cast<SwapDir *>(INDEXSD(dirn));
 
         if (sd->writeCleanStart() < 0) {
-            debug(20, 1) ("log.clean.start() failed for dir #%d\n", sd->index);
+            debugs(20, 1, "log.clean.start() failed for dir #" << sd->index);
             continue;
         }
     }
@@ -470,7 +476,8 @@ storeDirWriteCleanLogs(int reopen)
 
             if ((++n & 0xFFFF) == 0) {
                 getCurrentTime();
-                debug(20, 1) ("  %7d entries written so far.\n", n);
+                debugs(20, 1, "  " << std::setw(7) << n  <<
+                       " entries written so far.");
             }
         }
     }
@@ -486,10 +493,10 @@ storeDirWriteCleanLogs(int reopen)
 
     dt = tvSubDsec(start, current_time);
 
-    debug(20, 1) ("  Finished.  Wrote %d entries.\n", n);
+    debugs(20, 1, "  Finished.  Wrote " << n << " entries.");
+    debugs(20, 1, "  Took "<< std::setw(3)<< std::setprecision(2) << dt <<
+           " seconds ("<< std::setw(6) << ((double) n / (dt > 0.0 ? dt : 1.0)) << " entries/sec).");
 
-    debug(20, 1) ("  Took %3.1f seconds (%6.1f entries/sec).\n",
-                  dt, (double) n / (dt > 0.0 ? dt : 1.0));
 
     return n;
 }
@@ -515,7 +522,7 @@ StoreController::sync(void)
 }
 
 /*
- * handle callbacks all avaliable fs'es 
+ * handle callbacks all avaliable fs'es
  */
 int
 StoreController::callback()
@@ -539,7 +546,7 @@ storeDirGetBlkSize(const char *path, int *blksize)
     struct statvfs sfs;
 
     if (statvfs(path, &sfs)) {
-        debug(50, 1) ("%s: %s\n", path, xstrerror());
+        debugs(50, 1, "" << path << ": " << xstrerror());
         *blksize = 2048;
         return 1;
     }
@@ -550,7 +557,7 @@ storeDirGetBlkSize(const char *path, int *blksize)
     struct statfs sfs;
 
     if (statfs(path, &sfs)) {
-        debug(50, 1) ("%s: %s\n", path, xstrerror());
+        debugs(50, 1, "" << path << ": " << xstrerror());
         *blksize = 2048;
         return 1;
     }
@@ -578,7 +585,7 @@ storeDirGetUFSStats(const char *path, int *totl_kb, int *free_kb, int *totl_in,
     struct statvfs sfs;
 
     if (statvfs(path, &sfs)) {
-        debug(50, 1) ("%s: %s\n", path, xstrerror());
+        debugs(50, 1, "" << path << ": " << xstrerror());
         return 1;
     }
 
@@ -591,7 +598,7 @@ storeDirGetUFSStats(const char *path, int *totl_kb, int *free_kb, int *totl_in,
     struct statfs sfs;
 
     if (statfs(path, &sfs)) {
-        debug(50, 1) ("%s: %s\n", path, xstrerror());
+        debugs(50, 1, "" << path << ": " << xstrerror());
         return 1;
     }
 
@@ -605,7 +612,7 @@ storeDirGetUFSStats(const char *path, int *totl_kb, int *free_kb, int *totl_in,
 }
 
 void
-allocate_new_swapdir(_SquidConfig::_cacheSwap * swap)
+allocate_new_swapdir(SquidConfig::_cacheSwap * swap)
 {
     if (swap->swapDirs == NULL) {
         swap->n_allocated = 4;
@@ -623,7 +630,7 @@ allocate_new_swapdir(_SquidConfig::_cacheSwap * swap)
 }
 
 void
-free_cachedir(_SquidConfig::_cacheSwap * swap)
+free_cachedir(SquidConfig::_cacheSwap * swap)
 {
     int i;
     /* DON'T FREE THESE FOR RECONFIGURE */
@@ -634,7 +641,7 @@ free_cachedir(_SquidConfig::_cacheSwap * swap)
     for (i = 0; i < swap->n_configured; i++) {
         /* TODO XXX this lets the swapdir free resources asynchronously
         * swap->swapDirs[i]->deactivate();
-        * but there may be such a means already. 
+        * but there may be such a means already.
         * RBC 20041225
         */
         swap->swapDirs[i] = NULL;
@@ -683,7 +690,7 @@ StoreController::dereference(StoreEntry & e)
 StoreEntry *
 
 StoreController::get
-    (const cache_key *key)
+(const cache_key *key)
 {
 
     return swapDir->get
@@ -693,13 +700,15 @@ StoreController::get
 void
 
 StoreController::get
-    (String const key, STOREGETCLIENT callback, void *cbdata)
+(String const key, STOREGETCLIENT callback, void *cbdata)
 {
     fatal("not implemented");
 }
 
 StoreHashIndex::StoreHashIndex()
 {
+    if (store_table)
+        abort();
     assert (store_table == NULL);
 }
 
@@ -756,10 +765,10 @@ StoreHashIndex::create()
 StoreEntry *
 
 StoreHashIndex::get
-    (const cache_key *key)
+(const cache_key *key)
 {
     PROF_start(storeGet);
-    debug(20, 3) ("storeGet: looking up %s\n", storeKeyText(key));
+    debugs(20, 3, "storeGet: looking up " << storeKeyText(key));
     StoreEntry *p = static_cast<StoreEntry *>(hash_lookup(store_table, key));
     PROF_stop(storeGet);
     return p;
@@ -768,7 +777,7 @@ StoreHashIndex::get
 void
 
 StoreHashIndex::get
-    (String const key, STOREGETCLIENT callback, void *cbdata)
+(String const key, STOREGETCLIENT callback, void *cbdata)
 {
     fatal("not implemented");
 }
@@ -800,7 +809,7 @@ StoreHashIndex::init()
          * driven by the StoreHashIndex, not by each store.
         *
         * That is, the HashIndex should perform a search of each dir it is
-        * indexing to do the hash insertions. The search is then able to 
+        * indexing to do the hash insertions. The search is then able to
         * decide 'from-memory', or 'from-clean-log' or 'from-dirty-log' or
         * 'from-no-log'.
         *
@@ -873,7 +882,7 @@ StoreHashIndex::maintain()
 }
 
 void
-StoreHashIndex::updateSize(size_t, int)
+StoreHashIndex::updateSize(int64_t, int)
 {}
 
 void