]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
e2851fe7 AR |
9 | #ifndef SQUID_FS_ROCK_SWAP_DIR_H |
10 | #define SQUID_FS_ROCK_SWAP_DIR_H | |
11 | ||
43ebbac3 | 12 | #include "DiskIO/DiskFile.h" |
e2851fe7 | 13 | #include "DiskIO/IORequestor.h" |
aac0df40 | 14 | #include "fs/rock/forward.h" |
fcd789da | 15 | #include "fs/rock/RockDbCell.h" |
93910d5c AR |
16 | #include "ipc/mem/Page.h" |
17 | #include "ipc/mem/PageStack.h" | |
9d4e9cfb | 18 | #include "ipc/StoreMap.h" |
2745fea5 | 19 | #include "store/Disk.h" |
d8a6ec7f | 20 | #include <vector> |
e2851fe7 AR |
21 | |
22 | class DiskIOStrategy; | |
e2851fe7 AR |
23 | class ReadRequest; |
24 | class WriteRequest; | |
25 | ||
9199139f AR |
26 | namespace Rock |
27 | { | |
e2851fe7 | 28 | |
e2851fe7 | 29 | /// \ingroup Rock |
93910d5c | 30 | class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner |
e2851fe7 AR |
31 | { |
32 | public: | |
50dc81ec AR |
33 | typedef RefCount<SwapDir> Pointer; |
34 | typedef Ipc::StoreMap DirMap; | |
35 | ||
e2851fe7 AR |
36 | SwapDir(); |
37 | virtual ~SwapDir(); | |
38 | ||
39 | /* public ::SwapDir API */ | |
c6059970 | 40 | virtual void reconfigure(); |
44def0f9 | 41 | virtual StoreEntry *get(const cache_key *key); |
4310f8b0 EB |
42 | virtual void evictCached(StoreEntry &); |
43 | virtual void evictIfFound(const cache_key *); | |
f58bb2f4 | 44 | virtual void disconnect(StoreEntry &e); |
39c1e1d9 DK |
45 | virtual uint64_t currentSize() const; |
46 | virtual uint64_t currentCount() const; | |
47 | virtual bool doReportStat() const; | |
4310f8b0 EB |
48 | virtual void finalizeSwapoutSuccess(const StoreEntry &); |
49 | virtual void finalizeSwapoutFailure(StoreEntry &); | |
9bb01611 AR |
50 | virtual void create(); |
51 | virtual void parse(int index, char *path); | |
1a210de4 | 52 | virtual bool smpAware() const { return true; } |
4310f8b0 | 53 | virtual bool hasReadableEntry(const StoreEntry &) const; |
6d8d05b5 | 54 | |
300fd297 | 55 | // temporary path to the shared memory map of first slots of cached entries |
1860fbac | 56 | SBuf inodeMapPath() const; |
300fd297 | 57 | // temporary path to the shared memory stack of free slots |
50dc81ec | 58 | const char *freeSlotsPath() const; |
300fd297 | 59 | |
36c84e19 AR |
60 | int64_t entryLimitAbsolute() const { return SwapFilenMax+1; } ///< Core limit |
61 | int64_t entryLimitActual() const; ///< max number of possible entries in db | |
62 | int64_t slotLimitAbsolute() const; ///< Rock store implementation limit | |
63 | int64_t slotLimitActual() const; ///< total number of slots in this db | |
b3165da6 | 64 | |
50dc81ec AR |
65 | /// whether the given slot ID may point to a slot in this db |
66 | bool validSlotId(const SlotId slotId) const; | |
c2037547 EB |
67 | |
68 | /// finds and returns a free db slot to fill or throws | |
69 | SlotId reserveSlotForWriting(); | |
70 | ||
50dc81ec AR |
71 | /// purges one or more entries to make full() false and free some slots |
72 | void purgeSome(); | |
93910d5c AR |
73 | |
74 | int64_t diskOffset(Ipc::Mem::PageId &pageId) const; | |
50dc81ec | 75 | int64_t diskOffset(int filen) const; |
abf396ec | 76 | void writeError(StoreIOState &sio); |
93910d5c | 77 | |
50dc81ec | 78 | /* StoreMapCleaner API */ |
36c84e19 | 79 | virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno); |
902df398 | 80 | |
e51ce7da AR |
81 | uint64_t slotSize; ///< all db slots are of this size |
82 | ||
e2851fe7 | 83 | protected: |
ce49546e | 84 | /* Store API */ |
4310f8b0 EB |
85 | virtual bool anchorToCache(StoreEntry &entry, bool &inSync); |
86 | virtual bool updateAnchored(StoreEntry &); | |
ce49546e | 87 | |
e2851fe7 | 88 | /* protected ::SwapDir API */ |
14911a4e | 89 | virtual bool needsDiskStrand() const; |
e2851fe7 | 90 | virtual void init(); |
43ebbac3 | 91 | virtual ConfigOption *getOptionTree() const; |
24063512 | 92 | virtual bool allowOptionReconfigure(const char *const option) const; |
c728b6f9 | 93 | virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const; |
e2851fe7 AR |
94 | virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *); |
95 | virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *); | |
96 | virtual void maintain(); | |
e2851fe7 AR |
97 | virtual void diskFull(); |
98 | virtual void reference(StoreEntry &e); | |
2745fea5 | 99 | virtual bool dereference(StoreEntry &e); |
abf396ec | 100 | virtual void updateHeaders(StoreEntry *e); |
c521ad17 | 101 | virtual bool unlinkdUseful() const; |
e2851fe7 AR |
102 | virtual void statfs(StoreEntry &e) const; |
103 | ||
104 | /* IORequestor API */ | |
105 | virtual void ioCompletedNotification(); | |
106 | virtual void closeCompleted(); | |
107 | virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>); | |
108 | virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>); | |
109 | ||
24063512 | 110 | void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option |
e2851fe7 | 111 | void validateOptions(); ///< warns of configuration problems; may quit |
43ebbac3 AR |
112 | bool parseTimeOption(char const *option, const char *value, int reconfiguring); |
113 | void dumpTimeOption(StoreEntry * e) const; | |
df881a0f AR |
114 | bool parseRateOption(char const *option, const char *value, int reconfiguring); |
115 | void dumpRateOption(StoreEntry * e) const; | |
e51ce7da AR |
116 | bool parseSizeOption(char const *option, const char *value, int reconfiguring); |
117 | void dumpSizeOption(StoreEntry * e) const; | |
e2851fe7 AR |
118 | |
119 | void rebuild(); ///< starts loading and validating stored entry metadata | |
e2851fe7 AR |
120 | |
121 | bool full() const; ///< no more entries can be stored without purging | |
122 | void trackReferences(StoreEntry &e); ///< add to replacement policy scope | |
123 | void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope | |
124 | ||
e2851fe7 | 125 | int64_t diskOffsetLimit() const; |
e2851fe7 | 126 | |
abf396ec AR |
127 | void updateHeadersOrThrow(Ipc::StoreMapUpdate &update); |
128 | StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *); | |
129 | ||
ce49546e | 130 | void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor); |
4310f8b0 | 131 | bool updateAnchoredWith(StoreEntry &, const Ipc::StoreMapAnchor &); |
ce49546e | 132 | |
e2851fe7 | 133 | friend class Rebuild; |
50dc81ec | 134 | friend class IoState; |
abf396ec | 135 | friend class HeaderUpdater; |
e2851fe7 | 136 | const char *filePath; ///< location of cache storage file inside path/ |
50dc81ec | 137 | DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping |
e2851fe7 AR |
138 | |
139 | private: | |
413f00bd | 140 | void createError(const char *const msg); |
a12f1a4c EB |
141 | void handleWriteCompletionSuccess(const WriteRequest &request); |
142 | void handleWriteCompletionProblem(const int errflag, const WriteRequest &request); | |
413f00bd | 143 | |
e2851fe7 AR |
144 | DiskIOStrategy *io; |
145 | RefCount<DiskFile> theFile; ///< cache storage for this cache_dir | |
6d68a230 AR |
146 | Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< all unused slots |
147 | Ipc::Mem::PageId *waitingForPage; ///< one-page cache for a "hot" free slot | |
b3165da6 | 148 | |
43ebbac3 AR |
149 | /* configurable options */ |
150 | DiskFile::Config fileConfig; ///< file-level configuration options | |
151 | ||
b3165da6 | 152 | static const int64_t HeaderSize; ///< on-disk db header size |
e2851fe7 AR |
153 | }; |
154 | ||
9bb01611 AR |
155 | /// initializes shared memory segments used by Rock::SwapDir |
156 | class SwapDirRr: public Ipc::Mem::RegisteredRunner | |
157 | { | |
158 | public: | |
159 | /* ::RegisteredRunner API */ | |
160 | virtual ~SwapDirRr(); | |
161 | ||
162 | protected: | |
163 | /* Ipc::Mem::RegisteredRunner API */ | |
21b7990f | 164 | virtual void create(); |
9bb01611 AR |
165 | |
166 | private: | |
cfb88efb AR |
167 | std::vector<SwapDir::DirMap::Owner *> mapOwners; |
168 | std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners; | |
9bb01611 AR |
169 | }; |
170 | ||
e2851fe7 AR |
171 | } // namespace Rock |
172 | ||
173 | #endif /* SQUID_FS_ROCK_SWAP_DIR_H */ | |
f53969cc | 174 |