RockSwapDir.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_SWAP_DIR_H
10#define SQUID_FS_ROCK_SWAP_DIR_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
24class DiskIOStrategy;
25class ReadRequest;
26class WriteRequest;
27
28namespace Rock
29{
30
33{
34public:
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
85protected:
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);
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
138private:
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;
152};
153
156{
157public:
158 /* ::RegisteredRunner API */
159 ~SwapDirRr() override;
160
161protected:
162 /* Ipc::Mem::RegisteredRunner API */
163 void create() override;
164
165private:
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_FS_ROCK_SWAP_DIR_H */
174
generally useful configuration options supported by some children
Definition: DiskFile.h:28
Shared memory page identifier, address, or handler.
Definition: Page.h:24
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:398
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:182
initializes shared memory segments used by Rock::SwapDir
Definition: RockSwapDir.h:156
~SwapDirRr() override
void create() override
called when the runner should create a new memory segment
std::vector< SwapDir::DirMap::Owner * > mapOwners
Definition: RockSwapDir.h:167
std::vector< Ipc::Mem::Owner< Rebuild::Stats > * > rebuildStatsOwners
Definition: RockSwapDir.h:166
std::vector< Ipc::Mem::Owner< Ipc::Mem::PageStack > * > freeSlotsOwners
Definition: RockSwapDir.h:168
int64_t slotLimitAbsolute() const
Rock store implementation limit.
Definition: RockSwapDir.cc:186
void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest >) override
Definition: RockSwapDir.cc:840
void handleWriteCompletionProblem(const int errflag, const WriteRequest &request)
code shared by writeCompleted() error handling cases
Definition: RockSwapDir.cc:920
int64_t slotLimitActual() const
total number of slots in this db
Definition: RockSwapDir.cc:195
void dumpSizeOption(StoreEntry *e) const
reports size-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:534
uint64_t slotSize
all db slots are of this size
Definition: RockSwapDir.h:83
bool doReportStat() const override
Definition: RockSwapDir.cc:164
StoreEntry * get(const cache_key *key) override
Definition: RockSwapDir.cc:56
int64_t diskOffset(int filen) const
void updateHeaders(StoreEntry *e) override
make stored metadata and HTTP headers the same as in the given entry
Definition: RockSwapDir.cc:946
bool anchorToCache(StoreEntry &) override
Definition: RockSwapDir.cc:75
SBuf inodeMapPath() const
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
all unused slots
Definition: RockSwapDir.h:145
bool allowOptionReconfigure(const char *const option) const override
Definition: RockSwapDir.cc:388
void reconfigure() override
Definition: RockSwapDir.cc:342
void disconnect(StoreEntry &e) override
called when the entry is about to forget its association with cache_dir
Definition: RockSwapDir.cc:120
DiskFile::Config fileConfig
file-level configuration options
Definition: RockSwapDir.h:149
void parseSize(const bool reconfiguring)
parses anonymous cache_dir size option
Definition: RockSwapDir.cc:352
ConfigOption * getOptionTree() const override
Definition: RockSwapDir.cc:369
bool parseTimeOption(char const *option, const char *value, int reconfiguring)
parses time-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:396
void validateOptions()
warns of configuration problems; may quit
Definition: RockSwapDir.cc:541
const char * filePath
location of cache storage file inside path/
Definition: RockSwapDir.h:135
RefCount< DiskFile > theFile
cache storage for this cache_dir
Definition: RockSwapDir.h:144
void handleWriteCompletionSuccess(const WriteRequest &request)
code shared by writeCompleted() success handling cases
Definition: RockSwapDir.cc:881
void init() override
Definition: RockSwapDir.cc:280
~SwapDir() override
Definition: RockSwapDir.cc:47
bool parseRateOption(char const *option, const char *value, int reconfiguring)
parses rate-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:444
void purgeSome()
purges one or more entries to make full() false and free some slots
bool unlinkdUseful() const override
whether SwapDir may benefit from unlinkd
const char * freeSlotsPath() const
bool full() const
no more entries can be stored without purging
Definition: RockSwapDir.cc:964
StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *) override
Definition: RockSwapDir.cc:612
void evictCached(StoreEntry &) override
void finalizeSwapoutSuccess(const StoreEntry &) override
finalize the successful swapout that has been already noticed by Store
Definition: RockSwapDir.cc:170
int64_t diskOffset(Ipc::Mem::PageId &pageId) const
Definition: RockSwapDir.cc:686
static const int64_t HeaderSize
on-disk db header size
Definition: RockSwapDir.h:151
bool updateAnchored(StoreEntry &) override
Definition: RockSwapDir.cc:93
bool dereference(StoreEntry &e) override
Definition: RockSwapDir.cc:997
int64_t entryLimitAbsolute() const
Core limit.
Definition: RockSwapDir.h:62
bool hasReadableEntry(const StoreEntry &) const override
whether this cache dir has an entry with e.key
void reference(StoreEntry &e) override
somebody needs this entry (many cache replacement policies need to know)
Definition: RockSwapDir.cc:989
void diskFull() override
Definition: RockSwapDir.cc:972
void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest >) override
Definition: RockSwapDir.cc:849
bool needsDiskStrand() const override
needs a dedicated kid process
Definition: RockSwapDir.cc:311
bool validSlotId(const SlotId slotId) const
whether the given slot ID may point to a slot in this db
Definition: RockSwapDir.cc:734
void ignoreReferences(StoreEntry &e)
delete from repl policy scope
Ipc::StoreMap DirMap
Definition: RockSwapDir.h:36
DiskIOStrategy * io
Definition: RockSwapDir.h:143
void finalizeSwapoutFailure(StoreEntry &) override
abort the failed swapout that has been already noticed by Store
Definition: RockSwapDir.cc:179
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:583
DirMap * map
entry key/sfileno to MaxExtras/inode mapping
Definition: RockSwapDir.h:136
void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno) override
adjust slice-linked state before a locked Readable slice is erased
Definition: RockSwapDir.cc:740
uint64_t currentCount() const override
the total number of objects stored right now
Definition: RockSwapDir.cc:156
int64_t diskOffsetLimit() const
Definition: RockSwapDir.cc:693
bool smpAware() const override
whether this disk storage is capable of serving multiple workers
Definition: RockSwapDir.h:54
void trackReferences(StoreEntry &e)
add to replacement policy scope
StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STIOCB *, void *) override
Definition: RockSwapDir.cc:755
void closeCompleted() override
Definition: RockSwapDir.cc:834
Ipc::Mem::PageId * waitingForPage
one-page cache for a "hot" free slot
Definition: RockSwapDir.h:146
void maintain() override
purge while full(); it should be sufficient to purge just one
Definition: RockSwapDir.cc:980
void dumpRateOption(StoreEntry *e) const
reports rate-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:486
void createError(const char *const msg)
Definition: RockSwapDir.cc:271
void ioCompletedNotification() override
Definition: RockSwapDir.cc:813
StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:652
void parse(int index, char *path) override
Definition: RockSwapDir.cc:320
void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor)
Definition: RockSwapDir.cc:106
void dumpTimeOption(StoreEntry *e) const
reports time-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:435
void writeError(StoreIOState &sio)
Definition: RockSwapDir.cc:932
uint64_t currentSize() const override
current size
Definition: RockSwapDir.cc:147
bool parseSizeOption(char const *option, const char *value, int reconfiguring)
parses size-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:494
SlotId reserveSlotForWriting()
finds and returns a free db slot to fill or throws
Definition: RockSwapDir.cc:700
int64_t entryLimitActual() const
max number of possible entries in db
Definition: RockSwapDir.cc:204
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
RefCount< SwapDir > Pointer
Definition: RockSwapDir.h:35
void create() override
create system resources needed for this store to operate in the future
Definition: RockSwapDir.cc:211
void evictIfFound(const cache_key *) override
void statfs(StoreEntry &e) const override
Definition: SBuf.h:94
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:39
manages a single cache_dir
Definition: Disk.h:22
char * path
Definition: Disk.h:102
int index
Definition: Disk.h:103
int reconfiguring
int32_t StoreMapSliceId
Definition: StoreMap.h:24
Definition: forward.h:28
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:33
@ SwapFilenMax
Definition: forward.h:26
unsigned char cache_key
Store key.
Definition: forward.h:29
signed_int32_t sfileno
Definition: forward.h:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors