Squid Web Cache master
Loading...
Searching...
No Matches
RockRebuild.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#ifndef SQUID_SRC_FS_ROCK_ROCKREBUILD_H
10#define SQUID_SRC_FS_ROCK_ROCKREBUILD_H
11
12#include "base/AsyncJob.h"
14#include "cbdata.h"
15#include "fs/rock/forward.h"
16#include "ipc/mem/Pointer.h"
17#include "ipc/StoreMap.h"
18#include "MemBuf.h"
19#include "store_rebuild.h"
20
21namespace Rock
22{
23
24class LoadingEntry;
25class LoadingSlot;
26class LoadingParts;
27
30class Rebuild: public AsyncJob, private IndependentRunner
31{
33
34public:
36 class Stats
37 {
38 public:
39 static SBuf Path(const char *dirPath);
40 static Ipc::Mem::Owner<Stats> *Init(const SwapDir &);
41
42 static size_t SharedMemorySize() { return sizeof(Stats); }
43 size_t sharedMemorySize() const { return SharedMemorySize(); }
44
46 bool completed(const SwapDir &) const;
47
49 };
50
53 static bool Start(SwapDir &dir);
54
55 /* AsyncJob API */
56 virtual void callException(const std::exception &) override;
57
58protected:
60 static bool IsResponsible(const SwapDir &);
61
63 ~Rebuild() override;
64
65 /* Registered Runner API */
66 void startShutdown() override;
67
68 /* AsyncJob API */
69 void start() override;
70 bool doneAll() const override;
71 void swanSong() override;
72
73 bool doneLoading() const;
74 bool doneValidating() const;
75
76private:
77 void checkpoint();
78 void steps();
79 void loadingSteps();
80 void validationSteps();
81 void loadOneSlot();
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);
86
87 void failure(const char *msg, int errNo = 0);
88
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);
96
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);
101
102 template <class SlotIdType>
103 void chainSlots(SlotIdType &from, const SlotId to);
104
105 bool sameEntry(const sfileno fileno, const DbCellHeader &header) const;
106
108
111
113
114 int64_t dbSize;
116 int64_t dbSlotLimit;
117 int64_t dbEntryLimit;
118
119 int fd; // store db file descriptor
120 int64_t dbOffset; // TODO: calculate in a method, using loadingPos
121 int64_t loadingPos;
124
126
129 const bool resuming;
130
131 static void Steps(void *data);
132};
133
134} // namespace Rock
135
136#endif /* SQUID_SRC_FS_ROCK_ROCKREBUILD_H */
137
A RegisteredRunner with lifetime determined by forces outside the Registry.
smart StoreEntry-level info pointer (hides anti-padding LoadingParts arrays)
smart db slot-level info pointer (hides anti-padding LoadingParts arrays)
cache_dir indexing statistics shared across same-kid process restarts
Definition RockRebuild.h:37
static size_t SharedMemorySize()
Definition RockRebuild.h:42
size_t sharedMemorySize() const
Definition RockRebuild.h:43
static SBuf Path(const char *dirPath)
static Ipc::Mem::Owner< Stats > * Init(const SwapDir &)
bool completed(const SwapDir &) const
whether the rebuild is finished already
StoreRebuildData counts
Definition RockRebuild.h:48
void freeBadEntry(const sfileno fileno, const char *eDescription)
bool doneAll() const override
whether positive goal has been reached
void validateOneSlot(const SlotId slotId)
StoreRebuildData & counts
a reference to the shared memory counters
static void Steps(void *data)
void validationSteps()
void loadingSteps()
void finalizeOrThrow(const sfileno fileNo, LoadingEntry &le)
void freeSlot(const SlotId slotId, const bool invalid)
adds slot to the free slot index
void primeNewEntry(Ipc::StoreMapAnchor &anchor, const sfileno fileno, const DbCellHeader &header)
initialize housekeeping information for a newly accepted entry
const bool resuming
int64_t validationPos
index of the loaded db slot being validated now
void addSlotToEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
static bool Start(SwapDir &dir)
void mapSlot(const SlotId slotId, const DbCellHeader &header)
adds slot to the entry chain in the map
LoadingEntry loadingEntry(const sfileno fileNo)
virtual void callException(const std::exception &) override
called when the job throws during an async call
LoadingSlot loadingSlot(const SlotId slotId)
void start() override
prepares and initiates entry loading sequence
int64_t dbSlotLimit
total number of db cells
int64_t loadingPos
index of the db slot being loaded from disk now
int64_t dbEntryLimit
maximum number of entries that can be stored in db
void checkpoint()
continues after a pause if not done
MemBuf buf
space to load current db slot (and entry metadata) into
int dbSlotSize
the size of a db cell, including the cell header
void chainSlots(SlotIdType &from, const SlotId to)
void validateOneEntry(const sfileno fileNo)
bool doneLoading() const
int64_t dbOffset
bool doneValidating() const
bool importEntry(Ipc::StoreMapAnchor &anchor, const sfileno slotId, const DbCellHeader &header)
parse StoreEntry basics and add them to the map, returning true on success
void startNewEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
handle a slot from an entry that we have not seen before
void failure(const char *msg, int errNo=0)
a helper to handle rebuild-killing I/O errors
LoadingParts * parts
parts of store entries being loaded from disk
SBuf progressDescription() const
static bool IsResponsible(const SwapDir &)
whether the current kid is responsible for rebuilding the given cache_dir
SwapDir * sd
void useNewSlot(const SlotId slotId, const DbCellHeader &header)
handle freshly loaded (and validated) db slot header
bool sameEntry(const sfileno fileno, const DbCellHeader &header) const
does the header belong to the fileno entry being loaded?
void swanSong() override
~Rebuild() override
Ipc::Mem::Pointer< Stats > stats
indexing statistics in shared memory
void freeUnusedSlot(const SlotId slotId, const bool invalid)
freeSlot() for never-been-mapped slots
CBDATA_CHILD(Rebuild)
void finalizeOrFree(const sfileno fileNo, LoadingEntry &le)
void startShutdown() override
Definition SBuf.h:94
cache_dir(s) indexing statistics
Definition forward.h:28
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition forward.h:33
signed_int32_t sfileno
Definition forward.h:22