Skip to content

Refactor mqbstat_clusterstats.cpp: create partition views to avoid passing and checking partitionId every time #923

@678098

Description

@678098

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");
  1. Passed partitionId arg
  2. Checks for partitionId range
  3. 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);

Metadata

Metadata

Assignees

Labels

A-BrokerArea: C++ BrokerenhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions