#include <FragmentStore.h>
Public Member Functions | |
const bool | addFragment (I2OChain &) |
void | addToStaleEventTimes (const utils::Duration_t) |
void | clear () |
bool | empty () const |
FragmentStore (size_t maxMemoryUsageMB) | |
bool | full () const |
const bool | getStaleEvent (I2OChain &, utils::Duration_t timeout) |
size_t | memoryUsed () const |
void | resetStaleEventTimes () |
unsigned int | size () const |
Private Types | |
typedef std::map< FragKey, I2OChain > | fragmentMap |
Private Member Functions | |
FragmentStore (FragmentStore const &) | |
FragmentStore & | operator= (FragmentStore const &) |
Private Attributes | |
const size_t | maxMemoryUsage_ |
size_t | memoryUsed_ |
fragmentMap | store_ |
Stores incomplete events
Uses a map of I2OChains to store incomplete events.
Definition at line 26 of file FragmentStore.h.
typedef std::map<FragKey, I2OChain> stor::FragmentStore::fragmentMap [private] |
Definition at line 105 of file FragmentStore.h.
FragmentStore::FragmentStore | ( | size_t | maxMemoryUsageMB | ) | [explicit] |
Definition at line 10 of file FragmentStore.cc.
References clear().
: maxMemoryUsage_(maxMemoryUsageMB*1024*1024) { clear(); }
stor::FragmentStore::FragmentStore | ( | FragmentStore const & | ) | [private] |
const bool FragmentStore::addFragment | ( | I2OChain & | chain | ) |
Adds fragments of the I2OChain to the fragment store. If the passed fragments completes an event, it returns true. In this case, the passed I2OChain contains the completed event. Otherwise, it returns false and the I2OChain is empty.
Definition at line 16 of file FragmentStore.cc.
References stor::I2OChain::complete(), stor::I2OChain::fragmentKey(), stor::I2OChain::memoryUsed(), memoryUsed_, pos, stor::I2OChain::release(), stor::I2OChain::resetStaleWindowStartTime(), and store_.
Referenced by stor::Processing::do_processI2OFragment().
{ // the trivial case that the chain is already complete if ( chain.complete() ) return true; memoryUsed_ += chain.memoryUsed(); const FragKey newKey = chain.fragmentKey(); // Use efficientAddOrUpdates pattern suggested by Item 24 of // 'Effective STL' by Scott Meyers fragmentMap::iterator pos = store_.lower_bound(newKey); if(pos != store_.end() && !(store_.key_comp()(newKey, pos->first))) { // key already exists pos->second.addToChain(chain); if ( pos->second.complete() ) { chain = pos->second; store_.erase(pos); memoryUsed_ -= chain.memoryUsed(); return true; } } else { chain.resetStaleWindowStartTime(); // The key does not exist in the map, add it to the map // Use pos as a hint to insert, so it can avoid another lookup store_.insert(pos, fragmentMap::value_type(newKey, chain)); chain.release(); // We already handled the trivial case that the chain is complete. // Thus, store_ will not have a complete event. } return false; }
void FragmentStore::addToStaleEventTimes | ( | const utils::Duration_t | duration | ) |
Add the duration to the stale window start time for all I2OChains hold by the store.
Definition at line 57 of file FragmentStore.cc.
References store_.
Referenced by stor::FragmentProcessor::processOneFragmentIfPossible().
void stor::FragmentStore::clear | ( | void | ) | [inline] |
Clears all fragments hold by the fragment store
Definition at line 67 of file FragmentStore.h.
References memoryUsed_, and store_.
Referenced by stor::DrainingQueues::allQueuesAndWorkersAreEmpty(), and FragmentStore().
{ store_.clear(); memoryUsed_ = 0; }
bool stor::FragmentStore::empty | ( | void | ) | const [inline] |
Checks if the fragment store is empty
Definition at line 74 of file FragmentStore.h.
References store_.
Referenced by stor::DrainingQueues::allQueuesAndWorkersAreEmpty().
{ return store_.empty(); }
bool stor::FragmentStore::full | ( | ) | const [inline] |
Checks if the fragment store is full
Definition at line 81 of file FragmentStore.h.
References maxMemoryUsage_, and memoryUsed_.
Referenced by stor::FragmentProcessor::processOneFragmentIfPossible().
{ return (memoryUsed_ >= maxMemoryUsage_); }
const bool FragmentStore::getStaleEvent | ( | I2OChain & | chain, |
utils::Duration_t | timeout | ||
) |
Checks for event fragments for which the last event fragment was added longer than timeout seconds ago. If it finds one it returns true and the I2OChain contains the faulty event. Otherwise it returns false and the I2OChain is empty.
Definition at line 81 of file FragmentStore.cc.
References end, stor::utils::getCurrentTime(), stor::I2OChain::markFaulty(), stor::I2OChain::memoryUsed(), memoryUsed_, pos, stor::I2OChain::release(), and store_.
{ const utils::TimePoint_t cutOffTime = utils::getCurrentTime() - timeout; fragmentMap::iterator pos = store_.begin(); fragmentMap::iterator end = store_.end(); while ( (pos != end) && (pos->second.staleWindowStartTime() > cutOffTime ) ) { ++pos; } if ( pos == end ) { chain.release(); return false; } else { chain = pos->second; store_.erase(pos); memoryUsed_ -= chain.memoryUsed(); chain.markFaulty(); return true; } }
size_t stor::FragmentStore::memoryUsed | ( | ) | const [inline] |
Returns the total memory occupied by the events in the fragment store
Definition at line 95 of file FragmentStore.h.
References memoryUsed_.
Referenced by stor::Processing::do_processI2OFragment().
{ return memoryUsed_; }
FragmentStore& stor::FragmentStore::operator= | ( | FragmentStore const & | ) | [private] |
void FragmentStore::resetStaleEventTimes | ( | ) |
Resets the stale window start time for all I2OChains hold by the store.
Definition at line 69 of file FragmentStore.cc.
References store_.
unsigned int stor::FragmentStore::size | ( | void | ) | const [inline] |
Returns the number of events in the fragment store (complete or not).
Definition at line 88 of file FragmentStore.h.
References store_.
Referenced by stor::Processing::do_processI2OFragment().
{ return store_.size(); }
const size_t stor::FragmentStore::maxMemoryUsage_ [private] |
Definition at line 109 of file FragmentStore.h.
Referenced by full().
size_t stor::FragmentStore::memoryUsed_ [private] |
Definition at line 108 of file FragmentStore.h.
Referenced by addFragment(), clear(), full(), getStaleEvent(), and memoryUsed().
fragmentMap stor::FragmentStore::store_ [private] |
Definition at line 106 of file FragmentStore.h.
Referenced by addFragment(), addToStaleEventTimes(), clear(), empty(), getStaleEvent(), resetStaleEventTimes(), and size().