RockSwapDir.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_ROCKSWAPDIR_H
10 #define SQUID_SRC_FS_ROCK_ROCKSWAPDIR_H
11 
12 #include "DiskIO/DiskFile.h"
13 #include "DiskIO/IORequestor.h"
14 #include "fs/rock/forward.h"
15 #include "fs/rock/RockDbCell.h"
16 #include "fs/rock/RockRebuild.h"
17 #include "ipc/mem/Page.h"
18 #include "ipc/mem/PageStack.h"
19 #include "ipc/StoreMap.h"
20 #include "store/Disk.h"
21 #include "store_rebuild.h"
22 #include <vector>
23 
24 class DiskIOStrategy;
25 class ReadRequest;
26 class WriteRequest;
27 
28 namespace Rock
29 {
30 
32 class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
33 {
34 public:
37 
38  SwapDir();
39  ~SwapDir() override;
40 
41  /* public ::SwapDir API */
42  void reconfigure() override;
43  StoreEntry *get(const cache_key *key) override;
44  void evictCached(StoreEntry &) override;
45  void evictIfFound(const cache_key *) override;
46  void disconnect(StoreEntry &e) override;
47  uint64_t currentSize() const override;
48  uint64_t currentCount() const override;
49  bool doReportStat() const override;
50  void finalizeSwapoutSuccess(const StoreEntry &) override;
51  void finalizeSwapoutFailure(StoreEntry &) override;
52  void create() override;
53  void parse(int index, char *path) override;
54  bool smpAware() const override { return true; }
55  bool hasReadableEntry(const StoreEntry &) const override;
56 
57  // temporary path to the shared memory map of first slots of cached entries
58  SBuf inodeMapPath() const;
59  // temporary path to the shared memory stack of free slots
60  const char *freeSlotsPath() const;
61 
62  int64_t entryLimitAbsolute() const { return SwapFilenMax+1; }
63  int64_t entryLimitActual() const;
64  int64_t slotLimitAbsolute() const;
65  int64_t slotLimitActual() const;
66 
68  bool validSlotId(const SlotId slotId) const;
69 
72 
74  void purgeSome();
75 
76  int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
77  int64_t diskOffset(int filen) const;
78  void writeError(StoreIOState &sio);
79 
80  /* StoreMapCleaner API */
81  void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno) override;
82 
83  uint64_t slotSize;
84 
85 protected:
86  /* Store API */
87  bool anchorToCache(StoreEntry &) override;
88  bool updateAnchored(StoreEntry &) override;
89 
90  /* protected ::SwapDir API */
91  bool needsDiskStrand() const override;
92  void init() override;
93  ConfigOption *getOptionTree() const override;
94  bool allowOptionReconfigure(const char *const option) const override;
95  bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const override;
98  void maintain() override;
99  void diskFull() override;
100  void reference(StoreEntry &e) override;
101  bool dereference(StoreEntry &e) override;
102  void updateHeaders(StoreEntry *e) override;
103  bool unlinkdUseful() const override;
104  void statfs(StoreEntry &e) const override;
105 
106  /* IORequestor API */
107  void ioCompletedNotification() override;
108  void closeCompleted() override;
109  void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>) override;
110  void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>) override;
111 
112  void parseSize(const bool reconfiguring);
113  void validateOptions();
114  bool parseTimeOption(char const *option, const char *value, int reconfiguring);
115  void dumpTimeOption(StoreEntry * e) const;
116  bool parseRateOption(char const *option, const char *value, int reconfiguring);
117  void dumpRateOption(StoreEntry * e) const;
118  bool parseSizeOption(char const *option, const char *value, int reconfiguring);
119  void dumpSizeOption(StoreEntry * e) const;
120 
121  bool full() const;
122  void trackReferences(StoreEntry &e);
123  void ignoreReferences(StoreEntry &e);
124 
125  int64_t diskOffsetLimit() const;
126 
129 
130  void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
131 
132  friend class Rebuild;
133  friend class IoState;
134  friend class HeaderUpdater;
135  const char *filePath;
137 
138 private:
139  void createError(const char *const msg);
140  void handleWriteCompletionSuccess(const WriteRequest &request);
141  void handleWriteCompletionProblem(const int errflag, const WriteRequest &request);
142 
147 
148  /* configurable options */
150 
151  static const int64_t HeaderSize = 16*1024;
152 };
153 
156 {
157 public:
158  /* ::RegisteredRunner API */
159  ~SwapDirRr() override;
160 
161 protected:
162  /* Ipc::Mem::RegisteredRunner API */
163  void create() override;
164 
165 private:
166  std::vector<Ipc::Mem::Owner<Rebuild::Stats> *> rebuildStatsOwners;
167  std::vector<SwapDir::DirMap::Owner *> mapOwners;
168  std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
169 };
170 
171 } // namespace Rock
172 
173 #endif /* SQUID_SRC_FS_ROCK_ROCKSWAPDIR_H */
174 
int64_t diskOffset(Ipc::Mem::PageId &pageId) const
Definition: RockSwapDir.cc:683
std::vector< Ipc::Mem::Owner< Ipc::Mem::PageStack > * > freeSlotsOwners
Definition: RockSwapDir.h:168
StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *) override
Definition: RockSwapDir.cc:752
void evictCached(StoreEntry &) override
@ SwapFilenMax
Definition: forward.h:26
const char * freeSlotsPath() const
DirMap * map
entry key/sfileno to MaxExtras/inode mapping
Definition: RockSwapDir.h:136
void updateHeaders(StoreEntry *e) override
make stored metadata and HTTP headers the same as in the given entry
Definition: RockSwapDir.cc:942
Definition: forward.h:27
void ioCompletedNotification() override
Definition: RockSwapDir.cc:809
unsigned char cache_key
Store key.
Definition: forward.h:29
std::vector< SwapDir::DirMap::Owner * > mapOwners
Definition: RockSwapDir.h:167
bool hasReadableEntry(const StoreEntry &) const override
whether this cache dir has an entry with e.key
uint64_t currentCount() const override
the total number of objects stored right now
Definition: RockSwapDir.cc:155
Shared memory page identifier, address, or handler.
Definition: Page.h:23
Definition: SBuf.h:93
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
all unused slots
Definition: RockSwapDir.h:145
void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor)
Definition: RockSwapDir.cc:105
void create() override
called when the runner should create a new memory segment
SBuf inodeMapPath() const
void parseSize(const bool reconfiguring)
parses anonymous cache_dir size option
Definition: RockSwapDir.cc:351
std::vector< Ipc::Mem::Owner< Rebuild::Stats > * > rebuildStatsOwners
Definition: RockSwapDir.h:166
bool unlinkdUseful() const override
whether SwapDir may benefit from unlinkd
void create() override
create system resources needed for this store to operate in the future
Definition: RockSwapDir.cc:210
void maintain() override
purge while full(); it should be sufficient to purge just one
Definition: RockSwapDir.cc:976
void handleWriteCompletionProblem(const int errflag, const WriteRequest &request)
code shared by writeCompleted() error handling cases
Definition: RockSwapDir.cc:916
void dumpTimeOption(StoreEntry *e) const
reports time-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:434
Ipc::StoreMap DirMap
Definition: RockSwapDir.h:36
bool parseSizeOption(char const *option, const char *value, int reconfiguring)
parses size-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:493
bool needsDiskStrand() const override
needs a dedicated kid process
Definition: RockSwapDir.cc:310
RefCount< DiskFile > theFile
cache storage for this cache_dir
Definition: RockSwapDir.h:144
void validateOptions()
warns of configuration problems; may quit
Definition: RockSwapDir.cc:540
uint64_t slotSize
all db slots are of this size
Definition: RockSwapDir.h:83
void reconfigure() override
Definition: RockSwapDir.cc:341
void reference(StoreEntry &e) override
somebody needs this entry (many cache replacement policies need to know)
Definition: RockSwapDir.cc:985
void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno) override
adjust slice-linked state before a locked Readable slice is erased
Definition: RockSwapDir.cc:737
ConfigOption * getOptionTree() const override
Definition: RockSwapDir.cc:368
Ipc::Mem::PageId * waitingForPage
one-page cache for a "hot" free slot
Definition: RockSwapDir.h:146
int32_t StoreMapSliceId
Definition: StoreMap.h:24
bool anchorToCache(StoreEntry &) override
Definition: RockSwapDir.cc:74
void purgeSome()
purges one or more entries to make full() false and free some slots
int64_t entryLimitActual() const
max number of possible entries in db
Definition: RockSwapDir.cc:203
DiskFile::Config fileConfig
file-level configuration options
Definition: RockSwapDir.h:149
char * path
Definition: Disk.h:102
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:397
int64_t diskOffsetLimit() const
Definition: RockSwapDir.cc:690
int reconfiguring
~SwapDirRr() override
bool smpAware() const override
whether this disk storage is capable of serving multiple workers
Definition: RockSwapDir.h:54
void createError(const char *const msg)
Definition: RockSwapDir.cc:270
void handleWriteCompletionSuccess(const WriteRequest &request)
code shared by writeCompleted() success handling cases
Definition: RockSwapDir.cc:877
StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:650
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:181
void ignoreReferences(StoreEntry &e)
delete from repl policy scope
bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const override
check whether we can store the entry; if we can, report current load
Definition: RockSwapDir.cc:582
void diskFull() override
Definition: RockSwapDir.cc:968
SlotId reserveSlotForWriting()
finds and returns a free db slot to fill or throws
Definition: RockSwapDir.cc:697
void disconnect(StoreEntry &e) override
called when the entry is about to forget its association with cache_dir
Definition: RockSwapDir.cc:119
void finalizeSwapoutFailure(StoreEntry &) override
abort the failed swapout that has been already noticed by Store
Definition: RockSwapDir.cc:178
uint64_t currentSize() const override
current size
Definition: RockSwapDir.cc:146
bool updateAnchored(StoreEntry &) override
Definition: RockSwapDir.cc:92
signed_int32_t sfileno
Definition: forward.h:22
DiskIOStrategy * io
Definition: RockSwapDir.h:143
const char * filePath
location of cache storage file inside path/
Definition: RockSwapDir.h:135
void closeCompleted() override
Definition: RockSwapDir.cc:830
void writeError(StoreIOState &sio)
Definition: RockSwapDir.cc:928
initializes shared memory segments used by Rock::SwapDir
Definition: RockSwapDir.h:155
void trackReferences(StoreEntry &e)
add to replacement policy scope
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:39
bool validSlotId(const SlotId slotId) const
whether the given slot ID may point to a slot in this db
Definition: RockSwapDir.cc:731
~SwapDir() override
Definition: RockSwapDir.cc:46
generally useful configuration options supported by some children
Definition: DiskFile.h:27
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:30
int64_t slotLimitAbsolute() const
Rock store implementation limit.
Definition: RockSwapDir.cc:185
RefCount< SwapDir > Pointer
Definition: RockSwapDir.h:35
void evictIfFound(const cache_key *) override
int64_t slotLimitActual() const
total number of slots in this db
Definition: RockSwapDir.cc:194
StoreEntry * get(const cache_key *key) override
Definition: RockSwapDir.cc:55
bool parseRateOption(char const *option, const char *value, int reconfiguring)
parses rate-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:443
int index
Definition: Disk.h:103
static const int64_t HeaderSize
on-disk db header size
Definition: RockSwapDir.h:151
void init() override
Definition: RockSwapDir.cc:279
void finalizeSwapoutSuccess(const StoreEntry &) override
finalize the successful swapout that has been already noticed by Store
Definition: RockSwapDir.cc:169
void parse(int index, char *path) override
Definition: RockSwapDir.cc:319
void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest >) override
Definition: RockSwapDir.cc:845
bool full() const
no more entries can be stored without purging
Definition: RockSwapDir.cc:960
void dumpRateOption(StoreEntry *e) const
reports rate-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:485
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *) override
Definition: RockSwapDir.cc:611
bool doReportStat() const override
Definition: RockSwapDir.cc:163
void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest >) override
Definition: RockSwapDir.cc:836
void dumpSizeOption(StoreEntry *e) const
reports size-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:533
bool parseTimeOption(char const *option, const char *value, int reconfiguring)
parses time-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:395
void statfs(StoreEntry &e) const override
bool allowOptionReconfigure(const char *const option) const override
Definition: RockSwapDir.cc:387
bool dereference(StoreEntry &e) override
Definition: RockSwapDir.cc:993

 

Introduction

Documentation

Support

Miscellaneous