]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/rock/RockSwapDir.h
Support "appending" read/write lock state that can be shared by readers
[thirdparty/squid.git] / src / fs / rock / RockSwapDir.h
1 #ifndef SQUID_FS_ROCK_SWAP_DIR_H
2 #define SQUID_FS_ROCK_SWAP_DIR_H
3
4 #include "SwapDir.h"
5 #include "DiskIO/DiskFile.h"
6 #include "DiskIO/IORequestor.h"
7 #include "fs/rock/RockDbCell.h"
8 #include "fs/rock/RockForward.h"
9 #include "ipc/StoreMap.h"
10 #include "ipc/mem/Page.h"
11 #include "ipc/mem/PageStack.h"
12
13 class DiskIOStrategy;
14 class ReadRequest;
15 class WriteRequest;
16
17 namespace Rock
18 {
19
20 /// \ingroup Rock
21 class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
22 {
23 public:
24 typedef RefCount<SwapDir> Pointer;
25 typedef Ipc::StoreMap DirMap;
26
27 SwapDir();
28 virtual ~SwapDir();
29
30 /* public ::SwapDir API */
31 virtual void reconfigure();
32 virtual StoreSearch *search(String const url, HttpRequest *);
33 virtual StoreEntry *get(const cache_key *key);
34 virtual void get(String const, STOREGETCLIENT, void * cbdata);
35 virtual void disconnect(StoreEntry &e);
36 virtual uint64_t currentSize() const;
37 virtual uint64_t currentCount() const;
38 virtual bool doReportStat() const;
39 virtual void swappedOut(const StoreEntry &e);
40 virtual void create();
41 virtual void parse(int index, char *path);
42
43 // temporary path to the shared memory map of first slots of cached entries
44 const char *inodeMapPath() const;
45 // temporary path to the shared memory stack of free slots
46 const char *freeSlotsPath() const;
47
48 int64_t entryLimitHigh() const { return SwapFilenMax; } ///< Core limit
49 int64_t entryLimitAllowed() const;
50
51 /// removes a slot from a list of free slots or returns false
52 bool useFreeSlot(Ipc::Mem::PageId &pageId);
53 /// whether the given slot ID may point to a slot in this db
54 bool validSlotId(const SlotId slotId) const;
55 /// purges one or more entries to make full() false and free some slots
56 void purgeSome();
57
58 int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
59 int64_t diskOffset(int filen) const;
60 void writeError(const sfileno fileno);
61
62 /* StoreMapCleaner API */
63 virtual void noteFreeMapSlice(const sfileno fileno);
64
65 uint64_t slotSize; ///< all db slots are of this size
66
67 protected:
68 /* Store API */
69 virtual bool anchorCollapsed(StoreEntry &collapsed);
70 virtual bool updateCollapsed(StoreEntry &collapsed);
71
72 /* protected ::SwapDir API */
73 virtual bool needsDiskStrand() const;
74 virtual void init();
75 virtual ConfigOption *getOptionTree() const;
76 virtual bool allowOptionReconfigure(const char *const option) const;
77 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
78 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
79 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
80 virtual void maintain();
81 virtual void diskFull();
82 virtual void reference(StoreEntry &e);
83 virtual bool dereference(StoreEntry &e, bool);
84 virtual bool unlinkdUseful() const;
85 virtual void unlink(StoreEntry &e);
86 virtual void statfs(StoreEntry &e) const;
87
88 /* IORequestor API */
89 virtual void ioCompletedNotification();
90 virtual void closeCompleted();
91 virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
92 virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
93
94 void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option
95 void validateOptions(); ///< warns of configuration problems; may quit
96 bool parseTimeOption(char const *option, const char *value, int reconfiguring);
97 void dumpTimeOption(StoreEntry * e) const;
98 bool parseRateOption(char const *option, const char *value, int reconfiguring);
99 void dumpRateOption(StoreEntry * e) const;
100 bool parseSizeOption(char const *option, const char *value, int reconfiguring);
101 void dumpSizeOption(StoreEntry * e) const;
102
103 void rebuild(); ///< starts loading and validating stored entry metadata
104
105 bool full() const; ///< no more entries can be stored without purging
106 void trackReferences(StoreEntry &e); ///< add to replacement policy scope
107 void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
108
109 int64_t diskOffsetLimit() const;
110 int entryLimit() const { return map->entryLimit(); }
111 int entryMaxPayloadSize() const;
112 int entriesNeeded(const int64_t objSize) const;
113
114 void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
115 bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor);
116
117 friend class Rebuild;
118 friend class IoState;
119 const char *filePath; ///< location of cache storage file inside path/
120 DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping
121
122 private:
123 void createError(const char *const msg);
124
125 DiskIOStrategy *io;
126 RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
127 Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< all unused slots
128 Ipc::Mem::PageId *waitingForPage; ///< one-page cache for a "hot" free slot
129
130 /* configurable options */
131 DiskFile::Config fileConfig; ///< file-level configuration options
132
133 static const int64_t HeaderSize; ///< on-disk db header size
134 };
135
136 /// initializes shared memory segments used by Rock::SwapDir
137 class SwapDirRr: public Ipc::Mem::RegisteredRunner
138 {
139 public:
140 /* ::RegisteredRunner API */
141 virtual ~SwapDirRr();
142
143 protected:
144 /* Ipc::Mem::RegisteredRunner API */
145 virtual void create(const RunnerRegistry &);
146
147 private:
148 Vector<SwapDir::DirMap::Owner *> mapOwners;
149 Vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
150 };
151
152 } // namespace Rock
153
154 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */