RockSwapDir.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 markForUnlink(StoreEntry &e);
43  virtual void disconnect(StoreEntry &e);
44  virtual uint64_t currentSize() const;
45  virtual uint64_t currentCount() const;
46  virtual bool doReportStat() const;
47  virtual void swappedOut(const StoreEntry &e);
48  virtual void create();
49  virtual void parse(int index, char *path);
50  virtual bool smpAware() const { return true; }
51 
52  // temporary path to the shared memory map of first slots of cached entries
53  SBuf inodeMapPath() const;
54  // temporary path to the shared memory stack of free slots
55  const char *freeSlotsPath() const;
56 
57  int64_t entryLimitAbsolute() const { return SwapFilenMax+1; }
58  int64_t entryLimitActual() const;
59  int64_t slotLimitAbsolute() const;
60  int64_t slotLimitActual() const;
61 
63  bool useFreeSlot(Ipc::Mem::PageId &pageId);
65  bool validSlotId(const SlotId slotId) const;
67  void purgeSome();
68 
69  int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
70  int64_t diskOffset(int filen) const;
71  void writeError(StoreIOState &sio);
72 
73  /* StoreMapCleaner API */
74  virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
75 
76  uint64_t slotSize;
77 
78 protected:
79  /* Store API */
80  virtual bool anchorCollapsed(StoreEntry &collapsed, bool &inSync);
81  virtual bool updateCollapsed(StoreEntry &collapsed);
82 
83  /* protected ::SwapDir API */
84  virtual bool needsDiskStrand() const;
85  virtual void init();
86  virtual ConfigOption *getOptionTree() const;
87  virtual bool allowOptionReconfigure(const char *const option) const;
88  virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
91  virtual void maintain();
92  virtual void diskFull();
93  virtual void reference(StoreEntry &e);
94  virtual bool dereference(StoreEntry &e);
95  virtual void updateHeaders(StoreEntry *e);
96  virtual bool unlinkdUseful() const;
97  virtual void unlink(StoreEntry &e);
98  virtual void statfs(StoreEntry &e) const;
99 
100  /* IORequestor API */
101  virtual void ioCompletedNotification();
102  virtual void closeCompleted();
103  virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
104  virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
105 
106  void parseSize(const bool reconfiguring);
107  void validateOptions();
108  bool parseTimeOption(char const *option, const char *value, int reconfiguring);
109  void dumpTimeOption(StoreEntry * e) const;
110  bool parseRateOption(char const *option, const char *value, int reconfiguring);
111  void dumpRateOption(StoreEntry * e) const;
112  bool parseSizeOption(char const *option, const char *value, int reconfiguring);
113  void dumpSizeOption(StoreEntry * e) const;
114 
115  void rebuild();
116 
117  bool full() const;
118  void trackReferences(StoreEntry &e);
119  void ignoreReferences(StoreEntry &e);
120 
121  int64_t diskOffsetLimit() const;
122 
125 
126  void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
127  bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor);
128 
129  friend class Rebuild;
130  friend class IoState;
131  friend class HeaderUpdater;
132  const char *filePath;
134 
135 private:
136  void createError(const char *const msg);
137 
142 
143  /* configurable options */
145 
146  static const int64_t HeaderSize;
147 };
148 
151 {
152 public:
153  /* ::RegisteredRunner API */
154  virtual ~SwapDirRr();
155 
156 protected:
157  /* Ipc::Mem::RegisteredRunner API */
158  virtual void create();
159 
160 private:
161  std::vector<SwapDir::DirMap::Owner *> mapOwners;
162  std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
163 };
164 
165 } // namespace Rock
166 
167 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */
168 
virtual bool doReportStat() const
Definition: RockSwapDir.cc:195
virtual bool needsDiskStrand() const
needs a dedicated kid process
Definition: RockSwapDir.cc:337
virtual ~SwapDirRr()
generally useful configuration options supported by some children
Definition: DiskFile.h:27
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:645
virtual bool smpAware() const
Definition: RockSwapDir.h:50
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
DiskFile::Config fileConfig
file-level configuration options
Definition: RockSwapDir.h:144
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:146
bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor)
Definition: RockSwapDir.cc:110
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:778
Definition: SBuf.h:87
unsigned char cache_key
Store key.
Definition: forward.h:29
RefCount< SwapDir > Pointer
Definition: RockSwapDir.h:33
void dumpRateOption(StoreEntry *e) const
reports rate-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:512
uint64_t slotSize
all db slots are of this size
Definition: RockSwapDir.h:76
virtual void disconnect(StoreEntry &e)
called when the entry is about to forget its association with cache_dir
Definition: RockSwapDir.cc:147
Ipc::Mem::PageId * waitingForPage
one-page cache for a "hot" free slot
Definition: RockSwapDir.h:141
virtual void ioCompletedNotification()
Definition: RockSwapDir.cc:826
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:30
virtual bool unlinkdUseful() const
whether SwapDir may benefit from unlinkd
Definition: RockSwapDir.cc:995
virtual void unlink(StoreEntry &e)
remove the entry from the store
bool validSlotId(const SlotId slotId) const
whether the given slot ID may point to a slot in this db
Definition: RockSwapDir.cc:757
virtual void init()
Definition: RockSwapDir.cc:301
virtual bool anchorCollapsed(StoreEntry &collapsed, bool &inSync)
Definition: RockSwapDir.cc:79
virtual void diskFull()
Definition: RockSwapDir.cc:959
int64_t slotLimitAbsolute() const
Rock store implementation limit.
Definition: RockSwapDir.cc:207
virtual void reference(StoreEntry &e)
somebody needs this entry (many cache replacement policies need to know)
Definition: RockSwapDir.cc:976
void rebuild()
starts loading and validating stored entry metadata
Definition: RockSwapDir.cc:609
virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest >)
Definition: RockSwapDir.cc:852
char * path
Definition: Disk.h:96
virtual void closeCompleted()
Definition: RockSwapDir.cc:846
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:329
void dumpSizeOption(StoreEntry *e) const
reports size-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:560
virtual void updateHeaders(StoreEntry *e)
make stored metadata and HTTP headers the same as in the given entry
Definition: RockSwapDir.cc:933
virtual ~SwapDir()
Definition: RockSwapDir.cc:48
virtual void reconfigure()
Definition: RockSwapDir.cc:368
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:616
virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno)
adjust slice-linked state before a locked Readable slice is erased
Definition: RockSwapDir.cc:763
DirMap * map
entry key/sfileno to MaxExtras/inode mapping
Definition: RockSwapDir.h:133
void parseSize(const bool reconfiguring)
parses anonymous cache_dir size option
Definition: RockSwapDir.cc:378
void writeError(StoreIOState &sio)
Definition: RockSwapDir.cc:919
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:146
StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:685
int32_t StoreMapSliceId
Definition: StoreMap.h:24
int64_t diskOffsetLimit() const
Definition: RockSwapDir.cc:726
void dumpTimeOption(StoreEntry *e) const
reports time-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:461
virtual ConfigOption * getOptionTree() const
Definition: RockSwapDir.cc:395
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
all unused slots
Definition: RockSwapDir.h:140
std::vector< SwapDir::DirMap::Owner * > mapOwners
Definition: RockSwapDir.h:161
int64_t diskOffset(Ipc::Mem::PageId &pageId) const
Definition: RockSwapDir.cc:719
std::vector< Ipc::Mem::Owner< Ipc::Mem::PageStack > * > freeSlotsOwners
Definition: RockSwapDir.h:162
signed_int32_t sfileno
Definition: forward.h:22
bool useFreeSlot(Ipc::Mem::PageId &pageId)
removes a slot from a list of free slots or returns false
Definition: RockSwapDir.cc:733
void ignoreReferences(StoreEntry &e)
delete from repl policy scope
virtual bool allowOptionReconfigure(const char *const option) const
Definition: RockSwapDir.cc:414
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:567
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:232
virtual uint64_t currentSize() const
current size
Definition: RockSwapDir.cc:178
int index
Definition: Disk.h:97
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:117
void trackReferences(StoreEntry &e)
add to replacement policy scope
const char * freeSlotsPath() const
int64_t entryLimitActual() const
max number of possible entries in db
Definition: RockSwapDir.cc:225
virtual uint64_t currentCount() const
the total number of objects stored right now
Definition: RockSwapDir.cc:187
const char * filePath
location of cache storage file inside path/
Definition: RockSwapDir.h:132
virtual bool dereference(StoreEntry &e)
Definition: RockSwapDir.cc:984
int64_t slotLimitActual() const
total number of slots in this db
Definition: RockSwapDir.cc:216
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
void createError(const char *const msg)
Definition: RockSwapDir.cc:292
void const cache_key * key
SBuf inodeMapPath() const
virtual void swappedOut(const StoreEntry &e)
called when entry swap out is complete
Definition: RockSwapDir.cc:201
virtual void markForUnlink(StoreEntry &e)
expect an unlink() call after the entry becomes idle
virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest >)
Definition: RockSwapDir.cc:865
RefCount< DiskFile > theFile
cache storage for this cache_dir
Definition: RockSwapDir.h:139
virtual bool updateCollapsed(StoreEntry &collapsed)
Definition: RockSwapDir.cc:96
bool parseRateOption(char const *option, const char *value, int reconfiguring)
parses rate-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:470
Ipc::StoreMap DirMap
Definition: RockSwapDir.h:34
virtual void statfs(StoreEntry &e) const
virtual void create()
called when the runner should create a new memory segment
virtual void maintain()
purge while full(); it should be sufficient to purge just one
Definition: RockSwapDir.cc:967
bool full() const
no more entries can be stored without purging
Definition: RockSwapDir.cc:951
DiskIOStrategy * io
Definition: RockSwapDir.h:138
bool parseSizeOption(char const *option, const char *value, int reconfiguring)
parses size-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:520
initializes shared memory segments used by Rock::SwapDir
Definition: RockSwapDir.h:150
int reconfiguring
int64_t entryLimitAbsolute() const
Core limit.
Definition: RockSwapDir.h:57
virtual void parse(int index, char *path)
Definition: RockSwapDir.cc:346
bool parseTimeOption(char const *option, const char *value, int reconfiguring)
parses time-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:422

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors