From f4e3fa542e2b0207f4b7e27b43f87f9f4ee0eeea Mon Sep 17 00:00:00 2001 From: wessels <> Date: Thu, 20 Aug 1998 08:49:10 +0000 Subject: [PATCH] when write fails because a disk is full, only lower *that* cache_dir and recompute the maxSize. 'storedir' stats should now be consistent --- src/cache_cf.cc | 24 ++---------------------- src/protos.h | 4 +++- src/store_dir.cc | 39 ++++++++++++++++++++++++++++++++++++++- src/store_swapout.cc | 12 ++++++------ 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/cache_cf.cc b/src/cache_cf.cc index eae709f8ed..09f3303ab0 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.298 1998/08/17 23:27:58 wessels Exp $ + * $Id: cache_cf.cc,v 1.299 1998/08/20 02:49:10 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -210,11 +210,7 @@ static void configDoConfigure(void) { LOCAL_ARRAY(char, buf, BUFSIZ); - int i; - SwapDir *SD; - fileMap *fm; const refresh_t *R; - int n; memset(&Config2, '\0', sizeof(SquidConfig2)); /* init memory as early as possible */ memConfigure(); @@ -222,23 +218,7 @@ configDoConfigure(void) if (Config.cacheSwap.swapDirs == NULL) fatal("No cache_dir's specified in config file"); /* calculate Config.Swap.maxSize */ - Config.Swap.maxSize = 0; - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - SD = &Config.cacheSwap.swapDirs[i];; - Config.Swap.maxSize += SD->max_size; - n = 2 * SD->max_size / Config.Store.avgObjectSize; - if (NULL == SD->map) { - /* first time */ - SD->map = file_map_create(n); - } else if (n > SD->map->max_n_files) { - /* it grew, need to expand */ - fm = file_map_create(n); - filemapCopy(SD->map, fm); - filemapFreeMemory(SD->map); - SD->map = fm; - } - /* else it shrunk, and we leave the old one in place */ - } + storeDirConfigure(); if (Config.Swap.maxSize < (Config.Mem.maxSize >> 10)) fatal("cache_swap is lower than cache_mem"); if (Config.Announce.period > 0) { diff --git a/src/protos.h b/src/protos.h index abac01d533..11001d85ae 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.251 1998/08/19 06:05:54 wessels Exp $ + * $Id: protos.h,v 1.252 1998/08/20 02:49:11 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -852,6 +852,8 @@ extern int storeDirValidFileno(int fn); extern int storeFilenoBelongsHere(int, int, int, int); extern OBJH storeDirStats; extern int storeDirMapBitsInUse(void); +extern void storeDirConfigure(void); +extern void storeDirDiskFull(int fn); /* diff --git a/src/store_dir.cc b/src/store_dir.cc index c57f74a627..8babbbe8ec 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir.cc,v 1.74 1998/07/22 20:37:59 wessels Exp $ + * $Id: store_dir.cc,v 1.75 1998/08/20 02:49:12 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -789,3 +789,40 @@ storeDirWriteCleanLogs(int reopen) return n; } #undef CLEAN_BUF_SZ + +void +storeDirConfigure(void) +{ + SwapDir *SD; + int n; + int i; + fileMap *fm; + Config.Swap.maxSize = 0; + for (i = 0; i < Config.cacheSwap.n_configured; i++) { + SD = &Config.cacheSwap.swapDirs[i];; + Config.Swap.maxSize += SD->max_size; + n = 2 * SD->max_size / Config.Store.avgObjectSize; + if (NULL == SD->map) { + /* first time */ + SD->map = file_map_create(n); + } else if (n > SD->map->max_n_files) { + /* it grew, need to expand */ + fm = file_map_create(n); + filemapCopy(SD->map, fm); + filemapFreeMemory(SD->map); + SD->map = fm; + } + /* else it shrunk, and we leave the old one in place */ + } +} + +void +storeDirDiskFull(int fn) +{ + int dirn = fn >> SWAP_DIR_SHIFT; + SwapDir *SD = &Config.cacheSwap.swapDirs[dirn]; + assert(0 <= dirn && dirn < Config.cacheSwap.n_configured); + SD->max_size = SD->cur_size; + debug(20, 1)("WARNING: Shrinking cache_dir #%d to %d KB\n", + dirn, SD->cur_size); +} diff --git a/src/store_swapout.cc b/src/store_swapout.cc index e4d8c6eddf..3830f40228 100644 --- a/src/store_swapout.cc +++ b/src/store_swapout.cc @@ -1,6 +1,6 @@ /* - * $Id: store_swapout.cc,v 1.23 1998/08/19 04:32:14 wessels Exp $ + * $Id: store_swapout.cc,v 1.24 1998/08/20 02:49:13 wessels Exp $ * * DEBUG: section 20 Storage Manager Swapout Functions * AUTHOR: Duane Wessels @@ -79,13 +79,13 @@ storeSwapOutHandle(int fdnotused, int flag, size_t len, void *data) if (e->swap_file_number > -1) { storeUnlinkFileno(e->swap_file_number); storeDirMapBitReset(e->swap_file_number); + if (flag == DISK_NO_SPACE_LEFT) { + storeDirDiskFull(e->swap_file_number); + storeDirConfigure(); + storeConfigure(); + } e->swap_file_number = -1; } - if (flag == DISK_NO_SPACE_LEFT) { - /* reduce the swap_size limit to the current size. */ - Config.Swap.maxSize = store_swap_size; - storeConfigure(); - } storeReleaseRequest(e); storeSwapOutFileClose(e); return; -- 2.47.3