9#ifndef SQUID_SRC_IPC_STOREMAP_H
10#define SQUID_SRC_IPC_STOREMAP_H
49 std::atomic<StoreMapSliceId>
next;
88 uint64_t
key[2] = {0, 0};
147 for (
int index = 0; index <
capacity; ++index)
148 items[index] = value;
191 explicit operator bool()
const {
return anchor; }
approximate stats of a set of ReadWriteLocks
std::atomic< uint32_t > readers
number of reading users
std::atomic< bool > writing
there is a writing user (there can be at most 1)
std::atomic< StoreMapSliceId > splicingPoint
std::atomic< StoreMapSliceId > start
where the chain of StoreEntry slices begins [app]
void rewind()
undo the effects of set(), setKey(), etc., but keep locks and state
bool sameKey(const cache_key *const aKey) const
struct Ipc::StoreMapAnchor::Basics basics
uint64_t key[2]
StoreEntry key.
std::atomic< uint8_t > writerHalted
whether StoreMap::abortWriting() was called for a read-locked entry
void set(const StoreEntry &anEntry, const cache_key *aKey=nullptr)
store StoreEntry key and basics for an inode slot
void setKey(const cache_key *const aKey)
ReadWriteLock lock
protects slot data below
std::atomic< uint8_t > waitingToBeFreed
void exportInto(StoreEntry &) const
load StoreEntry basics that were previously stored with set()
Ipc::Mem::FlexibleArray< StoreMapAnchor > items
anchors storage
Ipc::Mem::Owner< StoreMapAnchors > Owner
std::atomic< int32_t > count
current number of entries
const int capacity
total number of anchors
std::atomic< uint32_t > victim
starting point for purge search
size_t sharedMemorySize() const
static size_t SharedMemorySize(const int anAnchorLimit)
API for adjusting external state when dirty map slice is being freed.
virtual void noteFreeMapSlice(const StoreMapSliceId sliceId)=0
adjust slice-linked state before a locked Readable slice is erased
virtual ~StoreMapCleaner()
StoreMapItems(const int aCapacity)
const Item & at(const int index) const
Item & at(const int index)
const int capacity
total number of items
void fill(const Item &value)
reset all items to the same value
Ipc::Mem::Owner< StoreMapItems< Item > > Owner
static size_t SharedMemorySize(const int aCapacity)
Ipc::Mem::FlexibleArray< Item > items
storage
size_t sharedMemorySize() const
void clear()
restore default-constructed state
std::atomic< StoreMapSliceId > next
ID of the next entry slice.
std::atomic< Size > size
slice contents size
StoreMapSlice(const StoreMapSlice &o)
StoreMapSlice & operator=(const StoreMapSlice &o)
During an update, the stored entry has two editions: stale and fresh.
sfileno name
StoreEntry position in StoreMap::fileNos, for swapping Editions.
sfileno fileNo
StoreMap::fileNos[name], for convenience/speed.
StoreMapSliceId splicingPoint
the last slice in the chain still containing metadata/headers
StoreMapAnchor * anchor
StoreMap::anchors[fileNo], for convenience/speed.
Aggregates information required for updating entry metadata and headers.
Edition fresh
new anchor and the updated chain prefix
Edition stale
old anchor and chain
StoreMapUpdate & operator=(const StoreMapUpdate &other)=delete
StoreEntry * entry
the store entry being updated
aggregates anchor and slice owners for Init() caller convenience
Owner & operator=(const Owner &)
Anchor * openForWriting(const cache_key *const key, sfileno &fileno)
const Slice & readableSlice(const AnchorId anchorId, const SliceId sliceId) const
readable slice within an entry chain opened by openForReading()
const Anchor * openForReadingAt(const sfileno, const cache_key *const)
opens entry (identified by sfileno) for reading, increments read level
bool validateHit(const sfileno)
bool openForUpdating(Update &update, sfileno fileNoHint)
finds and locks the Update entry for an exclusive metadata update
Anchor * openForWritingAt(sfileno fileno, bool overwriteExisting=true)
bool visitVictims(const NameFilter filter)
bool markedForDeletion(const cache_key *const)
Anchor & writeableEntry(const AnchorId anchorId)
writeable anchor for the entry created by openForWriting()
Mem::Pointer< StoreMapAnchors > anchors
entry inodes (starting blocks)
const Anchor * peekAtReader(const sfileno fileno) const
bool validEntry(const int n) const
whether n is a valid slice coordinate
const Anchor & readableEntry(const AnchorId anchorId) const
readable anchor for the entry created by openForReading()
void closeForUpdateFinal(Update &update)
Anchor & anchorByKey(const cache_key *const key)
int entryCount() const
number of writeable and readable entries
static Owner * Init(const SBuf &path, const int slotLimit)
initialize shared memory
void relocate(const sfileno name, const sfileno fileno)
map name to fileNo
void freeChain(const sfileno fileno, Anchor &inode, const bool keepLock)
unconditionally frees an already locked chain of slots, unlocking if needed
Slice & sliceAt(const SliceId sliceId)
void closeForWriting(const sfileno fileno)
successfully finish creating or updating the entry at fileno pos
const Anchor * openOrCreateForReading(const cache_key *, sfileno &)
openForReading() but creates a new entry if there is no old one
StoreMapCleaner * cleaner
notified before a readable entry is freed
void abortUpdating(Update &update)
undoes partial update, unlocks, and cleans up
bool hitValidation
whether paranoid_hit_validation should be performed
SliceId sliceContaining(const sfileno fileno, const uint64_t nth) const
const Anchor * openForReading(const cache_key *const key, sfileno &fileno)
opens entry (identified by key) for reading, increments read level
void forgetWritingEntry(const sfileno fileno)
int compareVersions(const sfileno oldFileno, time_t newVersion) const
bool freeEntry(const sfileno)
const SBuf path
cache_dir path or similar cache name; for logging
void closeForReading(const sfileno fileno)
closes open entry after reading, decrements read level
void importSlice(const SliceId sliceId, const Slice &slice)
copies slice to its designated position
const Anchor * peekAtWriter(const sfileno fileno) const
void closeForReadingAndFreeIdle(const sfileno fileno)
same as closeForReading() but also frees the entry if it is unlocked
void abortWriting(const sfileno fileno)
stop writing the entry, freeing its slot for others to use if possible
bool validSlice(const int n) const
whether n is a valid slice coordinate
void startAppending(const sfileno fileno)
restrict opened for writing entry to appending operations; allow reads
sfileno nameByKey(const cache_key *const key) const
computes entry name (i.e., key hash) for a given entry key
Anchor * openForReading(Slice &s)
void prepFreeSlice(const SliceId sliceId)
prepare a chain-unaffiliated slice for being added to an entry chain
Mem::Pointer< StoreMapSlices > slices
chained entry pieces positions
void closeForUpdating(Update &update)
makes updated info available to others, unlocks, and cleans up
std::function< bool(const sfileno name)> NameFilter
bool openKeyless(Update::Edition &edition)
bool purgeOne()
either finds and frees an entry with at least 1 slice or returns false
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
sfileno fileNoByKey(const cache_key *const key) const
computes map entry anchor position for a given entry key
bool hasReadableEntry(const cache_key *const)
whether the index contains a valid readable entry with the given key
void freeEntryByKey(const cache_key *const key)
sfileno fileNoByName(const sfileno name) const
computes anchor position for a given entry name
Anchor & anchorAt(const sfileno fileno)
const Anchor & peekAtEntry(const sfileno fileno) const
Mem::Pointer< StoreMapFileNos > fileNos
entry inodes (starting blocks)
Slice & writeableSlice(const AnchorId anchorId, const SliceId sliceId)
writeable slice within an entry chain created by openForWriting()
void switchWritingToReading(const sfileno fileno)
stop writing (or updating) the locked entry and start reading it
int sliceLimit() const
maximum number of slices possible
void disableHitValidation()
void freeChainAt(SliceId sliceId, const SliceId splicingPoint)
unconditionally frees an already locked chain of slots; no anchor maintenance
int entryLimit() const
maximum entryCount() possible
StoreMapItems< std::atomic< sfileno > > StoreMapFileNos
StoreMapAnchor positions, indexed by entry "name" (i.e., the entry key hash)
StoreMapItems< StoreMapSlice > StoreMapSlices
StoreMapSlices indexed by their slice ID.
unsigned char cache_key
Store key.
std::atomic< uint64_t > swap_file_sz