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