Refactor bmqu::AlignedPrinter to accept vector of strings
Is your feature request related to a problem?
bmqu::AlignedPrinter class has some problems:
- The class' API expects
bsl::vector<const char*>argument which is strange. The conventional way is to passbsl::vector<bsl::string>. - It also stores this vector as a field.
- To get the
const char*length,bsl::strlenis used.
https://github.com/bloomberg/blazingmq/blob/e19ff338c707b114e9f84d83ea866a97518afb37/src/groups/bmq/bmqu/bmqu_alignedprinter.h#L92
Describe the solution you'd like
Refactor bmqu::AlignedPrinter, so:
- [ ]
bmqu::AlignedPrinterconstructor expectsbsl::string, notconst char* - [ ]
bmqu::AlignedPrinteralso stores these strings as aconst bsl::vector<bsl::string>field (might be a pointer, might be a reference) - [ ] Add precondition assert that
d_fields_pis not NULL in constructorAlignedPrinter::AlignedPrinteror initialize this field as a reference - [ ] Update usage examples in the unit's documentation
- [ ] Update the code that uses this class
Alternatives you considered
No response
Hi all. I have started working on this. This is my first time ever trying to contribute to an open-source library. Please forgive my ignorance if there is any issue with commenting here. Just to make sure, I have to complete the checklist above with five items, then follow the steps on Contributing page? Thanks, -Ari
Just to make sure, I have to complete the checklist above with five items
Hi Ari, that is correct. It's not enough to only modify bmqu::AlignedPrinter class API, because this class is used in several places, and the project build will be broken if we introduce a mismatch between class API and its usage in other components. If we merge a PR with a partial change, the build will be broken for everyone, and this is not good.
then follow the steps on Contributing page?
Yes. The most common problem on new contributions is DCO check. You need to ensure that you add DCO signature to all of your commits with -s flag: git commit -s -m "<My feature>"
Thanks for getting back to me @678098 and also your response. Please see below for a breakdown, and to doublecheck/confirm before next steps.
-
Replaced
bsl::vector<const char*>withbsl::vector<bsl::string>. no longer stores rawconst char*pointers . avoids unnecessarybsl::strlencalls . no dangling pointers --> safer memory management -
Stored
d_fieldsas aconst bsl::vector<bsl::string>&to make surefieldsremains valid throughoutAlignedPrinterlifetime -
Added a precondition assertion to make sure
fieldsis not emptyBSLS_ASSERT(!d_fields.empty( )) -
Simplified
maxLencalculation by removingbsl::strlenusingbsl::string::size( ) -
Also updated operator<< to use bsl::string::size( ) for correct alignment
-
Updated instance where
AlignedPrinterclass were used. Please see below:
src/groups/mqb/mqbs/mqbs_filestoreprotocolprinter.cpp
103 | bmqu::AlignedPrinter printer(stream, fields);
104 | printer << static_cast<unsigned int>(header.headerWords()) << os.str();
118 | bmqu::AlignedPrinter printer(stream, fields);
138 | bmqu::AlignedPrinter printer(stream, fields);
288 | bmqu::AlignedPrinter printer(stream, fields);
341 | bmqu::AlignedPrinter printer(stream, fields);
386 | bmqu::AlignedPrinter printer(stream, fields);
417 | bmqu::AlignedPrinter printer(stream, fields);
459 | bmqu::AlignedPrinter printer(stream, fields);
496 | bmqu::AlignedPrinter printer(stream, fields);
701 | bmqu::AlignedPrinter printer(BALL_LOG_OUTPUT_STREAM, fields);
714 | bmqu::AlignedPrinter p(BALL_LOG_OUTPUT_STREAM, appIdsInfo);
src/applications/bmqtool/m_bmqtool_storageinspector.cpp
477 | bmqu::AlignedPrinter printer(BALL_LOG_OUTPUT_STREAM, fields);
478 | bsls::Types::Uint64 lastRecPos =
581 | bmqu::AlignedPrinter printer(BALL_LOG_OUTPUT_STREAM, fields);
595 | bmqu::AlignedPrinter p(BALL_LOG_OUTPUT_STREAM, f, indent);
src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp
84 | bmqu::AlignedPrinter printer(ostream, fields);
85 | bsls::Types::Uint64 lastRecPos = journalFile_p->lastRecordPosition();
1375 | bmqu::AlignedPrinter printer(d_ostream, fields);
1399 | bmqu::AlignedPrinter printer(d_ostream, fields);
1458 | bmqu::AlignedPrinter printer(d_ostream, fields);
src/applications/bmqstoragetool/m_bmqstoragetool_recordprinter.cpp
74 | bmqu::AlignedPrinter printer(stream, fields);
75 | printer << rec.header().primaryLeaseId() << rec.header().sequenceNumber();
158 | bmqu::AlignedPrinter printer(stream, fields);
200 | bmqu::AlignedPrinter printer(stream, fields);
261 | bmqu::AlignedPrinter printer(stream, fields);
Thanks for getting back to me @678098 and also your response. Please see below for a breakdown, and to doublecheck/confirm before next steps.
The breakdown seems reasonable, however, there might be other places requiring changes. It's easier to solve this step by step iteratively and check that the PR with changes builds with our CI
@ariraein Are you still working on this issue?
@vinay-deshmukh yes, waiting for review: https://github.com/bloomberg/blazingmq/pull/605
@678098 I missed checking if someone was already working on the issue before starting work on this isse. However, looks like @ariraein had no activity on this PR for the last few months.
I put up PR: Refactor bmqu::AlignedPrinter to accept vector of strings #895
Let me know if I should work on getting my PR reviewed/merged?
Also, do I need to get approval everytime for running these workflows?
7 workflows awaiting approval
This workflow requires approval from a maintainer. ```
Hi @kapil0x, it's fine to proceed if there is no progress for a long time.
Let me know if I should work on getting my PR reviewed/merged?
We have seen this PR and currently we have a concern that we need to discuss internally.
Also, do I need to get approval everytime for running these workflows?
This happens for first-time contributors to the repo. If you merge any PR you will not need these approvals anymore.
@678098 Thanks Evgenii
We have seen this PR and currently we have a concern that we need to discuss internally. What is the concern?