RockRebuild.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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_FS_ROCK_REBUILD_H
10#define SQUID_FS_ROCK_REBUILD_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
55protected:
57 static bool IsResponsible(const SwapDir &);
58
60 ~Rebuild() override;
61
62 /* Registered Runner API */
63 void startShutdown() override;
64
65 /* AsyncJob API */
66 void start() override;
67 bool doneAll() const override;
68 void swanSong() override;
69
70 bool doneLoading() const;
71 bool doneValidating() const;
72
73private:
74 void checkpoint();
75 void steps();
76 void loadingSteps();
77 void validationSteps();
78 void loadOneSlot();
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);
83
84 void failure(const char *msg, int errNo = 0);
85
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);
93
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);
98
99 template <class SlotIdType>
100 void chainSlots(SlotIdType &from, const SlotId to);
101
102 bool sameEntry(const sfileno fileno, const DbCellHeader &header) const;
103
105
108
110
111 int64_t dbSize;
113 int64_t dbSlotLimit;
114 int64_t dbEntryLimit;
115
116 int fd; // store db file descriptor
117 int64_t dbOffset; // TODO: calculate in a method, using loadingPos
118 int64_t loadingPos;
121
123
126 const bool resuming;
127
128 static void Steps(void *data);
129};
130
131} // namespace Rock
132
133#endif /* SQUID_FS_ROCK_REBUILD_H */
134
A RegisteredRunner with lifetime determined by forces outside the Registry.
Definition: MemBuf.h:24
smart StoreEntry-level info pointer (hides anti-padding LoadingParts arrays)
Definition: RockRebuild.cc:110
smart db slot-level info pointer (hides anti-padding LoadingParts arrays)
Definition: RockRebuild.cc:134
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)
Definition: RockRebuild.cc:251
static Ipc::Mem::Owner< Stats > * Init(const SwapDir &)
Definition: RockRebuild.cc:257
bool completed(const SwapDir &) const
whether the rebuild is finished already
Definition: RockRebuild.cc:263
StoreRebuildData counts
Definition: RockRebuild.h:48
void freeBadEntry(const sfileno fileno, const char *eDescription)
Definition: RockRebuild.cc:670
bool doneAll() const override
whether positive goal has been reached
Definition: RockRebuild.cc:394
void validateOneSlot(const SlotId slotId)
Definition: RockRebuild.cc:660
StoreRebuildData & counts
a reference to the shared memory counters
Definition: RockRebuild.h:122
static void Steps(void *data)
Definition: RockRebuild.cc:400
void validationSteps()
Definition: RockRebuild.cc:559
void loadingSteps()
Definition: RockRebuild.cc:418
void finalizeOrThrow(const sfileno fileNo, LoadingEntry &le)
Definition: RockRebuild.cc:598
void freeSlot(const SlotId slotId, const bool invalid)
adds slot to the free slot index
Definition: RockRebuild.cc:714
void primeNewEntry(Ipc::StoreMapAnchor &anchor, const sfileno fileno, const DbCellHeader &header)
initialize housekeeping information for a newly accepted entry
Definition: RockRebuild.cc:830
const bool resuming
Definition: RockRebuild.h:126
int64_t validationPos
index of the loaded db slot being validated now
Definition: RockRebuild.h:119
void addSlotToEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
Definition: RockRebuild.cc:770
static bool Start(SwapDir &dir)
Definition: RockRebuild.cc:279
void mapSlot(const SlotId slotId, const DbCellHeader &header)
adds slot to the entry chain in the map
Definition: RockRebuild.cc:744
LoadingEntry loadingEntry(const sfileno fileNo)
Definition: RockRebuild.cc:453
LoadingSlot loadingSlot(const SlotId slotId)
Definition: RockRebuild.cc:460
void start() override
prepares and initiates entry loading sequence
Definition: RockRebuild.cc:339
int64_t dbSlotLimit
total number of db cells
Definition: RockRebuild.h:113
int64_t loadingPos
index of the db slot being loaded from disk now
Definition: RockRebuild.h:118
int64_t dbEntryLimit
maximum number of entries that can be stored in db
Definition: RockRebuild.h:114
void checkpoint()
continues after a pause if not done
Definition: RockRebuild.cc:375
MemBuf buf
space to load current db slot (and entry metadata) into
Definition: RockRebuild.h:120
int dbSlotSize
the size of a db cell, including the cell header
Definition: RockRebuild.h:112
void chainSlots(SlotIdType &from, const SlotId to)
Definition: RockRebuild.cc:759
void validateOneEntry(const sfileno fileNo)
Definition: RockRebuild.cc:642
void loadOneSlot()
Definition: RockRebuild.cc:468
bool doneLoading() const
Definition: RockRebuild.cc:382
int64_t dbOffset
Definition: RockRebuild.h:117
Rebuild(SwapDir *dir, const Ipc::Mem::Pointer< Stats > &)
Definition: RockRebuild.cc:298
bool doneValidating() const
Definition: RockRebuild.cc:388
bool importEntry(Ipc::StoreMapAnchor &anchor, const sfileno slotId, const DbCellHeader &header)
parse StoreEntry basics and add them to the map, returning true on success
Definition: RockRebuild.cc:530
int64_t dbSize
Definition: RockRebuild.h:111
void startNewEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
handle a slot from an entry that we have not seen before
Definition: RockRebuild.cc:846
void failure(const char *msg, int errNo=0)
Definition: RockRebuild.cc:698
LoadingParts * parts
parts of store entries being loaded from disk
Definition: RockRebuild.h:107
SBuf progressDescription() const
Definition: RockRebuild.cc:932
static bool IsResponsible(const SwapDir &)
whether the current kid is responsible for rebuilding the given cache_dir
Definition: RockRebuild.cc:272
SwapDir * sd
Definition: RockRebuild.h:106
void useNewSlot(const SlotId slotId, const DbCellHeader &header)
handle freshly loaded (and validated) db slot header
Definition: RockRebuild.cc:876
bool sameEntry(const sfileno fileno, const DbCellHeader &header) const
does the header belong to the fileno entry being loaded?
Definition: RockRebuild.cc:866
void swanSong() override
Definition: RockRebuild.cc:690
~Rebuild() override
Definition: RockRebuild.cc:322
Ipc::Mem::Pointer< Stats > stats
indexing statistics in shared memory
Definition: RockRebuild.h:109
void freeUnusedSlot(const SlotId slotId, const bool invalid)
freeSlot() for never-been-mapped slots
Definition: RockRebuild.cc:734
CBDATA_CHILD(Rebuild)
void finalizeOrFree(const sfileno fileNo, LoadingEntry &le)
Definition: RockRebuild.cc:632
void startShutdown() override
Definition: RockRebuild.cc:332
Definition: SBuf.h:94
cache_dir(s) indexing statistics
Definition: store_rebuild.h:20
void Stats(StoreEntry *)
Definition: old_api.cc:165
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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors