RockSwapDir.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 "ipc/mem/Page.h"
17 #include "ipc/mem/PageStack.h"
18 #include "ipc/StoreMap.h"
19 #include "store/Disk.h"
20 #include <vector>
21 
22 class DiskIOStrategy;
23 class ReadRequest;
24 class WriteRequest;
25 
26 namespace Rock
27 {
28 
30 class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
31 {
32 public:
35 
36  SwapDir();
37  virtual ~SwapDir();
38 
39  /* public ::SwapDir API */
40  virtual void reconfigure();
41  virtual StoreEntry *get(const cache_key *key);
42  virtual void evictCached(StoreEntry &);
43  virtual void evictIfFound(const cache_key *);
44  virtual void disconnect(StoreEntry &e);
45  virtual uint64_t currentSize() const;
46  virtual uint64_t currentCount() const;
47  virtual bool doReportStat() const;
48  virtual void finalizeSwapoutSuccess(const StoreEntry &);
49  virtual void finalizeSwapoutFailure(StoreEntry &);
50  virtual void create();
51  virtual void parse(int index, char *path);
52  virtual bool smpAware() const { return true; }
53  virtual bool hasReadableEntry(const StoreEntry &) const;
54 
55  // temporary path to the shared memory map of first slots of cached entries
56  SBuf inodeMapPath() const;
57  // temporary path to the shared memory stack of free slots
58  const char *freeSlotsPath() const;
59 
60  int64_t entryLimitAbsolute() const { return SwapFilenMax+1; }
61  int64_t entryLimitActual() const;
62  int64_t slotLimitAbsolute() const;
63  int64_t slotLimitActual() const;
64 
66  bool validSlotId(const SlotId slotId) const;
67 
70 
72  void purgeSome();
73 
74  int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
75  int64_t diskOffset(int filen) const;
76  void writeError(StoreIOState &sio);
77 
78  /* StoreMapCleaner API */
79  virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
80 
81  uint64_t slotSize;
82 
83 protected:
84  /* Store API */
85  virtual bool anchorToCache(StoreEntry &entry, bool &inSync);
86  virtual bool updateAnchored(StoreEntry &);
87 
88  /* protected ::SwapDir API */
89  virtual bool needsDiskStrand() const;
90  virtual void init();
91  virtual ConfigOption *getOptionTree() const;
92  virtual bool allowOptionReconfigure(const char *const option) const;
93  virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
96  virtual void maintain();
97  virtual void diskFull();
98  virtual void reference(StoreEntry &e);
99  virtual bool dereference(StoreEntry &e);
100  virtual void updateHeaders(StoreEntry *e);
101  virtual bool unlinkdUseful() const;
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 
110  void parseSize(const bool reconfiguring);
111  void validateOptions();
112  bool parseTimeOption(char const *option, const char *value, int reconfiguring);
113  void dumpTimeOption(StoreEntry * e) const;
114  bool parseRateOption(char const *option, const char *value, int reconfiguring);
115  void dumpRateOption(StoreEntry * e) const;
116  bool parseSizeOption(char const *option, const char *value, int reconfiguring);
117  void dumpSizeOption(StoreEntry * e) const;
118 
119  void rebuild();
120 
121  bool full() const;
122  void trackReferences(StoreEntry &e);
123  void ignoreReferences(StoreEntry &e);
124 
125  int64_t diskOffsetLimit() const;
126 
129 
130  void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
132 
133  friend class Rebuild;
134  friend class IoState;
135  friend class HeaderUpdater;
136  const char *filePath;
137  DirMap *map;
138 
139 private:
140  void createError(const char *const msg);
142  void handleWriteCompletionProblem(const int errflag, const WriteRequest &request);
143 
148 
149  /* configurable options */
151 
152  static const int64_t HeaderSize;
153 };
154 
157 {
158 public:
159  /* ::RegisteredRunner API */
160  virtual ~SwapDirRr();
161 
162 protected:
163  /* Ipc::Mem::RegisteredRunner API */
164  virtual void create();
165 
166 private:
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:27
virtual void evictIfFound(const cache_key *)
virtual bool anchorToCache(StoreEntry &entry, bool &inSync)
Definition: RockSwapDir.cc:76
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:626
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
DiskFile::Config fileConfig
file-level configuration options
Definition: RockSwapDir.h:150
bool validSlotId(const SlotId slotId) const
whether the given slot ID may point to a slot in this db
Definition: RockSwapDir.cc:748
int64_t diskOffset(Ipc::Mem::PageId &pageId) const
Definition: RockSwapDir.cc:700
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:162
int64_t entryLimitAbsolute() const
Core limit.
Definition: RockSwapDir.h:60
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:769
Definition: SBuf.h:86
void dumpRateOption(StoreEntry *e) const
reports rate-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:493
unsigned char cache_key
Store key.
Definition: forward.h:29
bool full() const
no more entries can be stored without purging
Definition: RockSwapDir.cc:966
virtual bool doReportStat() const
Definition: RockSwapDir.cc:169
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
Definition: forward.h:27
RefCount< SwapDir > Pointer
Definition: RockSwapDir.h:33
virtual void evictCached(StoreEntry &)
uint64_t slotSize
all db slots are of this size
Definition: RockSwapDir.h:81
SBuf inodeMapPath() const
virtual void disconnect(StoreEntry &e)
called when the entry is about to forget its association with cache_dir
Definition: RockSwapDir.cc:126
Ipc::Mem::PageId * waitingForPage
one-page cache for a "hot" free slot
Definition: RockSwapDir.h:147
int64_t slotLimitAbsolute() const
Rock store implementation limit.
Definition: RockSwapDir.cc:188
virtual void ioCompletedNotification()
Definition: RockSwapDir.cc:817
void dumpTimeOption(StoreEntry *e) const
reports time-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:442
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:30
virtual bool smpAware() const
whether this disk storage is capable of serving multiple workers
Definition: RockSwapDir.h:52
virtual void init()
Definition: RockSwapDir.cc:282
virtual bool needsDiskStrand() const
needs a dedicated kid process
Definition: RockSwapDir.cc:318
virtual void diskFull()
Definition: RockSwapDir.cc:974
virtual void reference(StoreEntry &e)
somebody needs this entry (many cache replacement policies need to know)
Definition: RockSwapDir.cc:991
virtual ConfigOption * getOptionTree() const
Definition: RockSwapDir.cc:376
void rebuild()
starts loading and validating stored entry metadata
Definition: RockSwapDir.cc:590
SlotId reserveSlotForWriting()
finds and returns a free db slot to fill or throws
Definition: RockSwapDir.cc:714
virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest >)
Definition: RockSwapDir.cc:843
char * path
Definition: Disk.h:102
virtual void closeCompleted()
Definition: RockSwapDir.cc:837
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:358
virtual void updateHeaders(StoreEntry *e)
make stored metadata and HTTP headers the same as in the given entry
Definition: RockSwapDir.cc:948
virtual ~SwapDir()
Definition: RockSwapDir.cc:48
virtual void statfs(StoreEntry &e) const
virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const
check whether we can store the entry; if we can, report current load
Definition: RockSwapDir.cc:597
virtual void reconfigure()
Definition: RockSwapDir.cc:349
virtual void finalizeSwapoutSuccess(const StoreEntry &)
finalize the successful swapout that has been already noticed by Store
Definition: RockSwapDir.cc:175
virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno)
adjust slice-linked state before a locked Readable slice is erased
Definition: RockSwapDir.cc:754
DirMap * map
entry key/sfileno to MaxExtras/inode mapping
Definition: RockSwapDir.h:137
void parseSize(const bool reconfiguring)
parses anonymous cache_dir size option
Definition: RockSwapDir.cc:359
void writeError(StoreIOState &sio)
Definition: RockSwapDir.cc:934
void handleWriteCompletionSuccess(const WriteRequest &request)
code shared by writeCompleted() success handling cases
Definition: RockSwapDir.cc:884
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
static const int64_t HeaderSize
on-disk db header size
Definition: RockSwapDir.h:152
StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:666
int32_t StoreMapSliceId
Definition: StoreMap.h:24
void dumpSizeOption(StoreEntry *e) const
reports size-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:541
bool updateAnchoredWith(StoreEntry &, const Ipc::StoreMapAnchor &)
Definition: RockSwapDir.cc:105
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
all unused slots
Definition: RockSwapDir.h:146
virtual bool updateAnchored(StoreEntry &)
Definition: RockSwapDir.cc:93
std::vector< SwapDir::DirMap::Owner * > mapOwners
Definition: RockSwapDir.h:167
std::vector< Ipc::Mem::Owner< Ipc::Mem::PageStack > * > freeSlotsOwners
Definition: RockSwapDir.h:168
signed_int32_t sfileno
Definition: forward.h:22
void ignoreReferences(StoreEntry &e)
delete from repl policy scope
virtual bool hasReadableEntry(const StoreEntry &) const
whether this cache dir has an entry with e.key
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
void validateOptions()
warns of configuration problems; may quit
Definition: RockSwapDir.cc:548
void const char * buf
Definition: stub_helper.cc:16
virtual void create()
create system resources needed for this store to operate in the future
Definition: RockSwapDir.cc:213
int index
Definition: Disk.h:103
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:51
void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor)
Definition: RockSwapDir.cc:112
void trackReferences(StoreEntry &e)
add to replacement policy scope
const char * filePath
location of cache storage file inside path/
Definition: RockSwapDir.h:136
virtual uint64_t currentCount() const
the total number of objects stored right now
Definition: RockSwapDir.cc:161
int64_t diskOffsetLimit() const
Definition: RockSwapDir.cc:707
virtual bool dereference(StoreEntry &e)
Definition: RockSwapDir.cc:999
void purgeSome()
purges one or more entries to make full() false and free some slots
Shared memory page identifier, address, or handler.
Definition: Page.h:21
const char * freeSlotsPath() const
void createError(const char *const msg)
Definition: RockSwapDir.cc:273
virtual uint64_t currentSize() const
current size
Definition: RockSwapDir.cc:152
virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest >)
Definition: RockSwapDir.cc:852
void handleWriteCompletionProblem(const int errflag, const WriteRequest &request)
code shared by writeCompleted() error handling cases
Definition: RockSwapDir.cc:922
RefCount< DiskFile > theFile
cache storage for this cache_dir
Definition: RockSwapDir.h:145
int64_t entryLimitActual() const
max number of possible entries in db
Definition: RockSwapDir.cc:206
int64_t slotLimitActual() const
total number of slots in this db
Definition: RockSwapDir.cc:197
bool parseRateOption(char const *option, const char *value, int reconfiguring)
parses rate-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:451
virtual bool allowOptionReconfigure(const char *const option) const
Definition: RockSwapDir.cc:395
Ipc::StoreMap DirMap
Definition: RockSwapDir.h:34
virtual void maintain()
purge while full(); it should be sufficient to purge just one
Definition: RockSwapDir.cc:982
virtual void finalizeSwapoutFailure(StoreEntry &)
abort the failed swapout that has been already noticed by Store
Definition: RockSwapDir.cc:181
DiskIOStrategy * io
Definition: RockSwapDir.h:144
bool parseSizeOption(char const *option, const char *value, int reconfiguring)
parses size-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:501
initializes shared memory segments used by Rock::SwapDir
Definition: RockSwapDir.h:156
int reconfiguring
virtual bool unlinkdUseful() const
whether SwapDir may benefit from unlinkd
virtual void parse(int index, char *path)
Definition: RockSwapDir.cc:327
bool parseTimeOption(char const *option, const char *value, int reconfiguring)
parses time-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:403

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors