#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, bool lockForReading=false)
 successfully finish creating or updating the entry at fileno pos 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...
 
void freeEntry (const sfileno fileno)
 free the entry if possible or mark it as waiting to be freed if not More...
 
void freeEntryByKey (const cache_key *const key)
 
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 183 of file StoreMap.h.

Member Typedef Documentation

Definition at line 187 of file StoreMap.h.

Definition at line 189 of file StoreMap.h.

Definition at line 188 of file StoreMap.h.

Definition at line 186 of file StoreMap.h.

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

Definition at line 321 of file StoreMap.h.

Definition at line 190 of file StoreMap.h.

Definition at line 192 of file StoreMap.h.

Definition at line 191 of file StoreMap.h.

Definition at line 193 of file StoreMap.h.

Constructor & Destructor Documentation

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

Definition at line 49 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 659 of file StoreMap.cc.

References assert.

Referenced by anchorAt().

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

Definition at line 666 of file StoreMap.cc.

References anchorAt().

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

Definition at line 706 of file StoreMap.cc.

void Ipc::StoreMap::closeForReading ( const sfileno  fileno)
void Ipc::StoreMap::closeForUpdateFinal ( Update update)
private
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 62 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 622 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 699 of file StoreMap.cc.

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

Definition at line 681 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 78 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 311 of file StoreMap.cc.

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

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 270 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::unlink().

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

Definition at line 611 of file StoreMap.cc.

References assert.

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

Definition at line 672 of file StoreMap.cc.

References hash, and key.

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

Definition at line 353 of file StoreMap.cc.

References debugs, NULL, and storeKeyText().

Referenced by MemStore::anchorCollapsed(), 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 97 of file StoreMap.cc.

References debugs, NULL, and storeKeyText().

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

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 479 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 251 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 197 of file StoreMap.cc.

References assert.

Referenced by Transients::abandonedAt(), and MemStore::updateCollapsed().

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

Definition at line 182 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 692 of file StoreMap.cc.

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

Definition at line 712 of file StoreMap.cc.

References assert.

Referenced by sliceAt().

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

Definition at line 719 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 334 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 634 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 640 of file StoreMap.cc.

References i.

Referenced by MemStore::stat().

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

Definition at line 647 of file StoreMap.cc.

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

Definition at line 653 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 574 of file StoreMap.cc.

References debugs, and min().

Ipc::StoreMap::Anchor & Ipc::StoreMap::writeableEntry ( const AnchorId  anchorId)

Definition at line 190 of file StoreMap.cc.

References assert.

Referenced by MemStore::copyToShm(), and MemStore::nextAppendableSlice().

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

Definition at line 174 of file StoreMap.cc.

References assert.

Referenced by MemStore::nextAppendableSlice().

Member Data Documentation

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

Definition at line 301 of file StoreMap.h.

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

StoreMapCleaner* Ipc::StoreMap::cleaner

Definition at line 296 of file StoreMap.h.

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

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

Definition at line 300 of file StoreMap.h.

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

const SBuf Ipc::StoreMap::path
protected

Definition at line 299 of file StoreMap.h.

Referenced by StoreMap().

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

Definition at line 302 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