RockSwapDir.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 "fs/rock/RockRebuild.h"
17 #include "ipc/mem/Page.h"
18 #include "ipc/mem/PageStack.h"
19 #include "ipc/StoreMap.h"
20 #include "store/Disk.h"
21 #include "store_rebuild.h"
22 #include <vector>
23 
24 class DiskIOStrategy;
25 class ReadRequest;
26 class WriteRequest;
27 
28 namespace Rock
29 {
30 
32 class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
33 {
34 public:
37 
38  SwapDir();
39  virtual ~SwapDir();
40 
41  /* public ::SwapDir API */
42  virtual void reconfigure();
43  virtual StoreEntry *get(const cache_key *key);
44  virtual void evictCached(StoreEntry &);
45  virtual void evictIfFound(const cache_key *);
46  virtual void disconnect(StoreEntry &e);
47  virtual uint64_t currentSize() const;
48  virtual uint64_t currentCount() const;
49  virtual bool doReportStat() const;
50  virtual void finalizeSwapoutSuccess(const StoreEntry &);
51  virtual void finalizeSwapoutFailure(StoreEntry &);
52  virtual void create();
53  virtual void parse(int index, char *path);
54  virtual bool smpAware() const { return true; }
55  virtual bool hasReadableEntry(const StoreEntry &) const;
56 
57  // temporary path to the shared memory map of first slots of cached entries
58  SBuf inodeMapPath() const;
59  // temporary path to the shared memory stack of free slots
60  const char *freeSlotsPath() const;
61 
62  int64_t entryLimitAbsolute() const { return SwapFilenMax+1; }
63  int64_t entryLimitActual() const;
64  int64_t slotLimitAbsolute() const;
65  int64_t slotLimitActual() const;
66 
68  bool validSlotId(const SlotId slotId) const;
69 
72 
74  void purgeSome();
75 
76  int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
77  int64_t diskOffset(int filen) const;
78  void writeError(StoreIOState &sio);
79 
80  /* StoreMapCleaner API */
81  virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
82 
83  uint64_t slotSize;
84 
85 protected:
86  /* Store API */
87  virtual bool anchorToCache(StoreEntry &entry, bool &inSync);
88  virtual bool updateAnchored(StoreEntry &);
89 
90  /* protected ::SwapDir API */
91  virtual bool needsDiskStrand() const;
92  virtual void init();
93  virtual ConfigOption *getOptionTree() const;
94  virtual bool allowOptionReconfigure(const char *const option) const;
95  virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
98  virtual void maintain();
99  virtual void diskFull();
100  virtual void reference(StoreEntry &e);
101  virtual bool dereference(StoreEntry &e);
102  virtual void updateHeaders(StoreEntry *e);
103  virtual bool unlinkdUseful() const;
104  virtual void statfs(StoreEntry &e) const;
105 
106  /* IORequestor API */
107  virtual void ioCompletedNotification();
108  virtual void closeCompleted();
109  virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
110  virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
111 
112  void parseSize(const bool reconfiguring);
113  void validateOptions();
114  bool parseTimeOption(char const *option, const char *value, int reconfiguring);
115  void dumpTimeOption(StoreEntry * e) const;
116  bool parseRateOption(char const *option, const char *value, int reconfiguring);
117  void dumpRateOption(StoreEntry * e) const;
118  bool parseSizeOption(char const *option, const char *value, int reconfiguring);
119  void dumpSizeOption(StoreEntry * e) const;
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;
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<Ipc::Mem::Owner<Rebuild::Stats> *> rebuildStatsOwners;
168  std::vector<SwapDir::DirMap::Owner *> mapOwners;
169  std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
170 };
171 
172 } // namespace Rock
173 
174 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */
175 
@ SwapFilenMax
Definition: forward.h:26
bool updateAnchoredWith(StoreEntry &, const Ipc::StoreMapAnchor &)
Definition: RockSwapDir.cc:104
int64_t diskOffset(Ipc::Mem::PageId &pageId) const
Definition: RockSwapDir.cc:687
virtual ~SwapDir()
Definition: RockSwapDir.cc:47
std::vector< Ipc::Mem::Owner< Ipc::Mem::PageStack > * > freeSlotsOwners
Definition: RockSwapDir.h:169
virtual bool hasReadableEntry(const StoreEntry &) const
whether this cache dir has an entry with e.key
virtual void reconfigure()
Definition: RockSwapDir.cc:343
const char * freeSlotsPath() const
DirMap * map
entry key/sfileno to MaxExtras/inode mapping
Definition: RockSwapDir.h:137
Definition: forward.h:28
unsigned char cache_key
Store key.
Definition: forward.h:29
std::vector< SwapDir::DirMap::Owner * > mapOwners
Definition: RockSwapDir.h:168
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:584
Shared memory page identifier, address, or handler.
Definition: Page.h:24
virtual uint64_t currentSize() const
current size
Definition: RockSwapDir.cc:151
Definition: SBuf.h:94
Ipc::Mem::Pointer< Ipc::Mem::PageStack > freeSlots
all unused slots
Definition: RockSwapDir.h:146
void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor)
Definition: RockSwapDir.cc:111
SBuf inodeMapPath() const
virtual ConfigOption * getOptionTree() const
Definition: RockSwapDir.cc:370
virtual bool dereference(StoreEntry &e)
Definition: RockSwapDir.cc:987
virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno)
adjust slice-linked state before a locked Readable slice is erased
Definition: RockSwapDir.cc:741
void parseSize(const bool reconfiguring)
parses anonymous cache_dir size option
Definition: RockSwapDir.cc:353
virtual bool updateAnchored(StoreEntry &)
Definition: RockSwapDir.cc:92
std::vector< Ipc::Mem::Owner< Rebuild::Stats > * > rebuildStatsOwners
Definition: RockSwapDir.h:167
virtual void finalizeSwapoutFailure(StoreEntry &)
abort the failed swapout that has been already noticed by Store
Definition: RockSwapDir.cc:180
virtual bool doReportStat() const
Definition: RockSwapDir.cc:168
virtual void updateHeaders(StoreEntry *e)
make stored metadata and HTTP headers the same as in the given entry
Definition: RockSwapDir.cc:936
void handleWriteCompletionProblem(const int errflag, const WriteRequest &request)
code shared by writeCompleted() error handling cases
Definition: RockSwapDir.cc:910
void dumpTimeOption(StoreEntry *e) const
reports time-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:436
virtual bool allowOptionReconfigure(const char *const option) const
Definition: RockSwapDir.cc:389
virtual void create()
called when the runner should create a new memory segment
Ipc::StoreMap DirMap
Definition: RockSwapDir.h:36
bool parseSizeOption(char const *option, const char *value, int reconfiguring)
parses size-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:495
RefCount< DiskFile > theFile
cache storage for this cache_dir
Definition: RockSwapDir.h:145
virtual bool anchorToCache(StoreEntry &entry, bool &inSync)
Definition: RockSwapDir.cc:75
void validateOptions()
warns of configuration problems; may quit
Definition: RockSwapDir.cc:542
virtual void ioCompletedNotification()
Definition: RockSwapDir.cc:804
uint64_t slotSize
all db slots are of this size
Definition: RockSwapDir.h:83
virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:613
void STFNCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:41
virtual void reference(StoreEntry &e)
somebody needs this entry (many cache replacement policies need to know)
Definition: RockSwapDir.cc:979
virtual void parse(int index, char *path)
Definition: RockSwapDir.cc:321
Ipc::Mem::PageId * waitingForPage
one-page cache for a "hot" free slot
Definition: RockSwapDir.h:147
int32_t StoreMapSliceId
Definition: StoreMap.h:24
virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest >)
Definition: RockSwapDir.cc:831
virtual void maintain()
purge while full(); it should be sufficient to purge just one
Definition: RockSwapDir.cc:970
void purgeSome()
purges one or more entries to make full() false and free some slots
int64_t entryLimitActual() const
max number of possible entries in db
Definition: RockSwapDir.cc:205
virtual uint64_t currentCount() const
the total number of objects stored right now
Definition: RockSwapDir.cc:160
virtual ~SwapDirRr()
DiskFile::Config fileConfig
file-level configuration options
Definition: RockSwapDir.h:150
virtual void evictCached(StoreEntry &)
char * path
Definition: Disk.h:102
virtual bool needsDiskStrand() const
needs a dedicated kid process
Definition: RockSwapDir.cc:312
API for adjusting external state when dirty map slice is being freed.
Definition: StoreMap.h:398
int64_t diskOffsetLimit() const
Definition: RockSwapDir.cc:694
int reconfiguring
void createError(const char *const msg)
Definition: RockSwapDir.cc:272
void handleWriteCompletionSuccess(const WriteRequest &request)
code shared by writeCompleted() success handling cases
Definition: RockSwapDir.cc:872
Aggregates information required for updating entry metadata and headers.
Definition: StoreMap.h:182
void ignoreReferences(StoreEntry &e)
delete from repl policy scope
virtual void finalizeSwapoutSuccess(const StoreEntry &)
finalize the successful swapout that has been already noticed by Store
Definition: RockSwapDir.cc:174
SlotId reserveSlotForWriting()
finds and returns a free db slot to fill or throws
Definition: RockSwapDir.cc:701
virtual void statfs(StoreEntry &e) const
virtual void diskFull()
Definition: RockSwapDir.cc:962
virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest >)
Definition: RockSwapDir.cc:840
signed_int32_t sfileno
Definition: forward.h:22
DiskIOStrategy * io
Definition: RockSwapDir.h:144
const char * filePath
location of cache storage file inside path/
Definition: RockSwapDir.h:136
int64_t entryLimitAbsolute() const
Core limit.
Definition: RockSwapDir.h:62
void writeError(StoreIOState &sio)
Definition: RockSwapDir.cc:922
initializes shared memory segments used by Rock::SwapDir
Definition: RockSwapDir.h:157
virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:756
void trackReferences(StoreEntry &e)
add to replacement policy scope
void STIOCB(void *their_data, int errflag, StoreIOState::Pointer self)
Definition: StoreIOState.h:51
virtual void disconnect(StoreEntry &e)
called when the entry is about to forget its association with cache_dir
Definition: RockSwapDir.cc:125
virtual bool unlinkdUseful() const
whether SwapDir may benefit from unlinkd
Definition: RockSwapDir.cc:998
bool validSlotId(const SlotId slotId) const
whether the given slot ID may point to a slot in this db
Definition: RockSwapDir.cc:735
virtual void closeCompleted()
Definition: RockSwapDir.cc:825
generally useful configuration options supported by some children
Definition: DiskFile.h:28
sfileno SlotId
db cell number, starting with cell 0 (always occupied by the db header)
Definition: forward.h:30
int64_t slotLimitAbsolute() const
Rock store implementation limit.
Definition: RockSwapDir.cc:187
RefCount< SwapDir > Pointer
Definition: RockSwapDir.h:35
int64_t slotLimitActual() const
total number of slots in this db
Definition: RockSwapDir.cc:196
bool parseRateOption(char const *option, const char *value, int reconfiguring)
parses rate-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:445
int index
Definition: Disk.h:103
static const int64_t HeaderSize
on-disk db header size
Definition: RockSwapDir.h:152
virtual void create()
create system resources needed for this store to operate in the future
Definition: RockSwapDir.cc:212
virtual StoreEntry * get(const cache_key *key)
Definition: RockSwapDir.cc:56
bool full() const
no more entries can be stored without purging
Definition: RockSwapDir.cc:954
virtual void evictIfFound(const cache_key *)
void dumpRateOption(StoreEntry *e) const
reports rate-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:487
void updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
virtual bool smpAware() const
whether this disk storage is capable of serving multiple workers
Definition: RockSwapDir.h:54
StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *)
Definition: RockSwapDir.cc:653
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void dumpSizeOption(StoreEntry *e) const
reports size-specific options; mimics SwapDir::optionObjectSizeDump()
Definition: RockSwapDir.cc:535
bool parseTimeOption(char const *option, const char *value, int reconfiguring)
parses time-specific options; mimics SwapDir::optionObjectSizeParse()
Definition: RockSwapDir.cc:397
virtual void init()
Definition: RockSwapDir.cc:281
int64_t diskOffset(int filen) const

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors