]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockRebuild.h
2 * Copyright (C) 1996-2023 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_SRC_FS_ROCK_ROCKREBUILD_H
10 #define SQUID_SRC_FS_ROCK_ROCKREBUILD_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 virtual void callException(const std::exception
&) override
;
59 /// whether the current kid is responsible for rebuilding the given cache_dir
60 static bool IsResponsible(const SwapDir
&);
62 Rebuild(SwapDir
*dir
, const Ipc::Mem::Pointer
<Stats
> &);
65 /* Registered Runner API */
66 void startShutdown() override
;
69 void start() override
;
70 bool doneAll() const override
;
71 void swanSong() override
;
73 bool doneLoading() const;
74 bool doneValidating() const;
80 void validationSteps();
82 void validateOneEntry(const sfileno fileNo
);
83 void validateOneSlot(const SlotId slotId
);
84 bool importEntry(Ipc::StoreMapAnchor
&anchor
, const sfileno slotId
, const DbCellHeader
&header
);
85 void freeBadEntry(const sfileno fileno
, const char *eDescription
);
87 void failure(const char *msg
, int errNo
= 0);
89 LoadingEntry
loadingEntry(const sfileno fileNo
);
90 void startNewEntry(const sfileno fileno
, const SlotId slotId
, const DbCellHeader
&header
);
91 void primeNewEntry(Ipc::StoreMapAnchor
&anchor
, const sfileno fileno
, const DbCellHeader
&header
);
92 void finalizeOrFree(const sfileno fileNo
, LoadingEntry
&le
);
93 void finalizeOrThrow(const sfileno fileNo
, LoadingEntry
&le
);
94 void addSlotToEntry(const sfileno fileno
, const SlotId slotId
, const DbCellHeader
&header
);
95 void useNewSlot(const SlotId slotId
, const DbCellHeader
&header
);
97 LoadingSlot
loadingSlot(const SlotId slotId
);
98 void mapSlot(const SlotId slotId
, const DbCellHeader
&header
);
99 void freeUnusedSlot(const SlotId slotId
, const bool invalid
);
100 void freeSlot(const SlotId slotId
, const bool invalid
);
102 template <class SlotIdType
>
103 void chainSlots(SlotIdType
&from
, const SlotId to
);
105 bool sameEntry(const sfileno fileno
, const DbCellHeader
&header
) const;
107 SBuf
progressDescription() const;
110 LoadingParts
*parts
; ///< parts of store entries being loaded from disk
112 Ipc::Mem::Pointer
<Stats
> stats
; ///< indexing statistics in shared memory
115 int dbSlotSize
; ///< the size of a db cell, including the cell header
116 int64_t dbSlotLimit
; ///< total number of db cells
117 int64_t dbEntryLimit
; ///< maximum number of entries that can be stored in db
119 int fd
; // store db file descriptor
120 int64_t dbOffset
; // TODO: calculate in a method, using loadingPos
121 int64_t loadingPos
; ///< index of the db slot being loaded from disk now
122 int64_t validationPos
; ///< index of the loaded db slot being validated now
123 MemBuf buf
; ///< space to load current db slot (and entry metadata) into
125 StoreRebuildData
&counts
; ///< a reference to the shared memory counters
127 /// whether we have started indexing this cache_dir before,
128 /// presumably in the previous process performing the same-kid role
131 static void Steps(void *data
);
136 #endif /* SQUID_SRC_FS_ROCK_ROCKREBUILD_H */