From af2fda0724adbce9a8ef6586ec1028d4966864a2 Mon Sep 17 00:00:00 2001 From: Dmitry Kurochkin Date: Mon, 18 Apr 2011 15:53:16 +0400 Subject: [PATCH] Warn if MemStore cannot support the configured maximum disk-cache entry size. --- src/MemStore.cc | 20 +++++++++++++++++++- src/MemStore.h | 1 + src/Store.h | 3 +++ src/StoreHashIndex.h | 2 ++ src/SwapDir.h | 4 ++++ src/store_dir.cc | 19 +++++++++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/MemStore.cc b/src/MemStore.cc index 517a495143..fe6680036b 100644 --- a/src/MemStore.cc +++ b/src/MemStore.cc @@ -44,6 +44,19 @@ MemStore::init() { if (entryLimit <= 0) return; // no memory cache configured or a misconfiguration + if (IamWorkerProcess()) { // XXX: coordinator should not create MemStore + const int64_t max_size = Store::Root().maxObjectSize(); + if (max_size == -1) { + debugs(20, DBG_IMPORTANT, "WARNING: disk-cache maximum object size " + "is unlimited but mem-cache maximum object size is " << + Ipc::Mem::PageSize()); + } else if (max_size > maxObjectSize()) { + debugs(20, DBG_IMPORTANT, "WARNING: disk-cache maximum object size " + "is too large for mem-cache: " << + Store::Root().maxObjectSize() << " > " << maxObjectSize()); + } + } + map = new MemStoreMap(ShmLabel); map->cleaner = this; } @@ -100,6 +113,12 @@ MemStore::currentCount() const return map ? map->entryCount() : 0; } +int64_t +MemStore::maxObjectSize() const +{ + return Ipc::Mem::PageSize(); +} + void MemStore::updateSize(int64_t eSize, int sign) { @@ -332,7 +351,6 @@ MemStore::EntryLimit() if (!Config.memMaxSize) return 0; // no memory cache configured - // TODO: warn if we cannot support the configured maximum entry size const int64_t entrySize = Ipc::Mem::PageSize(); // for now const int64_t entryLimit = Config.memMaxSize / entrySize; // TODO: warn if we cannot cache at least one item (misconfiguration) diff --git a/src/MemStore.h b/src/MemStore.h index b628e25898..ca5e60cea3 100644 --- a/src/MemStore.h +++ b/src/MemStore.h @@ -27,6 +27,7 @@ public: virtual uint64_t minSize() const; virtual uint64_t currentSize() const; virtual uint64_t currentCount() const; + virtual int64_t maxObjectSize() const; virtual void stat(StoreEntry &) const; virtual StoreSearch *search(String const url, HttpRequest *); virtual void reference(StoreEntry &); diff --git a/src/Store.h b/src/Store.h index d12d1ffccf..4b731be01c 100644 --- a/src/Store.h +++ b/src/Store.h @@ -306,6 +306,9 @@ public: /** the total number of objects stored */ virtual uint64_t currentCount() const = 0; + /** the maximum object size that can be stored, -1 if unlimited */ + virtual int64_t maxObjectSize() const = 0; + /** * Output stats to the provided store entry. \todo make these calls asynchronous diff --git a/src/StoreHashIndex.h b/src/StoreHashIndex.h index 8ed0c00991..b3badea2ad 100644 --- a/src/StoreHashIndex.h +++ b/src/StoreHashIndex.h @@ -71,6 +71,8 @@ public: virtual uint64_t currentCount() const; + virtual int64_t maxObjectSize() const; + virtual void stat(StoreEntry&) const; virtual void reference(StoreEntry&); diff --git a/src/SwapDir.h b/src/SwapDir.h index df0648f8a5..53dde7126c 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -73,6 +73,8 @@ public: virtual uint64_t currentCount() const; + virtual int64_t maxObjectSize() const; + virtual void stat(StoreEntry &) const; virtual void sync(); /* Sync the store prior to shutdown */ @@ -146,6 +148,8 @@ public: virtual uint64_t currentCount() const { return n_disk_objects; } + virtual int64_t maxObjectSize() const { return max_objsize; } + virtual void stat (StoreEntry &anEntry) const; virtual StoreSearch *search(String const url, HttpRequest *) = 0; diff --git a/src/store_dir.cc b/src/store_dir.cc index 4d64c018e5..922bb7d786 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -389,6 +389,12 @@ StoreController::currentCount() const return swapDir->currentCount(); } +int64_t +StoreController::maxObjectSize() const +{ + return swapDir->maxObjectSize(); +} + void SwapDir::diskFull() { @@ -958,6 +964,19 @@ StoreHashIndex::currentCount() const return result; } +int64_t +StoreHashIndex::maxObjectSize() const +{ + int64_t result = -1; + + for (int i = 0; i < Config.cacheSwap.n_configured; i++) { + if (dir(i).active() && store(i)->maxObjectSize() > result) + result = store(i)->maxObjectSize(); + } + + return result; +} + void StoreHashIndex::stat(StoreEntry & output) const { -- 2.47.2