ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::DelayedConditionsCleanerSvc Class Reference

Clean conditions containers after a delay. More...

#include <DelayedConditionsCleanerSvc.h>

Inheritance diagram for Athena::DelayedConditionsCleanerSvc:
Collaboration diagram for Athena::DelayedConditionsCleanerSvc:

Classes

class  CondContInfo
 Information that we maintain about each conditions container. More...
struct  QueueItem
 Item in the work queue. More...

Public Types

typedef CondContBase::key_type key_type
 Packed key type.

Public Member Functions

 DelayedConditionsCleanerSvc (const std::string &name, ISvcLocator *svc)
 Standard Gaudi constructor.
 ~DelayedConditionsCleanerSvc ()
 Standard destructor.
virtual StatusCode initialize () override
 Standard Gaudi initialize method.
virtual StatusCode finalize () override
 Standard Gaudi finalize method.
virtual StatusCode event (const EventContext &ctx, bool allowAsync) override
 Called at the start of each event.
virtual StatusCode condObjAdded (const EventContext &ctx, CondContBase &cc) override
 Called after a conditions object has been added.
virtual StatusCode printStats () const override
 Print some statistics about the garbage collection.
virtual StatusCode reset () override
 Clear the internal state of the service.

Private Types

typedef CxxUtils::Ring< key_type > Ring
 Ring buffer holding most recent IOV keys of a given type.
using KeyType = CondContBase::KeyType
 Run+LBN or timestamp key?
typedef std::array< std::vector< key_type >, 2 > twoKeys_t
typedef std::unordered_map< CondContBase *, CondContInfo > CCInfoMap_t
 Map of information, indexed by the conditions container.
typedef std::mutex mutex_t
 Serialize access to m_ccinfo and m_work.
typedef std::lock_guard< mutex_t > lock_t

Private Member Functions

twoKeys_t getKeys (const Ring &runLBRing, const Ring &TSRing) const
void scheduleClean (std::vector< CondContInfo * > &&cis, twoKeys_t &&twoKeys, bool allowAsync)
 Do cleaning for a set of containers.
void cleanContainers (std::vector< CondContInfo * > &&cis, twoKeys_t &&twoKeys)
 Clean a set of containers.
bool cleanContainer (CondContInfo *ci, const twoKeys_t &keys) const
 Clean a single container.

Private Attributes

Ring m_runlbn
 Two ring buffers for recent IOV keys, one for run+LBN and one for timestamp.
Ring m_timestamp
std::vector< key_type > m_slotLBN
 IOV keys currently in use for each slot.
std::vector< key_type > m_slotTimestamp
CCInfoMap_t m_ccinfo
std::priority_queue< QueueItem > m_work
 Priority queue of pending cleaning requests.
mutex_t m_workMutex
size_t m_nEvents = 0
 Priority queue statistics.
size_t m_queueSum = 0
size_t m_workRemoved = 0
size_t m_maxQueue = 0
std::atomic< int > m_cleanTasks {0}
 Number of active asynchronous cleaning tasks.
std::unique_ptr< DelayedConditionsCleanerSvcProps > m_props
 Component properties.

Friends

class DelayedConditionsCleanerTask

Detailed Description

Clean conditions containers after a delay.

This is an implementation of IConditionsCleanerSvc, for doing garbage collection of conditions objects.

Briefly, it works like this.

When a conditions object is added (condObjAdded interface), we put an entry in a priority queue, saying that we want to clean this container CleanDelay events later.

On each event (event interface) we put the current IOV keys (run+LBN and timestamp) into ring buffers (of size RingSize). If the topmost entry of the priority queue has come due, then we pull off that entry and other entries due up to LookAhead events later. We then do a trim operation on each of the conditions containers, removing conditions objects from the oldest first that do not match any of the IOV keys in the ring buffer.

The cleaning can optionally be done as an asynchronous TBB job if Async is true and allowAsync=true is passed to event.

Definition at line 57 of file DelayedConditionsCleanerSvc.h.

Member Typedef Documentation

◆ CCInfoMap_t

Map of information, indexed by the conditions container.

Definition at line 214 of file DelayedConditionsCleanerSvc.h.

◆ key_type

◆ KeyType

Run+LBN or timestamp key?

Definition at line 133 of file DelayedConditionsCleanerSvc.h.

◆ lock_t

typedef std::lock_guard<mutex_t> Athena::DelayedConditionsCleanerSvc::lock_t
private

Definition at line 241 of file DelayedConditionsCleanerSvc.h.

◆ mutex_t

Serialize access to m_ccinfo and m_work.

Definition at line 240 of file DelayedConditionsCleanerSvc.h.

◆ Ring

Ring buffer holding most recent IOV keys of a given type.

Definition at line 129 of file DelayedConditionsCleanerSvc.h.

◆ twoKeys_t

typedef std::array<std::vector<key_type>,2> Athena::DelayedConditionsCleanerSvc::twoKeys_t
private

Definition at line 135 of file DelayedConditionsCleanerSvc.h.

Constructor & Destructor Documentation

◆ DelayedConditionsCleanerSvc()

Athena::DelayedConditionsCleanerSvc::DelayedConditionsCleanerSvc ( const std::string & name,
ISvcLocator * svc )

Standard Gaudi constructor.

Parameters
nameService name.
svcService locator.

Definition at line 154 of file DelayedConditionsCleanerSvc.cxx.

156 : base_class (name, svc),
157 m_props (std::make_unique<DelayedConditionsCleanerSvcProps> (this))
158{
159}
std::unique_ptr< DelayedConditionsCleanerSvcProps > m_props
Component properties.

◆ ~DelayedConditionsCleanerSvc()

Athena::DelayedConditionsCleanerSvc::~DelayedConditionsCleanerSvc ( )

Standard destructor.

Needed to avoid problems with unique_ptr

Member Function Documentation

◆ cleanContainer()

bool Athena::DelayedConditionsCleanerSvc::cleanContainer ( CondContInfo * ci,
const twoKeys_t & keys ) const
private

Clean a single container.

Parameters
ciThe container to clean.
keysSet of IOV keys for recent events.

Returns true if anything was removed from the container,

◆ cleanContainers()

void Athena::DelayedConditionsCleanerSvc::cleanContainers ( std::vector< CondContInfo * > && cis,
twoKeys_t && twoKeys )
private

Clean a set of containers.

Parameters
cisSet of containers to clean.
keysSet of IOV keys for recent events.

◆ condObjAdded()

StatusCode Athena::DelayedConditionsCleanerSvc::condObjAdded ( const EventContext & ctx,
CondContBase & cc )
overridevirtual

Called after a conditions object has been added.

Parameters
ctxThe current event context.
ccThe container to which the object was added.

Definition at line 255 of file DelayedConditionsCleanerSvc.cxx.

257{
258 // Add this container to the priority queue.
260 CCInfoMap_t::iterator it = m_ccinfo.find (&cc);
261 if (it == m_ccinfo.end()) {
262 it = m_ccinfo.emplace (&cc, CondContInfo (cc)).first;
263 }
264
265 EventContext::ContextEvt_t evt = ctx.evt();
266 m_work.emplace (evt + m_props->m_cleanDelay, it->second);
267 return StatusCode::SUCCESS;
268}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Information that we maintain about each conditions container.
std::priority_queue< QueueItem > m_work
Priority queue of pending cleaning requests.

◆ event()

StatusCode Athena::DelayedConditionsCleanerSvc::event ( const EventContext & ctx,
bool allowAsync )
overridevirtual

Called at the start of each event.

Parameters
ctxThe current event context.
allowAsyncIf true, then cleaning may be run in an asynchronous TBB task.

Definition at line 187 of file DelayedConditionsCleanerSvc.cxx.

