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

Refactor bmqu::AlignedPrinter to accept vector of strings #564

Open
5 tasks
678098 opened this issue Jan 13, 2025 · 4 comments
Open
5 tasks

Refactor bmqu::AlignedPrinter to accept vector of strings #564

678098 opened this issue Jan 13, 2025 · 4 comments
Labels
good first issue Good for newcomers

Comments

@678098
Copy link
Collaborator

678098 commented Jan 13, 2025

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.

const bsl::vector<const char*>* fields,

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 678098 added enhancement New feature or request good first issue Good for newcomers and removed enhancement New feature or request labels Jan 13, 2025
@ariraein
Copy link

ariraein commented Feb 3, 2025

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

@678098
Copy link
Collaborator Author

678098 commented Feb 4, 2025

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

@ariraein
Copy link

ariraein commented Feb 7, 2025

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);

@678098
Copy link
Collaborator Author

678098 commented Feb 7, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants