There are multiple setters in ClusterStats
with the same pattern:
void ClusterStats::onPartitionEvent(PartitionEventType::Enum type,
int partitionId,
bsls::Types::Int64 value)
{
// PRECONDITIONS
BSLS_ASSERT_SAFE(partitionId >= 0 &&
partitionId <
static_cast<int>(d_partitionsStatContexts.size()));
BSLS_ASSERT_SAFE(d_partitionsStatContexts[partitionId] &&
"initialize was not called");
- Passed
partitionId
arg
- Checks for
partitionId
range
- Check that subcontext was initialized
I propose to add PartitionStats
view to handle partition stats updates and access d_partitionsStatContexts[partitionId]
without extra checks. It might look like this:
// Perform all checks during this `get` once and cache `pstats_sp` for later use:
PartitionStats pstats_sp = d_clusterStats_sp->getPartitionStats(partitionId);
...
// Update partition stats without extra checks
pstats_sp->onPartitionEvent(e_ROLLOVER, value);