188{
189 // Push the IOV key for the current event into the ring buffers.
190 // Also save in the per-slot arrays.
191 key_type key_lbn = CondContBase::keyFromRunLBN (ctx.eventID());
192 key_type key_ts = CondContBase::keyFromTimestamp (ctx.eventID());
193 m_runlbn.push (key_lbn);
194 m_timestamp.push (key_ts);
195 EventContext::ContextID_t slot = ctx.slot();
196 if (slot != EventContext::INVALID_CONTEXT_ID) {
197 m_slotLBN[slot] = key_lbn;
198 m_slotTimestamp[slot] = key_ts;
199 }
200
201 // Return now if an asynchronous cleaning task is still running ---
202 // we don't want to start a new one yet. We'll check pending work
203 // on the next call.
204 if (m_cleanTasks > 0) {
205 return StatusCode::SUCCESS;
206 }
207
208 // Collect conditions containers in need of cleaning.
209 std::vector<CondContInfo*> ci_vec;
210 {
212 // Is it time to clean the container at the top of the work queue?
213 if (!m_work.empty() && m_work.top().m_evt <= ctx.evt()) {
214 ++m_nEvents;
215 size_t sz = m_work.size();
216 m_queueSum += sz;
217 m_maxQueue = std::max (m_maxQueue, sz);
218
219 // Yes. Put it on the correct list. Also look ahead in the queue
220 // a bit; if there are other containers that we want to clean soon,
221 // go ahead and do them now.
222 do {
223 CondContInfo* ci = m_work.top().m_ci;
224 switch (ci->m_cc.keyType()) {
225 case KeyType::SINGLE:
226 break;
227 case KeyType::RUNLBN:
228 case KeyType::MIXED:
229 case KeyType::TIMESTAMP:
230 ci_vec.push_back (ci);
231 break;
232 default:
233 std::abort();
234 }
235 m_work.pop();
237 } while (!m_work.empty() && m_work.top().m_evt <= ctx.evt() + m_props->m_lookAhead);
238 }
239 }
240
241 // Clean the containers.
242 if (!ci_vec.empty()) {
243 scheduleClean (std::move (ci_vec), getKeys(m_runlbn,m_timestamp),
244 allowAsync);
245 }
246 return StatusCode::SUCCESS;
247}
static Double_t sz
size_t m_nEvents
Priority queue statistics.
twoKeys_t getKeys(const Ring &runLBRing, const Ring &TSRing) const
Ring m_runlbn
Two ring buffers for recent IOV keys, one for run+LBN and one for timestamp.
void scheduleClean(std::vector< CondContInfo * > &&cis, twoKeys_t &&twoKeys, bool allowAsync)
Do cleaning for a set of containers.
CondContBase::key_type key_type
Packed key type.
std::atomic< int > m_cleanTasks
Number of active asynchronous cleaning tasks.
std::vector< key_type > m_slotLBN
IOV keys currently in use for each slot.
static key_type keyFromTimestamp(const EventIDBase &b)
Make a timestamp key from an EventIDBase.
static key_type keyFromRunLBN(const EventIDBase &b)
Make a run+lbn key from an EventIDBase.

◆ finalize()

virtual StatusCode Athena::DelayedConditionsCleanerSvc::finalize ( )
overridevirtual

Standard Gaudi finalize method.

◆ getKeys()

DelayedConditionsCleanerSvc::twoKeys_t Athena::DelayedConditionsCleanerSvc::getKeys ( const Ring & runLBRing,
const Ring & TSRing ) const
private

Sort the key array and remove duplicates. We expect that the key array is probably `almost' sorted. std::sort, at least in the gcc implementation, is designed to perform well in such cases. */ for ( auto& keys : result ) { std::sort (keys.begin(), keys.end()); auto end = std::unique (keys.begin(), keys.end()); keys.resize (end - keys.begin()); }

return result; }

/** Do cleaning for a set of containers.

Parameters
cisSet of containers to clean.
ringRing buffer with recent IOV keys.
slotKeysVector of current keys for all slots.
allowAsyncCan this task run asynchronously?

This will either run cleaning directly, or submit it as a TBB task.

Clean a set of containers.

Parameters
cisSet of containers to clean.
keysSet of IOV keys for recent events.

Clean a single container.

Parameters
ciThe container to clean.
keyTypeRun+LBN or timestamp keys?
keysSet of IOV keys for recent events.

Returns true if anything was removed from the container,

Standard destructor.

Standard Gaudi finalize method.

Definition at line 343 of file DelayedConditionsCleanerSvc.cxx.

◆ initialize()

StatusCode Athena::DelayedConditionsCleanerSvc::initialize ( )
overridevirtual

Standard Gaudi initialize method.

Definition at line 165 of file DelayedConditionsCleanerSvc.cxx.

166{
167 // Set the ring buffer sizes.
168 m_runlbn.reset (m_props->m_ringSize);
169 m_timestamp.reset (m_props->m_ringSize);
170
171 ATH_CHECK( m_props->m_rcu.retrieve() );
172 size_t nslots = m_props->m_rcu->getNumSlots();
173 m_slotLBN.resize (nslots);
174 m_slotTimestamp.resize (nslots);
175
176 return StatusCode::SUCCESS;
177}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ printStats()

StatusCode Athena::DelayedConditionsCleanerSvc::printStats ( ) const
overridevirtual

Print some statistics about the garbage collection.

Would generally be called in finalize(), but broken out as a separate interface for testing/debugging purposes.

Definition at line 276 of file DelayedConditionsCleanerSvc.cxx.

277{
278 // Suppress output if we didn't actually do anything.
279 if (m_nEvents == 0) {
280 return StatusCode::SUCCESS;
281 }
282
283 ATH_MSG_INFO( "Conditions container statistics" );
284 ATH_MSG_INFO( " Work q: Max size: {} ({} queries) ", m_maxQueue, m_nEvents);
285 size_t den = std::max (m_nEvents, 1lu );
286 ATH_MSG_INFO( " Avg size: {:.2f} / Avg removed: {:.2f}",
287 static_cast<float>(m_queueSum)/den,
288 static_cast<float>(m_workRemoved)/den );
289
290 std::vector<const CondContInfo*> infos;
291 for (const auto& p : m_ccinfo) {
292 infos.push_back (&p.second);
293 }
294 std::sort (infos.begin(), infos.end(),
295 [](const CondContInfo* a, const CondContInfo* b)
296 { return a->m_cc.id().key() < b->m_cc.id().key(); });
297
298 for (const CondContInfo* ci : infos) {
299 ATH_MSG_INFO( " {:<20} nInserts {:6} maxSize {:3}",
300 ci->m_cc.id().key().c_str(),
301 ci->m_cc.nInserts(),
302 ci->m_cc.maxSize() );
303 den = std::max (ci->m_nClean, 1lu);
304 ATH_MSG_INFO( " nClean {} avgRemoved {:.2f} 0/1/2+ {}/{}/{}",
305 ci->m_nClean,
306 static_cast<float> (ci->m_nRemoved) / den,
307 ci->m_removed0,
308 ci->m_removed1,
309 ci->m_removed2plus );
310 }
311
312 return StatusCode::SUCCESS;
313}
#define ATH_MSG_INFO(x,...)
static Double_t a
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ reset()

StatusCode Athena::DelayedConditionsCleanerSvc::reset ( )
overridevirtual

Clear the internal state of the service.

Only for testing. Don't call if any other thread may be touching the service.

Definition at line 320 of file DelayedConditionsCleanerSvc.cxx.

321{
322 m_runlbn.reset (m_props->m_ringSize);
323 m_timestamp.reset (m_props->m_ringSize);
324
325 std::fill (m_slotLBN.begin(), m_slotLBN.end(), 0);
326 std::fill (m_slotTimestamp.begin(), m_slotTimestamp.end(), 0);
327
328 m_ccinfo.clear();
329 std::priority_queue<QueueItem> tmp;
330 m_work.swap (tmp);
331
332 m_nEvents = 0;
333 m_queueSum = 0;
334 m_workRemoved = 0;
335 m_maxQueue = 0;
336 m_cleanTasks = 0;
337
338 return StatusCode::SUCCESS;
339}

◆ scheduleClean()

void Athena::DelayedConditionsCleanerSvc::scheduleClean ( std::vector< CondContInfo * > && cis,
twoKeys_t && twoKeys,
bool allowAsync )
private

Do cleaning for a set of containers.

Parameters
cisSet of containers to clean.
ringRing buffer with recent IOV keys.
slotKeysVector of current keys for all slots.
allowAsyncCan this task run asynchronously?

This will either run cleaning directly, or submit it as a TBB task.

◆ DelayedConditionsCleanerTask

friend class DelayedConditionsCleanerTask
friend

Definition at line 125 of file DelayedConditionsCleanerSvc.h.

Member Data Documentation

◆ m_ccinfo

CCInfoMap_t Athena::DelayedConditionsCleanerSvc::m_ccinfo
private

Definition at line 215 of file DelayedConditionsCleanerSvc.h.

◆ m_cleanTasks

std::atomic<int> Athena::DelayedConditionsCleanerSvc::m_cleanTasks {0}
private

Number of active asynchronous cleaning tasks.

Definition at line 253 of file DelayedConditionsCleanerSvc.h.

253{0};

◆ m_maxQueue

size_t Athena::DelayedConditionsCleanerSvc::m_maxQueue = 0
private

Definition at line 249 of file DelayedConditionsCleanerSvc.h.

◆ m_nEvents

size_t Athena::DelayedConditionsCleanerSvc::m_nEvents = 0
private

Priority queue statistics.

Definition at line 246 of file DelayedConditionsCleanerSvc.h.

◆ m_props

std::unique_ptr<DelayedConditionsCleanerSvcProps> Athena::DelayedConditionsCleanerSvc::m_props
private

Component properties.

Definition at line 256 of file DelayedConditionsCleanerSvc.h.

◆ m_queueSum

size_t Athena::DelayedConditionsCleanerSvc::m_queueSum = 0
private

Definition at line 247 of file DelayedConditionsCleanerSvc.h.

◆ m_runlbn

Ring Athena::DelayedConditionsCleanerSvc::m_runlbn
private

Two ring buffers for recent IOV keys, one for run+LBN and one for timestamp.

We only access these from event(), which is called from the event loop, so no locking is needed.

Definition at line 205 of file DelayedConditionsCleanerSvc.h.

◆ m_slotLBN

std::vector<key_type> Athena::DelayedConditionsCleanerSvc::m_slotLBN
private

IOV keys currently in use for each slot.

Definition at line 209 of file DelayedConditionsCleanerSvc.h.

◆ m_slotTimestamp

std::vector<key_type> Athena::DelayedConditionsCleanerSvc::m_slotTimestamp
private

Definition at line 210 of file DelayedConditionsCleanerSvc.h.

◆ m_timestamp

Ring Athena::DelayedConditionsCleanerSvc::m_timestamp
private

Definition at line 206 of file DelayedConditionsCleanerSvc.h.

◆ m_work

std::priority_queue<QueueItem> Athena::DelayedConditionsCleanerSvc::m_work
private

Priority queue of pending cleaning requests.

Definition at line 237 of file DelayedConditionsCleanerSvc.h.

◆ m_workMutex

mutex_t Athena::DelayedConditionsCleanerSvc::m_workMutex
mutableprivate

Definition at line 242 of file DelayedConditionsCleanerSvc.h.

◆ m_workRemoved

size_t Athena::DelayedConditionsCleanerSvc::m_workRemoved = 0
private

Definition at line 248 of file DelayedConditionsCleanerSvc.h.


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