]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockRebuild.h
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_FS_ROCK_REBUILD_H
10 #define SQUID_FS_ROCK_REBUILD_H
12 #include "base/AsyncJob.h"
13 #include "base/RunnersRegistry.h"
15 #include "fs/rock/forward.h"
16 #include "ipc/mem/Pointer.h"
17 #include "ipc/StoreMap.h"
19 #include "store_rebuild.h"
29 /// manages store rebuild process: loading meta information from db on disk
30 class Rebuild
: public AsyncJob
, private IndependentRunner
32 CBDATA_CHILD(Rebuild
);
35 /// cache_dir indexing statistics shared across same-kid process restarts
39 static SBuf
Path(const char *dirPath
);
40 static Ipc::Mem::Owner
<Stats
> *Init(const SwapDir
&);
42 static size_t SharedMemorySize() { return sizeof(Stats
); }
43 size_t sharedMemorySize() const { return SharedMemorySize(); }
45 /// whether the rebuild is finished already
46 bool completed(const SwapDir
&) const;
48 StoreRebuildData counts
;
51 /// starts indexing the given cache_dir if that indexing is necessary
52 /// \returns whether the indexing was necessary (and, hence, started)
53 static bool Start(SwapDir
&dir
);
56 /// whether the current kid is responsible for rebuilding this db file
57 static bool IsResponsible(const SwapDir
&);
59 Rebuild(SwapDir
*dir
, const Ipc::Mem::Pointer
<Stats
> &);
60 virtual ~Rebuild() override
;
62 /* Registered Runner API */
63 virtual void startShutdown() override
;
66 virtual void start() override
;
67 virtual bool doneAll() const override
;
68 virtual void swanSong() override
;
70 bool doneLoading() const;
71 bool doneValidating() const;
77 void validationSteps();
79 void validateOneEntry(const sfileno fileNo
);
80 void validateOneSlot(const SlotId slotId
);
81 bool importEntry(Ipc::StoreMapAnchor
&anchor
, const sfileno slotId
, const DbCellHeader
&header
);
82 void freeBadEntry(const sfileno fileno
, const char *eDescription
);
84 void failure(const char *msg
, int errNo
= 0);
86 LoadingEntry
loadingEntry(const sfileno fileNo
);
87 void startNewEntry(const sfileno fileno
, const SlotId slotId
, const DbCellHeader
&header
);
88 void primeNewEntry(Ipc::StoreMapAnchor
&anchor
, const sfileno fileno
, const DbCellHeader
&header
);
89 void finalizeOrFree(const sfileno fileNo
, LoadingEntry
&le
);
90 void finalizeOrThrow(const sfileno fileNo
, LoadingEntry
&le
);
91 void addSlotToEntry(const sfileno fileno
, const SlotId slotId
, const DbCellHeader
&header
);
92 void useNewSlot(const SlotId slotId
, const DbCellHeader
&header
);
94 LoadingSlot
loadingSlot(const SlotId slotId
);
95 void mapSlot(const SlotId slotId
, const DbCellHeader
&header
);
96 void freeUnusedSlot(const SlotId slotId
, const bool invalid
);
97 void freeSlot(const SlotId slotId
, const bool invalid
);
99 template <class SlotIdType
>
100 void chainSlots(SlotIdType
&from
, const SlotId to
);
102 bool sameEntry(const sfileno fileno
, const DbCellHeader
&header
) const;
104 SBuf
progressDescription() const;
107 LoadingParts
*parts
; ///< parts of store entries being loaded from disk
109 Ipc::Mem::Pointer
<Stats
> stats
; ///< indexing statistics in shared memory
112 int dbSlotSize
; ///< the size of a db cell, including the cell header
113 int64_t dbSlotLimit
; ///< total number of db cells
114 int64_t dbEntryLimit
; ///< maximum number of entries that can be stored in db
116 int fd
; // store db file descriptor
117 int64_t dbOffset
; // TODO: calculate in a method, using loadingPos
118 int64_t loadingPos
; ///< index of the db slot being loaded from disk now
119 int64_t validationPos
; ///< index of the loaded db slot being validated now
120 MemBuf buf
; ///< space to load current db slot (and entry metadata) into
122 StoreRebuildData
&counts
; ///< a reference to the shared memory counters
124 /// whether we have started indexing this cache_dir before,
125 /// presumably in the previous process performing the same-kid role
128 static void Steps(void *data
);
133 #endif /* SQUID_FS_ROCK_REBUILD_H */