Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitrii Petukhov <[email protected]>
  • Loading branch information
bbpetukhov committed Nov 28, 2024
1 parent 4bde0e4 commit 608ae0c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 65 deletions.
5 changes: 3 additions & 2 deletions src/applications/bmqstoragetool/bmqstoragetool.m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ parseArgs(CommandLineArguments& arguments, int argc, const char* argv[])
"and other statistics)",
balcl::TypeInfo(&arguments.d_summary),
balcl::OccurrenceInfo::e_OPTIONAL},
{"min-records-per-queue",
{"min-records-per-queue",
"min records per queue",
"min number of records per queue for detailed info to be displayed",
balcl::TypeInfo(&arguments.d_minRecordsPerQueue),
balcl::OccurrenceInfo(bsl::numeric_limits<bsls::Types::Int64>::max())},
balcl::OccurrenceInfo(
bsl::numeric_limits<bsls::Types::Int64>::max())},
{"h|help",
"help",
"print usage)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,24 @@ void JournalFileProcessor::process()
record,
iter->recordIndex(),
iter->recordOffset());
} else if (iter->recordType() == mqbs::RecordType::e_QUEUE_OP) {
}
else if (iter->recordType() == mqbs::RecordType::e_QUEUE_OP) {
const mqbs::QueueOpRecord& record = iter->asQueueOpRecord();

stopSearch = d_searchResult_p->processQueueOpRecord(
record,
iter->recordIndex(),
iter->recordOffset());
} else if (iter->recordType() == mqbs::RecordType::e_JOURNAL_OP) {
record,
iter->recordIndex(),
iter->recordOffset());
}
else if (iter->recordType() == mqbs::RecordType::e_JOURNAL_OP) {
const mqbs::JournalOpRecord& record = iter->asJournalOpRecord();

stopSearch = d_searchResult_p->processJournalOpRecord(
record,
iter->recordIndex(),
iter->recordOffset());
} else {
record,
iter->recordIndex(),
iter->recordOffset());
}
else {
stopSearch = d_searchResult_p->processOtherRecord(
iter->recordType());
}
Expand Down
84 changes: 44 additions & 40 deletions src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.

// bmqstoragetool
#include <m_bmqstoragetool_searchresult.h>
#include <m_bmqstoragetool_recordprinter.h>
#include <m_bmqstoragetool_searchresult.h>

// MQB
#include <mqbs_filestoreprotocolprinter.h>
Expand Down Expand Up @@ -187,16 +187,16 @@ void outputFooter(bsl::ostream& ostream, bsl::size_t foundMessagesCount)

bool SearchResult::processQueueOpRecord(
BSLS_ANNOTATION_UNUSED const mqbs::QueueOpRecord& record,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
{
return false;
}

bool SearchResult::processJournalOpRecord(
BSLS_ANNOTATION_UNUSED const mqbs::JournalOpRecord& record,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
{
return false;
}
Expand Down Expand Up @@ -254,7 +254,6 @@ bool SearchResultDecorator::processDeletionRecord(
recordOffset);
}


void SearchResultDecorator::outputResult()
{
d_searchResult->outputResult();
Expand Down Expand Up @@ -812,8 +811,8 @@ SummaryProcessor::SummaryProcessor(bsl::ostream& ostream,
mqbs::JournalFileIterator* journalFile_p,
mqbs::DataFileIterator* dataFile_p,
const QueueMap& queueMap,
bsls::Types::Uint64 minRecordsPerQueue,
bslma::Allocator* allocator)
bsls::Types::Uint64 minRecordsPerQueue,
bslma::Allocator* allocator)
: d_ostream(ostream)
, d_journalFile_p(journalFile_p)
, d_dataFile_p(dataFile_p)
Expand Down Expand Up @@ -868,7 +867,7 @@ bool SummaryProcessor::processConfirmRecord(

d_queueRecordsMap[record.queueKey()]++;
d_queueAppRecordsMap[record.queueKey()][record.appKey()]++;

d_queueConfirmRecordsMap[record.queueKey()]++;

return false;
Expand Down Expand Up @@ -897,8 +896,8 @@ bool SummaryProcessor::processDeletionRecord(

bool SummaryProcessor::processQueueOpRecord(
const mqbs::QueueOpRecord& record,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
{
handleAnyRecordType();

Expand All @@ -910,8 +909,8 @@ bool SummaryProcessor::processQueueOpRecord(

bool SummaryProcessor::processJournalOpRecord(
BSLS_ANNOTATION_UNUSED const mqbs::JournalOpRecord& record,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordIndex,
BSLS_ANNOTATION_UNUSED bsls::Types::Uint64 recordOffset)
{
handleAnyRecordType();

Expand All @@ -923,18 +922,17 @@ bool SummaryProcessor::processJournalOpRecord(
bool SummaryProcessor::processOtherRecord(mqbs::RecordType::Enum recordType)
{
handleAnyRecordType();

d_otherRecordsCounts[recordType]++;

return false;
}


void SummaryProcessor::outputResult()
{
// Check if queueInfo is present for queue key
bmqp_ctrlmsg::QueueInfo queueInfo(d_allocator_p);

if (d_foundMessagesCount == 0) {
d_ostream << "No messages found." << '\n';
return; // RETURN
Expand All @@ -947,33 +945,36 @@ void SummaryProcessor::outputResult()
<< d_partiallyConfirmedGuids.size() << '\n';
d_ostream << "Number of outstanding messages: "
<< (d_foundMessagesCount - d_deletedMessagesCount) << '\n';

outputOutstandingRatio(d_ostream,
d_foundMessagesCount,
d_deletedMessagesCount);

d_ostream << "Total number of records: " << d_totalRecordsCount << "\n";
for(OtherRecordsMap::iterator it = d_otherRecordsCounts.begin(); it != d_otherRecordsCounts.end(); ++it) {
d_ostream << "Number of " << it->first<< " records: " << it->second << "\n";
for (OtherRecordsMap::iterator it = d_otherRecordsCounts.begin();
it != d_otherRecordsCounts.end();
++it) {
d_ostream << "Number of " << it->first << " records: " << it->second
<< "\n";
}

// Print information per Queue:
d_ostream << "Number of records per Queue:\n";




for(QueueRecordsMap::const_iterator it = d_queueRecordsMap.begin(); it != d_queueRecordsMap.end(); ++it) {
for (QueueRecordsMap::const_iterator it = d_queueRecordsMap.begin();
it != d_queueRecordsMap.end();
++it) {
bsls::Types::Uint64 totalRecordsCount = it->second;

// Skip this queue if the number of records for this queue is smaller than threshold
// Skip this queue if the number of records for this queue is smaller
// than threshold
if (totalRecordsCount < d_minRecordsPerQueue) {
continue;
}

const mqbu::StorageKey& queueKey = it->first;
bsl::size_t appKeysCount = d_queueAppRecordsMap[queueKey].size();

// Setup fields to be displayed
bsl::vector<const char*> fields(d_allocator_p);
fields.push_back("Queue");
Expand All @@ -988,17 +989,15 @@ void SummaryProcessor::outputResult()

bmqu::AlignedPrinter printer(d_ostream, &fields);


// Get queue information contained in CSL file
const bool queueInfoPresent = d_queueMap.findInfoByKey(
&queueInfo,
queueKey
);
const bool queueInfoPresent = d_queueMap.findInfoByKey(&queueInfo,
queueKey);

// Print queue id: either Key or URI
if (queueInfoPresent) {
printer << queueInfo.uri();
} else {
}
else {
printer << queueKey;
}

Expand All @@ -1007,33 +1006,39 @@ void SummaryProcessor::outputResult()
printer << d_queueQueueOpRecordsMap[queueKey];
printer << d_queueMessageRecordsMap[queueKey];
printer << d_queueConfirmRecordsMap[queueKey];

// Print number of records per App Key/Id
if (appKeysCount > 1U) {
bsl::stringstream ss;

// Sort Apps by number of records ascending
AppsData appsData;
for(QueueRecordsMap::const_iterator it = d_queueAppRecordsMap[queueKey].cbegin(); it != d_queueAppRecordsMap[queueKey].cend(); ++it) {
for (QueueRecordsMap::const_iterator it =
d_queueAppRecordsMap[queueKey].cbegin();
it != d_queueAppRecordsMap[queueKey].cend();
++it) {
appsData.emplace_back(it->second, it->first);
}
bsl::sort(appsData.begin(), appsData.end());

// Print number of records per App
for(AppsData::const_iterator it = appsData.cbegin(); it != appsData.cend(); ++it) {
for (AppsData::const_iterator it = appsData.cbegin();
it != appsData.cend();
++it) {
const mqbu::StorageKey& appKey = it->second;

// Try resolve App Key to string App Id
bsl::string appIdStr;
if (queueInfoPresent) {
RecordPrinter::findQueueAppIdByAppKey(&appIdStr,
queueInfo.appIds(),
appKey);
queueInfo.appIds(),
appKey);
}

if (!appIdStr.empty()) {
ss << appIdStr;
} else {
}
else {
ss << appKey;
}

Expand All @@ -1045,7 +1050,6 @@ void SummaryProcessor::outputResult()
printer << d_queueDeleteRecordsMap[queueKey];
}


// Print meta data of opened files
printJournalFileMeta(d_ostream, d_journalFile_p, d_allocator_p);
printDataFileMeta(d_ostream, d_dataFile_p);
Expand Down
33 changes: 19 additions & 14 deletions src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class SearchResult {
/// and `recordOffset`.
virtual bool processQueueOpRecord(const mqbs::QueueOpRecord& record,
bsls::Types::Uint64 recordIndex,
bsls::Types::Uint64 recordOffset);
bsls::Types::Uint64 recordOffset);
/// Process `journalOp` record with the specified `record`, `recordIndex`
/// and `recordOffset`.
virtual bool processJournalOpRecord(const mqbs::JournalOpRecord& record,
Expand Down Expand Up @@ -599,10 +599,14 @@ class SummaryProcessor : public SearchResult {
// PTIVATE TYPES

typedef bsl::unordered_set<bmqt::MessageGUID> GuidsSet;
typedef bsl::unordered_map<mqbu::StorageKey, bsls::Types::Uint64> QueueRecordsMap;
typedef bsl::unordered_map<mqbu::StorageKey, QueueRecordsMap> QueueAppRecordsMap;
typedef bsl::unordered_map<mqbs::RecordType::Enum, bsls::Types::Uint64> OtherRecordsMap;
typedef bsl::vector<bsl::pair<bsls::Types::Uint64, mqbu::StorageKey>> AppsData;
typedef bsl::unordered_map<mqbu::StorageKey, bsls::Types::Uint64>
QueueRecordsMap;
typedef bsl::unordered_map<mqbu::StorageKey, QueueRecordsMap>
QueueAppRecordsMap;
typedef bsl::unordered_map<mqbs::RecordType::Enum, bsls::Types::Uint64>
OtherRecordsMap;
typedef bsl::vector<bsl::pair<bsls::Types::Uint64, mqbu::StorageKey> >
AppsData;
// Set of message guids.

// PRIVATE DATA
Expand All @@ -626,9 +630,9 @@ class SummaryProcessor : public SearchResult {
bsls::Types::Uint64 d_totalRecordsCount;
// Counter of total number of records.

QueueRecordsMap d_queueRecordsMap;
QueueRecordsMap d_queueRecordsMap;
// Map containing total records counts per queue
OtherRecordsMap d_otherRecordsCounts;
OtherRecordsMap d_otherRecordsCounts;
// Map containing counts per record type which are not processed by default
QueueAppRecordsMap d_queueAppRecordsMap;
// Map containing counts of records per Queue/App
Expand All @@ -646,7 +650,8 @@ class SummaryProcessor : public SearchResult {
// Reference to 'QueueMap' instance.

bsls::Types::Uint64 d_minRecordsPerQueue;
// Minimum number of records for the queue to be displayed its detailed info
// Minimum number of records for the queue to be displayed its detailed
// info

bslma::Allocator* d_allocator_p;
// Pointer to allocator that is used inside the class.
Expand Down Expand Up @@ -707,13 +712,13 @@ class SummaryProcessor : public SearchResult {
void handleAnyRecordType();
};

// =================================================
// INLINE FUNCTION DEFINITIONS
// =================================================

// =================================================
// INLINE FUNCTION DEFINITIONS
// =================================================

inline void SummaryProcessor::handleAnyRecordType() {
d_totalRecordsCount++;
inline void SummaryProcessor::handleAnyRecordType()
{
d_totalRecordsCount++;
}

} // close package namespace
Expand Down

0 comments on commit 608ae0c

Please sign in to comment.