Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat[Storagetool]: List queue appid numrecords #534

Merged
merged 51 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4a3ab78
wip
bbpetukhov Nov 16, 2024
dc981b7
Add support for Queue URI
bbpetukhov Nov 16, 2024
8111259
Support printer formatting
bbpetukhov Nov 25, 2024
c9a7c23
Can calc records by type per queue
bbpetukhov Nov 25, 2024
4d091fe
Calculate per records counts app key
bbpetukhov Nov 25, 2024
90ab10a
Add ""min records per queue" cmd line parameter
bbpetukhov Nov 26, 2024
fd373de
Move printRecord methods to RecordPrinter namespace
alexander-e1off Nov 22, 2024
0757a2a
Resolve AppKey to AppId
bbpetukhov Nov 27, 2024
5b99185
Update README.md
bbpetukhov Nov 27, 2024
059aacd
Sort app ids ny num records in asc order
bbpetukhov Nov 27, 2024
621ca50
Add comments
bbpetukhov Nov 28, 2024
185194d
Run clang-format
bbpetukhov Nov 28, 2024
7f3fa10
Update src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp
bbpetukhov Dec 2, 2024
5734e06
Update src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp
bbpetukhov Dec 2, 2024
12dfb48
Update src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp
bbpetukhov Dec 2, 2024
55fdc36
Always print Queue Key in detailed queue information
bbpetukhov Dec 2, 2024
079d26c
Refactor method to calc total records count
bbpetukhov Dec 2, 2024
b0de035
Prefer const_iterator
bbpetukhov Dec 2, 2024
7295527
Make min-records-per-queue parameter unsigned
bbpetukhov Dec 2, 2024
959f269
Run clang-format
bbpetukhov Dec 2, 2024
1ef7d9b
Remove redundant Parameters default ctor
bbpetukhov Dec 2, 2024
ff069a3
Add unit test for queue detailed output
bbpetukhov Dec 2, 2024
e565543
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Dec 5, 2024
313e91e
Run clang-format
bbpetukhov Dec 5, 2024
15d034a
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Dec 9, 2024
988cccf
Fix unit tests
bbpetukhov Dec 20, 2024
5e9e56a
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Dec 20, 2024
e1eb49a
Run clang-format
bbpetukhov Dec 20, 2024
83463d6
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 9, 2025
c3a2fc8
Resolve conflicts after merge
bbpetukhov Jan 9, 2025
bc28fd7
Run clang-format
bbpetukhov Jan 9, 2025
8a085d4
Fix unit tests
bbpetukhov Jan 10, 2025
9c04387
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 10, 2025
4d1c251
Run clang format
bbpetukhov Jan 13, 2025
28fc3f5
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 13, 2025
e28074b
Refactor Parameters class - test creator helper function
bbpetukhov Jan 13, 2025
ff44dd3
Revert bmqu files
bbpetukhov Jan 15, 2025
5dae9e5
Remove redundant comments
bbpetukhov Jan 15, 2025
4fa70e0
Remove redundant virtual methods
bbpetukhov Jan 15, 2025
0cc6060
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 15, 2025
9ef1aec
Update src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.h
bbpetukhov Jan 16, 2025
dd8ff03
Update src/applications/bmqstoragetool/m_bmqstoragetool_journalfilepr…
bbpetukhov Jan 16, 2025
79017f2
Optimize queueInfo variable declaration
bbpetukhov Jan 16, 2025
22f0050
Update src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.h
bbpetukhov Jan 16, 2025
c6c87dd
Extend logic of createTestParameters helper function
bbpetukhov Jan 16, 2025
0c68133
Remove redundant function
bbpetukhov Jan 16, 2025
21f2298
Disable default alloc check in unit tests for SunOS
bbpetukhov Jan 16, 2025
86a267c
Use zero as default value for records limit
bbpetukhov Jan 16, 2025
2b6c8fd
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 16, 2025
f452ebc
Merge branch 'main' into list-queue-appid-numrecords
bbpetukhov Jan 17, 2025
01172e6
Initialize Command Line arguments fields to fix msan warning
bbpetukhov Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/applications/bmqstoragetool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Usage: bmqstoragetool [-r|record-type <record type>]*
[--details]
[--dump-payload]
[--dump-limit <dump limit>]
[--min-records-per-queue <threshold>]
[--summary]
[-h|help]
Where:
Expand Down Expand Up @@ -83,6 +84,8 @@ Where:
specify if you need message payload
--dump-limit <dump limit>
limit of payload output (default: 1024)
--min-records-per-queue
min number of records per queue for detailed info to be displayed
--summary
summary of all matching messages (number of outstanding messages and
other statistics)
Expand Down
6 changes: 6 additions & 0 deletions src/applications/bmqstoragetool/bmqstoragetool.m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ static bool parseArgs(CommandLineArguments& arguments,
"summary of all matching records",
balcl::TypeInfo(&arguments.d_summary),
balcl::OccurrenceInfo::e_OPTIONAL},
{"min-records-per-queue",
"min records per queue",
"min number of records per queue for detailed info to be displayed",
bbpetukhov marked this conversation as resolved.
Show resolved Hide resolved
balcl::TypeInfo(&arguments.d_minRecordsPerQueue),
balcl::OccurrenceInfo(
bsl::numeric_limits<bsls::Types::Int64>::max())},
bbpetukhov marked this conversation as resolved.
Show resolved Hide resolved
{"h|help",
"help",
"print usage)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ void outputGuidString(bsl::ostream& ostream,
ostream << bsl::endl;
}

/// Helper function to instantiate test Parameters
Parameters createTestParameters()
{
Parameters params(
CommandLineArguments(bmqtst::TestHelperUtil::allocator()),
bmqtst::TestHelperUtil::allocator());

params.d_processRecordTypes.d_message = true;
bbpetukhov marked this conversation as resolved.
Show resolved Hide resolved

return params;
};
bbpetukhov marked this conversation as resolved.
Show resolved Hide resolved

} // close unnamed namespace

static void test1_breathingTest()
Expand All @@ -189,7 +201,8 @@ static void test1_breathingTest()
journalFile.addAllTypesRecords(&records);

// Prepare parameters
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator())
Expand Down Expand Up @@ -247,7 +260,8 @@ static void test2_searchGuidTest()
journalFile.addAllTypesRecords(&records);

// Prepare parameters
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

// Get list of message GUIDs for searching
bsl::vector<bsl::string>& searchGuids = params.d_guid;
bsl::list<JournalFile::NodeType>::const_iterator recordIter =
Expand Down Expand Up @@ -315,7 +329,8 @@ static void test3_searchNonExistingGuidTest()
journalFile.addAllTypesRecords(&records);

// Prepare parameters
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

// Get list of message GUIDs for searching
bsl::vector<bsl::string>& searchGuids = params.d_guid;
bmqt::MessageGUID guid;
Expand Down Expand Up @@ -377,7 +392,7 @@ static void test4_searchExistingAndNonExistingGuidTest()
journalFile.addAllTypesRecords(&records);

// Prepare parameters
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

// Get list of message GUIDs for searching
bsl::vector<bsl::string>& searchGuids = params.d_guid;
Expand Down Expand Up @@ -465,8 +480,10 @@ static void test5_searchOutstandingMessagesTest()
true);

// Configure parameters to search outstanding messages
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_outstanding = true;

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator())
Expand Down Expand Up @@ -500,7 +517,6 @@ static void test5_searchOutstandingMessagesTest()
expectedStream << "Outstanding ratio: " << outstandingRatio << "% ("
<< outstandingGUIDS.size() << "/" << messageCount << ")"
<< bsl::endl;

BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

Expand Down Expand Up @@ -530,7 +546,8 @@ static void test6_searchConfirmedMessagesTest()
false);

// Configure parameters to search confirmed messages
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_confirmed = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
Expand Down Expand Up @@ -597,7 +614,8 @@ static void test7_searchPartiallyConfirmedMessagesTest()
&partiallyConfirmedGUIDS);

// Configure parameters to search partially confirmed messages
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_partiallyConfirmed = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
Expand Down Expand Up @@ -664,7 +682,8 @@ static void test8_searchMessagesByQueueKeyTest()
queueKey2);

// Configure parameters to search messages by queueKey1
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_queueKey.push_back(queueKey1);
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
Expand Down Expand Up @@ -733,7 +752,8 @@ static void test9_searchMessagesByQueueNameTest()
}
QueueMap qMap(bmqtst::TestHelperUtil::allocator());

Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_queueName.push_back("queue1");
params.d_queueMap.insert(queueInfo);

Expand Down Expand Up @@ -807,7 +827,8 @@ static void test10_searchMessagesByQueueNameAndQueueKeyTest()
}
QueueMap qMap(bmqtst::TestHelperUtil::allocator());

Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_queueName.push_back("queue1");
params.d_queueMap.insert(queueInfo);
params.d_queueKey.push_back(queueKey2);
Expand Down Expand Up @@ -865,7 +886,8 @@ static void test11_searchMessagesByTimestamp()
const bsls::Types::Uint64 ts2 = 40 * journalFile.timestampIncrement();

// Configure parameters to search messages by timestamps
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_range.d_timestampGt = ts1;
params.d_range.d_timestampLt = ts2;

Expand Down Expand Up @@ -941,7 +963,8 @@ static void test12_printMessagesDetailsTest()
false);

// Configure parameters to print message details
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_details = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
Expand Down Expand Up @@ -1073,7 +1096,8 @@ static void test13_searchMessagesWithPayloadDumpTest()

// Configure parameters to search confirmed messages GUIDs with dumping
// messages payload.
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_confirmed = true;
params.d_dumpPayload = true;
// Prepare file manager
Expand Down Expand Up @@ -1161,7 +1185,8 @@ static void test14_summaryTest()
&partiallyConfirmedGUIDS);

// Configure parameters to output summary
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_summary = true;
// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
Expand Down Expand Up @@ -1509,7 +1534,8 @@ static void test17_searchMessagesBySequenceNumbersRange()
const CompositeSequenceNumber seqNumLt(4, 6);

// Configure parameters to search messages by sequence number range
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_range.d_seqNumGt = seqNumGt;
params.d_range.d_seqNumLt = seqNumLt;
// Prepare file manager
Expand Down Expand Up @@ -1581,7 +1607,8 @@ static void test18_searchMessagesByOffsetsRange()
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE * 35 + k_HEADER_SIZE;

// Configure parameters to search messages by offsets
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_range.d_offsetGt = offsetGt;
params.d_range.d_offsetLt = offsetLt;
// Prepare file manager
Expand Down Expand Up @@ -1622,8 +1649,6 @@ static void test18_searchMessagesByOffsetsRange()
resultStream,
bmqtst::TestHelperUtil::allocator());
searchProcessor->process();

BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test19_searchQueueOpRecords()
Expand Down Expand Up @@ -1653,11 +1678,13 @@ static void test19_searchQueueOpRecords()
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE * 35 + k_HEADER_SIZE;

// Configure parameters to search queueOp records by offsets
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_processRecordTypes.d_message = false;
params.d_processRecordTypes.d_queueOp = true;
params.d_range.d_offsetGt = offsetGt;
params.d_range.d_offsetLt = offsetLt;

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator())
Expand Down Expand Up @@ -1729,11 +1756,13 @@ static void test20_searchJournalOpRecords()
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE * 35 + k_HEADER_SIZE;

// Configure parameters to search journalOp records by offsets
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_processRecordTypes.d_message = false;
params.d_processRecordTypes.d_journalOp = true;
params.d_range.d_offsetGt = offsetGt;
params.d_range.d_offsetLt = offsetLt;

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator())
Expand Down Expand Up @@ -1805,7 +1834,8 @@ static void test21_searchAllTypesRecords()
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE * 35 + k_HEADER_SIZE;

// Configure parameters to search journalOp records by offsets
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_processRecordTypes.d_message = true;
params.d_processRecordTypes.d_queueOp = true;
params.d_processRecordTypes.d_journalOp = true;
Expand Down Expand Up @@ -1904,7 +1934,8 @@ static void test22_searchQueueOpRecordsByOffset()
const size_t k_HEADER_OFFSET = sizeof(mqbs::FileHeader) / 2;

// Configure parameters to search queueOp records
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_processRecordTypes.d_message = false;
params.d_processRecordTypes.d_queueOp = true;

Expand Down Expand Up @@ -1977,7 +2008,8 @@ static void test23_searchJournalOpRecordsBySeqNumber()
journalFile.addAllTypesRecords(&records);

// Configure parameters to search journalOp
Parameters params(bmqtst::TestHelperUtil::allocator());
Parameters params = createTestParameters();

params.d_processRecordTypes.d_message = false;
params.d_processRecordTypes.d_journalOp = true;

Expand Down Expand Up @@ -2026,6 +2058,79 @@ static void test23_searchJournalOpRecordsBySeqNumber()
BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str());
}

static void test24_summaryWithQueueDetailsTest()
// ------------------------------------------------------------------------
// OUTPUT SUMMARY TEST
//
// Concerns:
// Search messages in journal file and output summary.
//
// Testing:
// JournalFileProcessor::process()
// ------------------------------------------------------------------------
{
bmqtst::TestHelper::printTestName(
"OUTPUT SUMMARY WITH QUEUE DETAILS TEST");

// Simulate journal file
const size_t k_NUM_RECORDS = 15;
JournalFile::RecordsListType records(bmqtst::TestHelperUtil::allocator());
JournalFile journalFile(k_NUM_RECORDS,
bmqtst::TestHelperUtil::allocator());
JournalFile::GuidVectorType partiallyConfirmedGUIDS(
bmqtst::TestHelperUtil::allocator());
journalFile.addJournalRecordsWithPartiallyConfirmedMessages(
&records,
&partiallyConfirmedGUIDS);

// Configure parameters to output summary
Parameters params = createTestParameters();

params.d_summary = true;
params.d_minRecordsPerQueue = 0;

params.d_processRecordTypes.d_message = true;

// Prepare file manager
bslma::ManagedPtr<FileManager> fileManager(
new (*bmqtst::TestHelperUtil::allocator())
FileManagerMock(journalFile),
bmqtst::TestHelperUtil::allocator());

// Run search
bmqu::MemOutStream resultStream(bmqtst::TestHelperUtil::allocator());
bslma::ManagedPtr<CommandProcessor> searchProcessor =
CommandProcessorFactory::createCommandProcessor(
&params,
fileManager,
resultStream,
bmqtst::TestHelperUtil::allocator());
searchProcessor->process();

// Prepare expected output
bmqu::MemOutStream expectedStream(bmqtst::TestHelperUtil::allocator());
expectedStream << "5 message(s) found.\n";
bsl::vector<const char*> fields(bmqtst::TestHelperUtil::allocator());
bbpetukhov marked this conversation as resolved.
Show resolved Hide resolved
fields.push_back("Number of partially confirmed messages");
fields.push_back("Number of confirmed messages");
fields.push_back("Number of outstanding messages");
bmqu::AlignedPrinter printer(expectedStream, &fields);
printer << 3 << 2 << 2;
expectedStream << "Outstanding ratio: 40% (2/5)\n";

expectedStream << "Total number of records: 15\n"
"Number of records per Queue:\n"
" Queue Key : 6162636465\n"
" Total Records : 15\n"
" Num Queue Op Records : 0\n"
" Num Message Records : 5\n"
" Num Confirm Records : 5\n"
" Num Delete Records : 5";

bsl::string res(resultStream.str(), bmqtst::TestHelperUtil::allocator());
ASSERT(res.starts_with(expectedStream.str()));
}

// ============================================================================
// MAIN PROGRAM
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -2059,6 +2164,7 @@ int main(int argc, char* argv[])
case 21: test21_searchAllTypesRecords(); break;
case 22: test22_searchQueueOpRecordsByOffset(); break;
case 23: test23_searchJournalOpRecordsBySeqNumber(); break;
case 24: test24_summaryWithQueueDetailsTest(); break;
default: {
cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;
bmqtst::TestHelperUtil::testStatus() = -1;
Expand Down
Loading
Loading