RockRebuild.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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"
13 #include "base/RunnersRegistry.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 
21 namespace Rock
22 {
23 
24 class LoadingEntry;
25 class LoadingSlot;
26 class LoadingParts;
27 
30 class Rebuild: public AsyncJob, private IndependentRunner
31 {
33 
34 public:
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 protected:
57  static bool IsResponsible(const SwapDir &);
58 
60  virtual ~Rebuild() override;
61 
62  /* Registered Runner API */
63  virtual void startShutdown() override;
64 
65  /* AsyncJob API */
66  virtual void start() override;
67  virtual bool doneAll() const override;
68  virtual void swanSong() override;
69 
70  bool doneLoading() const;
71  bool doneValidating() const;
72 
73 private:
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 
104  SBuf progressDescription() const;
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;
119  int64_t validationPos;
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 
CBDATA_CHILD(Rebuild)
A RegisteredRunner with lifetime determined by forces outside the Registry.
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:825
SBuf progressDescription() const
Definition: RockRebuild.cc:911
LoadingSlot loadingSlot(const SlotId slotId)
Definition: RockRebuild.cc:459
smart db slot-level info pointer (hides anti-padding LoadingParts arrays)
Definition: RockRebuild.cc:133
int64_t dbEntryLimit
maximum number of entries that can be stored in db
Definition: RockRebuild.h:114
Definition: forward.h:28
smart StoreEntry-level info pointer (hides anti-padding LoadingParts arrays)
Definition: RockRebuild.cc:109
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:513
Rebuild(SwapDir *dir, const Ipc::Mem::Pointer< Stats > &)
Definition: RockRebuild.cc:297
SwapDir * sd
Definition: RockRebuild.h:106
MemBuf buf
space to load current db slot (and entry metadata) into
Definition: RockRebuild.h:120
void chainSlots(SlotIdType &from, const SlotId to)
Definition: RockRebuild.cc:738
static void Steps(void *data)
Definition: RockRebuild.cc:399
bool sameEntry(const sfileno fileno, const DbCellHeader &header) const
does the header belong to the fileno entry being loaded?
Definition: RockRebuild.cc:845
Definition: SBuf.h:87
cache_dir(s) indexing statistics
Definition: store_rebuild.h:20
bool doneValidating() const
Definition: RockRebuild.cc:387
LoadingEntry loadingEntry(const sfileno fileNo)
Definition: RockRebuild.cc:452
void primeNewEntry(Ipc::StoreMapAnchor &anchor, const sfileno fileno, const DbCellHeader &header)
initialize housekeeping information for a newly accepted entry
Definition: RockRebuild.cc:809
void freeBadEntry(const sfileno fileno, const char *eDescription)
Definition: RockRebuild.cc:649
void freeUnusedSlot(const SlotId slotId, const bool invalid)
freeSlot() for never-been-mapped slots
Definition: RockRebuild.cc:713
int64_t dbSize
Definition: RockRebuild.h:111
void finalizeOrThrow(const sfileno fileNo, LoadingEntry &le)
Definition: RockRebuild.cc:577
int dbSlotSize
the size of a db cell, including the cell header
Definition: RockRebuild.h:112
void Stats(StoreEntry *)
Definition: old_api.cc:166
StoreRebuildData counts
Definition: RockRebuild.h:48
void failure(const char *msg, int errNo=0)
Definition: RockRebuild.cc:677
virtual void startShutdown() override
Definition: RockRebuild.cc:331
Definition: MemBuf.h:24
void addSlotToEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
Definition: RockRebuild.cc:749
void validationSteps()
Definition: RockRebuild.cc:538
bool doneLoading() const
Definition: RockRebuild.cc:381
void loadOneSlot()
Definition: RockRebuild.cc:467
int64_t dbSlotLimit
total number of db cells
Definition: RockRebuild.h:113
StoreRebuildData & counts
a reference to the shared memory counters
Definition: RockRebuild.h:122
static Ipc::Mem::Owner< Stats > * Init(const SwapDir &)
Definition: RockRebuild.cc:256
bool completed(const SwapDir &) const
whether the rebuild is finished already
Definition: RockRebuild.cc:262
void validateOneSlot(const SlotId slotId)
Definition: RockRebuild.cc:639
void checkpoint()
continues after a pause if not done
Definition: RockRebuild.cc:374
signed_int32_t sfileno
Definition: forward.h:22
void useNewSlot(const SlotId slotId, const DbCellHeader &header)
handle freshly loaded (and validated) db slot header
Definition: RockRebuild.cc:855
static bool IsResponsible(const SwapDir &)
whether the current kid is responsible for rebuilding the given cache_dir
Definition: RockRebuild.cc:271
int64_t loadingPos
index of the db slot being loaded from disk now
Definition: RockRebuild.h:118
Ipc::Mem::Pointer< Stats > stats
indexing statistics in shared memory
Definition: RockRebuild.h:109
virtual ~Rebuild() override
Definition: RockRebuild.cc:321
void validateOneEntry(const sfileno fileNo)
Definition: RockRebuild.cc:621
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:30
LoadingParts * parts
parts of store entries being loaded from disk
Definition: RockRebuild.h:107
static bool Start(SwapDir &dir)
Definition: RockRebuild.cc:278
void freeSlot(const SlotId slotId, const bool invalid)
adds slot to the free slot index
Definition: RockRebuild.cc:693
int64_t validationPos
index of the loaded db slot being validated now
Definition: RockRebuild.h:119
static size_t SharedMemorySize()
Definition: RockRebuild.h:42
virtual void start() override
prepares and initiates entry loading sequence
Definition: RockRebuild.cc:338
void loadingSteps()
Definition: RockRebuild.cc:417
virtual void swanSong() override
Definition: RockRebuild.cc:669
void mapSlot(const SlotId slotId, const DbCellHeader &header)
adds slot to the entry chain in the map
Definition: RockRebuild.cc:723
virtual bool doneAll() const override
whether positive goal has been reached
Definition: RockRebuild.cc:393
size_t sharedMemorySize() const
Definition: RockRebuild.h:43
const bool resuming
Definition: RockRebuild.h:126
cache_dir indexing statistics shared across same-kid process restarts
Definition: RockRebuild.h:37
static SBuf Path(const char *dirPath)
Definition: RockRebuild.cc:250
void finalizeOrFree(const sfileno fileNo, LoadingEntry &le)
Definition: RockRebuild.cc:611
int64_t dbOffset
Definition: RockRebuild.h:117

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors