blazingmq icon indicating copy to clipboard operation
blazingmq copied to clipboard

Refactor bmqu::AlignedPrinter to accept vector of strings

Open 678098 opened this issue 1 year ago • 9 comments

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 pass bsl::vector<bsl::string>.
  • It also stores this vector as a field.
  • To get the const char* length, bsl::strlen is 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::AlignedPrinter constructor expects bsl::string, not const char*
  • [ ] bmqu::AlignedPrinter also stores these strings as a const bsl::vector<bsl::string> field (might be a pointer, might be a reference)
  • [ ] Add precondition assert that d_fields_p is not NULL in constructor AlignedPrinter::AlignedPrinter or 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

678098 avatar Jan 13 '25 14:01 678098

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

ariraein avatar Feb 03 '25 19:02 ariraein

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>"

678098 avatar Feb 04 '25 11:02 678098

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*> with bsl::vector<bsl::string> . no longer stores raw const char* pointers . avoids unnecessary bsl::strlen calls . no dangling pointers --> safer memory management

  • Stored d_fields as a const bsl::vector<bsl::string>& to make sure fields remains valid throughout AlignedPrinter lifetime

  • Added a precondition assertion to make sure fields is not empty BSLS_ASSERT(!d_fields.empty( ))

  • Simplified maxLen calculation by removing bsl::strlen using bsl::string::size( )

  • Also updated operator<< to use bsl::string::size( ) for correct alignment

  • Updated instance where AlignedPrinter class 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);

ariraein avatar Feb 07 '25 03:02 ariraein

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

678098 avatar Feb 07 '25 14:02 678098

@ariraein Are you still working on this issue?

vinay-deshmukh avatar Apr 17 '25 00:04 vinay-deshmukh

@vinay-deshmukh yes, waiting for review: https://github.com/bloomberg/blazingmq/pull/605

ariraein avatar Apr 17 '25 01:04 ariraein

@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. ```

kapil0x avatar Aug 28 '25 00:08 kapil0x

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 avatar Aug 28 '25 14:08 678098

@678098 Thanks Evgenii

We have seen this PR and currently we have a concern that we need to discuss internally. What is the concern?

kapil0x avatar Aug 28 '25 22:08 kapil0x