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