]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Initialize and cleanup Rock shared maps using RunnersRegistry API.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Wed, 27 Apr 2011 01:52:46 +0000 (05:52 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Wed, 27 Apr 2011 01:52:46 +0000 (05:52 +0400)
src/fs/rock/RockSwapDir.cc
src/fs/rock/RockSwapDir.h

index ce06bc823e8d2b3031f5a96f0d3af50e75793142..73182b9d926932714eb52499814345e96b01aa0c 100644 (file)
@@ -8,6 +8,7 @@
 #include "Parsing.h"
 #include <iomanip>
 #include "MemObject.h"
+#include "base/RunnersRegistry.h"
 #include "DiskIO/DiskIOModule.h"
 #include "DiskIO/DiskIOStrategy.h"
 #include "DiskIO/ReadRequest.h"
 // must be divisible by 1024 due to cur_size and max_size KB madness
 const int64_t Rock::SwapDir::HeaderSize = 16*1024;
 
-Rock::SwapDir::SwapDir(): ::SwapDir("rock"), filePath(NULL), io(NULL),
-    mapOwner(NULL), map(NULL)
+Rock::SwapDir::SwapDir(): ::SwapDir("rock"), filePath(NULL), io(NULL), map(NULL)
 {
 }
 
 Rock::SwapDir::~SwapDir()
 {
     delete io;
-    delete mapOwner;
     delete map;
     safe_free(filePath);
 }
@@ -195,16 +194,8 @@ Rock::SwapDir::init()
     // are refcounted. We up our count once to avoid implicit delete's.
     RefCountReference();
 
-    if (!map && (!UsingSmp() || IamDiskProcess())) {
-        // XXX: polish, validateOptions() has same code
-        const int64_t eLimitHi = 0xFFFFFF; // Core sfileno maximum
-        const int64_t eLimitLo = 0; // dynamic shrinking unsupported
-        const int64_t eWanted = (maximumSize() - HeaderSize)/max_objsize;
-        const int64_t eAllowed = min(max(eLimitLo, eWanted), eLimitHi);
-        Must(!mapOwner);
-        mapOwner = DirMap::Init(path, eAllowed);
-        map = new DirMap(path);
-    }
+    Must(!map);
+    map = new DirMap(path);
 
     const char *ioModule = UsingSmp() ? "IpcIo" : "Blocking";
     if (DiskIOModule *m = DiskIOModule::Find(ioModule)) {
@@ -480,9 +471,6 @@ Rock::SwapDir::ioCompletedNotification()
         fatalf("Rock cache_dir failed to open db file: %s", filePath);
        }
 
-    if (!map)
-        map = new DirMap(path);
-
     // TODO: lower debugging level
     debugs(47,1, "Rock cache_dir[" << index << "] limits: " << 
         std::setw(12) << maximumSize() << " disk bytes and " <<
@@ -688,3 +676,45 @@ Rock::SwapDir::statfs(StoreEntry &e) const
     storeAppendPrintf(&e, "\n");
 
 }
+
+
+/// initializes shared memory segments used by Rock::SwapDir
+class RockSwapDirRr: public RegisteredRunner
+{
+public:
+    /* RegisteredRunner API */
+    virtual void run(const RunnerRegistry &);
+    virtual ~RockSwapDirRr();
+
+private:
+    Vector<Rock::SwapDir::DirMap::Owner *> owners;
+};
+
+RunnerRegistrationEntry(rrAfterConfig, RockSwapDirRr);
+
+
+void RockSwapDirRr::run(const RunnerRegistry &)
+{
+    if (IamMasterProcess()) {
+        Must(owners.empty());
+        for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+            const Rock::SwapDir *const sd =
+                dynamic_cast<Rock::SwapDir *>(INDEXSD(i));
+            if (!sd)
+                continue;
+
+            // XXX: polish, validateOptions() has same code
+            const int64_t eLimitHi = 0xFFFFFF; // Core sfileno maximum
+            const int64_t eLimitLo = 0; // dynamic shrinking unsupported
+            const int64_t eWanted = (sd->maximumSize() - Rock::SwapDir::HeaderSize)/sd->maxObjectSize();
+            const int64_t eAllowed = min(max(eLimitLo, eWanted), eLimitHi);
+            owners.push_back(Rock::SwapDir::DirMap::Init(sd->path, eAllowed));
+        }
+    }
+}
+
+RockSwapDirRr::~RockSwapDirRr()
+{
+    for (size_t i = 0; i < owners.size(); ++i)
+        delete owners[i];
+}
index 5d9ecc55c22ddca49caa5d72951702dec499f04c..f4c18c9b3ad8cece71c0626d86854953e1251e4f 100644 (file)
@@ -31,6 +31,13 @@ public:
     virtual uint64_t currentCount() const;
     virtual bool doReportStat() const;
 
+    // TODO: change cur_size and max_size type to stop this madness
+    int64_t maximumSize() const { return static_cast<int64_t>(max_size) << 10; }
+
+    static const int64_t HeaderSize;
+
+    typedef Ipc::StoreMapWithExtras<DbCellHeader> DirMap;
+
 protected:
     /* protected ::SwapDir API */
     virtual bool needsDiskStrand() const;
@@ -65,8 +72,6 @@ protected:
     void trackReferences(StoreEntry &e); ///< add to replacement policy scope
     void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
 
-    // TODO: change cur_size and max_size type to stop this madness
-    int64_t maximumSize() const { return static_cast<int64_t>(max_size) << 10;}
     int64_t diskOffset(int filen) const;
     int64_t diskOffsetLimit() const;
     int entryLimit() const { return map->entryLimit(); }
@@ -75,14 +80,9 @@ protected:
     const char *filePath; ///< location of cache storage file inside path/
 
 private:
-    typedef Ipc::StoreMapWithExtras<DbCellHeader> DirMap;
-
     DiskIOStrategy *io;
     RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
-    DirMap::Owner *mapOwner;
     DirMap *map;
-
-    static const int64_t HeaderSize; ///< on-disk db header size
 };
 
 } // namespace Rock