#include <StoreMap.h>

Collaboration diagram for Ipc::StoreMap:

Classes

class  Owner
 aggregates anchor and slice owners for Init() caller convenience More...
 

Public Types

typedef StoreMapFileNos FileNos
 
typedef StoreMapAnchor Anchor
 
typedef StoreMapAnchors Anchors
 
typedef sfileno AnchorId
 
typedef StoreMapSlice Slice
 
typedef StoreMapSlices Slices
 
typedef StoreMapSliceId SliceId
 
typedef StoreMapUpdate Update
 

Public Member Functions

 StoreMap (const SBuf &aPath)
 
sfileno fileNoByKey (const cache_key *const key) const
 computes map entry anchor position for a given entry key More...
 
int compareVersions (const sfileno oldFileno, time_t newVersion) const
 
AnchoropenForWriting (const cache_key *const key, sfileno &fileno)
 
AnchoropenForWritingAt (sfileno fileno, bool overwriteExisting=true)
 
void startAppending (const sfileno fileno)
 restrict opened for writing entry to appending operations; allow reads More...
 
void closeForWriting (const sfileno fileno)
 successfully finish creating or updating the entry at fileno pos More...
 
void switchWritingToReading (const sfileno fileno)
 stop writing (or updating) the locked entry and start reading it More...
 
void forgetWritingEntry (const sfileno fileno)
 
bool openForUpdating (Update &update, sfileno fileNoHint)
 finds and locks the Update entry for an exclusive metadata update More...
 
void closeForUpdating (Update &update)
 makes updated info available to others, unlocks, and cleans up More...
 
void abortUpdating (Update &update)
 undoes partial update, unlocks, and cleans up More...
 
const AnchorpeekAtReader (const sfileno fileno) const
 only works on locked entries; returns nil unless the slice is readable More...
 
const AnchorpeekAtEntry (const sfileno fileno) const
 only works on locked entries; returns the corresponding Anchor More...
 
bool freeEntry (const sfileno)
 
void freeEntryByKey (const cache_key *const key)
 
bool markedForDeletion (const cache_key *const)
 
bool hasReadableEntry (const cache_key *const)
 whether the index contains a valid readable entry with the given key More...
 
const AnchoropenForReading (const cache_key *const key, sfileno &fileno)
 opens entry (identified by key) for reading, increments read level More...
 
const AnchoropenForReadingAt (const sfileno fileno)
 opens entry (identified by sfileno) for reading, increments read level More...
 
void closeForReading (const sfileno fileno)
 closes open entry after reading, decrements read level More...
 
SlicewriteableSlice (const AnchorId anchorId, const SliceId sliceId)
 writeable slice within an entry chain created by openForWriting() More...
 
const SlicereadableSlice (const AnchorId anchorId, const SliceId sliceId) const
 readable slice within an entry chain opened by openForReading() More...
 
AnchorwriteableEntry (const AnchorId anchorId)
 writeable anchor for the entry created by openForWriting() More...
 
const AnchorreadableEntry (const AnchorId anchorId) const
 readable anchor for the entry created by openForReading() More...
 
SliceId sliceContaining (const sfileno fileno, const uint64_t nth) const
 
void abortWriting (const sfileno fileno)
 stop writing the entry, freeing its slot for others to use if possible More...
 
bool purgeOne ()
 either finds and frees an entry with at least 1 slice or returns false More...
 
void importSlice (const SliceId sliceId, const Slice &slice)
 copies slice to its designated position More...
 
bool validEntry (const int n) const
 whether n is a valid slice coordinate More...
 
bool validSlice (const int n) const
 whether n is a valid slice coordinate More...
 
int entryCount () const
 number of writeable and readable entries More...
 
int entryLimit () const
 maximum entryCount() possible More...
 
int sliceLimit () const
 maximum number of slices possible More...
 
void updateStats (ReadWriteLockStats &stats) const
 adds approximate current stats to the supplied ones More...
 

Static Public Member Functions

static OwnerInit (const SBuf &path, const int slotLimit)
 initialize shared memory More...
 

Public Attributes

StoreMapCleanercleaner
 notified before a readable entry is freed More...
 

Protected Attributes

const SBuf path
 cache_dir path or similar cache name; for logging More...
 
Mem::Pointer< StoreMapFileNosfileNos
 entry inodes (starting blocks) More...
 
Mem::Pointer< StoreMapAnchorsanchors
 entry inodes (starting blocks) More...
 
