/*
- * $Id: store.cc,v 1.215 1997/03/29 04:45:22 wessels Exp $
+ * $Id: store.cc,v 1.216 1997/04/02 04:39:59 wessels Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
} swapout_ctrl_t;
/* initializtion flag */
-int store_rebuilding = STORE_REBUILDING_SLOW;
+int store_rebuilding = STORE_REBUILDING_DIRTY;
/* Static Functions */
static const char *storeDescribeStatus _PARAMS((const StoreEntry *));
static int scan_revolutions;
static struct _bucketOrder *MaintBucketsOrder = NULL;
-/* Slow/Fast rebuild status parameter */
+/* Dirty/Clean rebuild status parameter */
static int store_validating = 1;
static MemObject *
e->expires = expires;
e->lastmod = lastmod;
e->ping_status = PING_NONE;
- BIT_RESET(e->flag, ENTRY_VALIDATED);
+ if (store_rebuilding == STORE_REBUILDING_CLEAN)
+ BIT_SET(e->flag, ENTRY_VALIDATED);
+ else
+ BIT_RESET(e->flag, ENTRY_VALIDATED);
return e;
}
rebuildData->dupcount++;
}
/* Is the swap file number already taken? */
- if (file_map_bit_test(sfileno)) {
+ if (storeDirMapBitTest(sfileno)) {
/* Yes it is, we can't use this swapfile */
debug(20, 2, "storeRebuildFromDisk: Line %d Active clash: file #%d\n",
rebuildData->linecount,
validnum++;
if ((validnum % 4096) == 0)
debug(20, 1, " %7d Entries Validated so far.\n", validnum);
- if (BIT_TEST(e->flag, ENTRY_VALIDATED)) {
- xfree(curr->key);
- xfree(curr);
- eventAdd("storeCleanup", storeCleanup, NULL, 0);
- return;
- }
- storeValidate(e, storeCleanupComplete, e);
+ if (!BIT_TEST(e->flag, ENTRY_VALIDATED))
+ storeValidate(e, storeCleanupComplete, e);
xfree(curr->key);
xfree(curr);
eventAdd("storeCleanup", storeCleanup, NULL, 0);
int i;
struct storeRebuild_data *data;
time_t last_clean;
-
if (stat(swaplog_file, &sb) < 0) {
debug(20, 1, "storeRebuildFromDisk: No log file\n");
store_rebuilding = STORE_NOT_REBUILDING;
return;
}
data = xcalloc(1, sizeof(*data));
-
for (i = 0; i < ncache_dirs; i++)
debug(20, 1, "Rebuilding storage from disk image in %s\n", storeSwapDir(i));
data->start = getCurrentTime();
-
/* Check if log is clean */
sprintf(tmp_filename, "%s-last-clean", swaplog_file);
if (stat(tmp_filename, &sb) >= 0) {
last_clean = sb.st_mtime;
if (stat(swaplog_file, &sb) >= 0)
store_rebuilding = (sb.st_mtime <= last_clean) ?
- STORE_REBUILDING_FAST : STORE_REBUILDING_SLOW;
+ STORE_REBUILDING_CLEAN : STORE_REBUILDING_DIRTY;
}
/* Remove timestamp in case we crash during rebuild */
safeunlink(tmp_filename, 1);
fatal(tmp_error_buf);
}
debug(20, 3, "data->log %d is now '%s'\n", fileno(data->log), swaplog_file);
- if (store_rebuilding == STORE_REBUILDING_FAST) {
- store_validating = 0;
- debug(20, 1, "Rebuilding in FAST MODE.\n");
- }
+ debug(20, 1, "Rebuilding in %s log.\n",
+ store_rebuilding == STORE_REBUILDING_CLEAN ? "CLEAN" : "DIRTY");
+ store_validating = store_rebuilding == STORE_REBUILDING_CLEAN ? 0 : 1;
memset(data->line_in, '\0', 4096);
- /* data->speed = store_rebuilding == STORE_REBUILDING_FAST ? 50 : 5; */
data->speed = 50;
-
/* Start reading the log file */
if (opt_foreground_rebuild) {
data->speed = 1 << 30;
pages_needed = (size / SM_PAGE_SIZE) + 1;
if (sm_stats.n_pages_in_use + pages_needed < store_pages_high)
return;
- if (store_rebuilding == STORE_REBUILDING_FAST)
+ if (store_rebuilding == STORE_REBUILDING_CLEAN)
return;
debug(20, 2, "storeGetMemSpace: Starting, need %d pages\n", pages_needed);
if ((hentry = (StoreEntry *) hash_lookup(store_table, hkey)))
storeExpireNow(hentry);
}
- if (store_rebuilding == STORE_REBUILDING_FAST) {
+ if (store_rebuilding == STORE_REBUILDING_CLEAN) {
debug(20, 2, "storeRelease: Delaying release until store is rebuilt: '%s'\n",
e->key ? e->key : e->url ? e->url : "NO URL");
storeExpireNow(e);
storeInit(void)
{
int dir_created = 0;
- wordlist *w = NULL;
char *fname = NULL;
storeInitHashValues();
storeCreateHashTable(urlcmp);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
/* We can't delete objects while rebuilding swap */
- if (store_rebuilding == STORE_REBUILDING_FAST)
+ if (store_rebuilding == STORE_REBUILDING_CLEAN)
return;
/* Purges expired objects, check one bucket on each calling */
#define DefaultLevelOneDirs 16
#define DefaultLevelTwoDirs 256
+/* GLOBALS */
+int ncache_dirs = 0;
+/* LOCALS */
static int SwapDirsAllocated = 0;
-static int ncache_dirs;
/* return full name to swapfile */
char *
return fullpath;
}
+/* return full name to swapfile */
+char *
+storeSwapSubSubDir(int fn, char *fullpath)
+{
+ LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN);
+ int dirn = (fn >> SWAP_DIR_SHIFT) % ncache_dirs;
+ int filn = fn & SWAP_FILE_MASK;
+ if (!fullpath)
+ fullpath = fullfilename;
+ fullpath[0] = '\0';
+ sprintf(fullpath, "%s/%02X/%02X",
+ SwapDirs[dirn].path,
+ filn % SwapDirs[dirn].l1,
+ filn / SwapDirs[dirn].l1 % SwapDirs[dirn].l2);
+ return fullpath;
+}
+
/* add directory to swap disk */
int
storeAddSwapDisk(const char *path, int size, int l1, int l2, int read_only)
}
}
debug(20, 1, "Created directory %s\n", path);
- if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode) == 0)
- return 1;
- sprintf(tmp_error_buf,
- "Failed to create directory %s: %s", path, xstrerror());
- fatal(tmp_error_buf);
- /* NOTREACHED */
+ if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode) != 0) {
+ sprintf(tmp_error_buf,
+ "Failed to create directory %s: %s", path, xstrerror());
+ fatal(tmp_error_buf);
+ }
+ return 1;
}
int
return dirn;
}
+int
+storeDirMapBitTest(int fn)
+{
+ int dirn = fn >> SWAP_DIR_SHIFT;
+ int filn = fn & SWAP_FILE_MASK;
+ return file_map_bit_test(SwapDirs[dirn].map, filn);
+}
+
void
storeDirMapBitSet(int fn)
{
int dirn = fn >> SWAP_DIR_SHIFT;
int filn = fn & SWAP_FILE_MASK;
- file_map_bit_set(SwapDir[dirn].map, filn);
- SwapDir[dirn].suggest++;
+ file_map_bit_set(SwapDirs[dirn].map, filn);
+ SwapDirs[dirn].suggest++;
}
void
{
int dirn = fn >> SWAP_DIR_SHIFT;
int filn = fn & SWAP_FILE_MASK;
- file_map_bit_reset(SwapDir[dirn].map, filn);
- if (fn < SwapDir[dirn].suggest)
- SwapDir[dirn].suggest = fn;
+ file_map_bit_reset(SwapDirs[dirn].map, filn);
+ if (fn < SwapDirs[dirn].suggest)
+ SwapDirs[dirn].suggest = fn;
}
int
{
if (dirn < 0 || dirn >= ncache_dirs)
fatal_dump("storeSwapDir: bad index");
- return SwapDir[dirn].path;
+ return SwapDirs[dirn].path;
}