Mem::Pointer< StoreMapSlicesslices
 chained entry pieces positions More...
 

Private Types

typedef std::function< bool(const
sfileno name)> 
NameFilter
 

Private Member Functions

sfileno nameByKey (const cache_key *const key) const
 computes entry name (i.e., key hash) for a given entry key More...
 
sfileno fileNoByName (const sfileno name) const
 computes anchor position for a given entry name More...
 
void relocate (const sfileno name, const sfileno fileno)
 map name to fileNo More...
 
AnchoranchorAt (const sfileno fileno)
 
const AnchoranchorAt (const sfileno fileno) const
 
AnchoranchorByKey (const cache_key *const key)
 
SlicesliceAt (const SliceId sliceId)
 
const SlicesliceAt (const SliceId sliceId) const
 
AnchoropenForReading (Slice &s)
 
bool openKeyless (Update::Edition &edition)
 
void closeForUpdateFinal (Update &update)
 
bool visitVictims (const NameFilter filter)
 
void freeChain (const sfileno fileno, Anchor &inode, const bool keepLock)
 unconditionally frees an already locked chain of slots, unlocking if needed More...
 
void freeChainAt (SliceId sliceId, const SliceId splicingPoint)
 unconditionally frees an already locked chain of slots; no anchor maintenance More...
 

Detailed Description

Manages shared Store index (e.g., locking/unlocking/freeing entries) using StoreMapFileNos indexed by hashed entry keys (a.k.a. entry names), StoreMapAnchors indexed by fileno, and StoreMapSlices indexed by slice ID.

Definition at line 187 of file StoreMap.h.

Member Typedef Documentation

Definition at line 191 of file StoreMap.h.

Definition at line 193 of file StoreMap.h.

Definition at line 192 of file StoreMap.h.

Definition at line 190 of file StoreMap.h.

typedef std::function<bool (const sfileno name)> Ipc::StoreMap::NameFilter
private

Definition at line 335 of file StoreMap.h.

Definition at line 194 of file StoreMap.h.

Definition at line 196 of file StoreMap.h.

Definition at line 195 of file StoreMap.h.

Definition at line 197 of file StoreMap.h.

Constructor & Destructor Documentation

Ipc::StoreMap::StoreMap ( const SBuf aPath)

Definition at line 50 of file StoreMap.cc.

References anchors, assert, debugs, entryLimit(), fileNos, path, sliceLimit(), and slices.

Member Function Documentation

Ipc::StoreMap::Anchor & Ipc::StoreMap::anchorAt ( const sfileno  fileno)
private

Definition at line 689 of file StoreMap.cc.

References assert.

Referenced by anchorAt().

const Ipc::StoreMap::Anchor & Ipc::StoreMap::anchorAt ( const sfileno  fileno) const
private

Definition at line 696 of file StoreMap.cc.

References anchorAt().

Ipc::StoreMap::Anchor & Ipc::StoreMap::anchorByKey ( const cache_key *const  key)
private

Definition at line 737 of file StoreMap.cc.

void Ipc::StoreMap::closeForReading ( const sfileno  fileno)
void Ipc::StoreMap::closeForUpdateFinal ( Update update)
private
void Ipc::StoreMap::closeForWriting ( const sfileno  fileno)
int Ipc::StoreMap::compareVersions ( const sfileno  oldFileno,
time_t  newVersion 
) const

Like strcmp(mapped, new), but for store entry versions/timestamps. Returns +2 if the mapped entry does not exist; -1/0/+1 otherwise. Comparison may be inaccurate unless the caller is a lock holder.

Definition at line 63 of file StoreMap.cc.

References Ipc::StoreMapAnchor::basics, Ipc::StoreMapAnchor::empty(), and Ipc::StoreMapAnchor::Basics::timestamp.

int Ipc::StoreMap::entryCount ( ) const
int Ipc::StoreMap::entryLimit ( ) const

Definition at line 652 of file StoreMap.cc.

References min(), and SwapFilenMax.

Referenced by MemStore::stat(), Transients::stat(), and StoreMap().

sfileno Ipc::StoreMap::fileNoByKey ( const cache_key *const  key) const

Definition at line 730 of file StoreMap.cc.

Referenced by Transients::evictIfFound().

sfileno Ipc::StoreMap::fileNoByName ( const sfileno  name) const
private

Definition at line 712 of file StoreMap.cc.

void Ipc::StoreMap::forgetWritingEntry ( const sfileno  fileno)

unlock and "forget" openForWriting entry, making it Empty again this call does not free entry slices so the caller has to do that

Definition at line 79 of file StoreMap.cc.

References assert, debugs, Ipc::StoreMapAnchor::lock, Ipc::StoreMapAnchor::rewind(), Ipc::ReadWriteLock::unlockExclusive(), and Ipc::StoreMapAnchor::writing().

void Ipc::StoreMap::freeChain ( const sfileno  fileno,
Anchor inode,
const bool  keepLock 
)
private
void Ipc::StoreMap::freeChainAt ( SliceId  sliceId,
const SliceId  splicingPoint 
)
private

Definition at line 341 of file StoreMap.cc.

References debugs, Ipc::StoreMapSlice::next, and Ipc::StoreMapSlice::size.

bool Ipc::StoreMap::freeEntry ( const sfileno  fileno)

free the entry if possible or mark it as waiting to be freed if not

Returns
whether the entry was neither empty nor marked

Definition at line 263 of file StoreMap.cc.

References debugs, Ipc::StoreMapAnchor::empty(), Ipc::StoreMapAnchor::lock, Ipc::ReadWriteLock::lockExclusive(), and Ipc::StoreMapAnchor::waitingToBeFreed.

Referenced by MemStore::evictCached(), Transients::evictCached(), Transients::evictIfFound(), and MemStore::get().

void Ipc::StoreMap::freeEntryByKey ( const cache_key *const  key)

free the entry if possible or mark it as waiting to be freed if not does nothing if we cannot check that the key matches the cached entry

Definition at line 281 of file StoreMap.cc.

References debugs, Ipc::StoreMapAnchor::lock, Ipc::ReadWriteLock::lockExclusive(), Ipc::ReadWriteLock::lockShared(), Ipc::StoreMapAnchor::sameKey(), storeKeyText(), Ipc::ReadWriteLock::unlockExclusive(), Ipc::ReadWriteLock::unlockShared(), and Ipc::StoreMapAnchor::waitingToBeFreed.

Referenced by MemStore::evictIfFound().

bool Ipc::StoreMap::hasReadableEntry ( const cache_key * const  key)

Definition at line 313 of file StoreMap.cc.

void Ipc::StoreMap::importSlice ( const SliceId  sliceId,
const Slice slice 
)

Definition at line 641 of file StoreMap.cc.

References assert.

bool Ipc::StoreMap::markedForDeletion ( const cache_key * const  key)

whether the entry with the given key exists and was marked as "waiting to be freed" some time ago

Definition at line 305 of file StoreMap.cc.

References Ipc::StoreMapAnchor::sameKey(), and Ipc::StoreMapAnchor::waitingToBeFreed.

Referenced by Transients::markedForDeletion().

sfileno Ipc::StoreMap::nameByKey ( const cache_key *const  key) const
private

Definition at line 702 of file StoreMap.cc.

References assert, and hash.

const Ipc::StoreMap::Anchor * Ipc::StoreMap::openForReading ( const cache_key *const  key,
sfileno fileno 
)

Definition at line 383 of file StoreMap.cc.

References debugs, NULL, and storeKeyText().

Referenced by MemStore::anchorToCache(), MemStore::get(), and Transients::get().

Anchor* Ipc::StoreMap::openForReading ( Slice s)
private
Ipc::StoreMap::Anchor * Ipc::StoreMap::openForWriting ( const cache_key *const  key,
sfileno fileno 
)

finds, locks, and returns an anchor for an empty key position, erasing the old entry (if any)

Definition at line 98 of file StoreMap.cc.

References debugs, NULL, and storeKeyText().

Referenced by Transients::addEntry(), and MemStore::startCaching().

Ipc::StoreMap::Anchor * Ipc::StoreMap::openForWritingAt ( sfileno  fileno,
bool  overwriteExisting = true 
)
bool Ipc::StoreMap::openKeyless ( Update::Edition edition)
private

finds an anchor that is currently not associated with any entry key and locks it for writing so ensure exclusive access during updates

Definition at line 509 of file StoreMap.cc.

References Ipc::StoreMapUpdate::Edition::anchor, debugs, Ipc::StoreMapUpdate::Edition::fileNo, Must, and Ipc::StoreMapUpdate::Edition::name.

const Ipc::StoreMap::Anchor & Ipc::StoreMap::peekAtEntry ( const sfileno  fileno) const

Definition at line 257 of file StoreMap.cc.

Referenced by Transients::readers().

const Ipc::StoreMap::Anchor * Ipc::StoreMap::peekAtReader ( const sfileno  fileno) const
const Ipc::StoreMap::Anchor & Ipc::StoreMap::readableEntry ( const AnchorId  anchorId) const

Definition at line 202 of file StoreMap.cc.

References assert.

Referenced by Transients::status(), and MemStore::updateAnchored().

const Ipc::StoreMap::Slice & Ipc::StoreMap::readableSlice ( const AnchorId  anchorId,
const SliceId  sliceId 
) const

Definition at line 187 of file StoreMap.cc.

References assert.

Referenced by MemStore::copyFromShm(), and MemStore::updateHeadersOrThrow().

void Ipc::StoreMap::relocate ( const sfileno  name,
const sfileno  fileno 
)
private

Definition at line 723 of file StoreMap.cc.

Ipc::StoreMap::Slice & Ipc::StoreMap::sliceAt ( const SliceId  sliceId)
private

Definition at line 743 of file StoreMap.cc.

References assert.

Referenced by sliceAt().

const Ipc::StoreMap::Slice & Ipc::StoreMap::sliceAt ( const SliceId  sliceId) const
private

Definition at line 750 of file StoreMap.cc.

References sliceAt().

Ipc::StoreMap::SliceId Ipc::StoreMap::sliceContaining ( const sfileno  fileno,
const uint64_t  nth 
) const

Returns the ID of the entry slice containing n-th byte or a negative ID if the entry does not store that many bytes (yet). Requires a read lock.

Definition at line 364 of file StoreMap.cc.

References debugs, Must, Ipc::StoreMapSlice::next, Ipc::StoreMapAnchor::reading(), Ipc::StoreMapSlice::size, and Ipc::StoreMapAnchor::start.

Referenced by MemStore::updateHeadersOrThrow().

int Ipc::StoreMap::sliceLimit ( ) const

Definition at line 664 of file StoreMap.cc.

Referenced by Init(), MemStore::stat(), and StoreMap().

void Ipc::StoreMap::startAppending ( const sfileno  fileno)
void Ipc::StoreMap::updateStats ( ReadWriteLockStats stats) const

Definition at line 670 of file StoreMap.cc.

References i.

Referenced by MemStore::stat().

bool Ipc::StoreMap::validEntry ( const int  n) const

Definition at line 677 of file StoreMap.cc.

bool Ipc::StoreMap::validSlice ( const int  n) const

Definition at line 683 of file StoreMap.cc.

bool Ipc::StoreMap::visitVictims ( const NameFilter  visitor)
private

Visits entries until either

  • the visitor returns true (indicating its satisfaction with the offer);
  • we give up finding a suitable entry because it already took "too long"; or
  • we have offered all entries.

Definition at line 604 of file StoreMap.cc.

References debugs, and min().

Ipc::StoreMap::Anchor & Ipc::StoreMap::writeableEntry ( const AnchorId  anchorId)
Ipc::StoreMap::Slice & Ipc::StoreMap::writeableSlice ( const AnchorId  anchorId,
const SliceId  sliceId 
)

Definition at line 179 of file StoreMap.cc.

References assert.

Referenced by MemStore::nextAppendableSlice().

Member Data Documentation

Mem::Pointer<StoreMapAnchors> Ipc::StoreMap::anchors
protected

Definition at line 315 of file StoreMap.h.

Referenced by StoreMap(), and Ipc::StoreMap::Owner::~Owner().

StoreMapCleaner* Ipc::StoreMap::cleaner

Definition at line 310 of file StoreMap.h.

Referenced by MemStore::init(), and Transients::init().

Mem::Pointer<StoreMapFileNos> Ipc::StoreMap::fileNos
protected

Definition at line 314 of file StoreMap.h.

Referenced by StoreMap(), and Ipc::StoreMap::Owner::~Owner().

const SBuf Ipc::StoreMap::path
protected

Definition at line 313 of file StoreMap.h.

Referenced by StoreMap().

Mem::Pointer<StoreMapSlices> Ipc::StoreMap::slices
protected

Definition at line 316 of file StoreMap.h.

Referenced by StoreMap(), and Ipc::StoreMap::Owner::~Owner().


The documentation for this class was generated from the following files:

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors