-
Notifications
You must be signed in to change notification settings - Fork 10
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
weighted_tree: make load_accounting_db public #103
weighted_tree: make load_accounting_db public #103
Conversation
Just a quick comment: did you want to put the new public function into the |
f3c7de7
to
79440d3
Compare
OK, now that #97 has landed, I think this is ready for review. |
@cmoussa1: I understand you want to create a public interface that will instantiate a weighted tree object with the given DB. I have two concerns: 1) by placing this file to the weighted_tree library code, we are breaking a good separation of concern. I think it perhaps makes better sense to keep I'd suggest the following.
Hope this makes sense. |
b60f940
to
1d9575b
Compare
Thanks for your feedback and suggestions @dongahn - I pushed up a couple of changes that moves the load-DB code and its unit test file and sample DB's into their own directory under
I think I could use some more clarification here. Are you thinking that this code could add additional context when an error occurs while interacting with the SQLite database? To the best of my knowledge, the rc = sqlite3_bind_text (c_shrs, 1, bank_name.c_str (), -1, NULL);
if (rc != SQLITE_OK) {
std::cerr << sqlite3_errmsg (DB) << std::endl;
errno = EPROTO;
return nullptr;
} But maybe there is something more this code could do that I don't know about. Maybe the |
@cmoussa1: please see the error message string support here. If you have something like that in the reader base class, you can change the above code: rc = sqlite3_bind_text (c_shrs, 1, bank_name.c_str (), -1, NULL);
if (rc != SQLITE_OK) {
m_err_msg += sqlite3_errmsg (DB) + std::string (" ");
errno = EPROTO;
return nullptr;
} This way, if the user code of the reader object wants to print out an error message, they can do something like this code Each user of your code would have its own preferred way to log messages and it won't be pretty if your public API prints out things in stderr/stdout. Also as I see this, I think |
PR flux-framework#97 adds the ability to create a populated weighted tree from a flux-accounting DB for testing purposes. That functionality will be required moving forward to handle flux-framework#63. To make this easier, pull the load_accounting_db.* source files out of the "test" directory and move them to a new directory "reader", located under "fairness." Rename the load_accounting_db.* files to data_reader_db.*. Also move the unit test file and sample databases to the reader directory. Fixes flux-framework#102
Now that the load_accounting_db source and test code is located in another directory "reader", remove its compilation instructions from the Makefile located in src/fairness/weighted_tree/test/.
4118d4c
to
96fe84b
Compare
@@ -0,0 +1,39 @@ | |||
/*****************************************************************************\ | |||
* Copyright (c) 2020 Lawrence Livermore National Security, LLC. Produced at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020
-> 2021
std::cerr << "error opening DB: " << sqlite3_errmsg (DB) << std::endl; | ||
std::stringstream msg; | ||
msg << "error opening DB: " << sqlite3_errmsg (DB); | ||
m_err_msg += msg.str (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per @dongahn 's verbal comment, the +=
is useful for recursive functions, but for single-invocation functions, using =
is preferred to ensure stale errors are not included.
|
||
static void test_fairshare_order (const std::string &filename, | ||
const std::vector<std::string> &expected) | ||
{ | ||
bool bo = true; | ||
std::shared_ptr<weighted_tree_node_t> root; | ||
data_reader_db_t data_reader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only have one derived class so far, so this is probably fine, but once we have additional derived classes, we will probably need a factory class like in resource
's reader
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks for pointing this out. What do you think about me posting a follow-up PR after this one that adds a factory class? I can open an issue to track this.
I also don't mind adding another commit that adds the factory class in this PR if we'd like to have it available from the start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about me posting a follow-up PR after this one that adds a factory class? I can open an issue to track this.
Sounds good to me.
Thanks for your review @SteVwonder! I pushed up a couple of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM! Just one comment on the changes. Thanks @cmoussa1!
9802369
to
955070c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM! Thanks @cmoussa1!
Thank you! I'll go ahead and set MWP. |
@cmoussa1: just a quick thing. For error message where you use |
Thanks for pointing that out! I will post an update that add a newline before I set MWP. |
@cmoussa1: thanks Chris. I think a newline would be a bit better for users. The user of this API can more easily split the error message using the newline as the token and decide what to do (e.g., printing only the last message, finding uniq messages etc...) |
Refactor data_reader_db to be a subclass of data_reader_base. Remove the use of std::cerr and instead append or assign error messages to a class attribute named m_err_msg.
955070c
to
7a47a2e
Compare
Codecov Report
@@ Coverage Diff @@
## master #103 +/- ##
===========================================
+ Coverage 70.46% 89.56% +19.10%
===========================================
Files 16 12 -4
Lines 1202 556 -646
===========================================
- Hits 847 498 -349
+ Misses 355 58 -297
|
OK, now CI is happy. @dongahn I just pushed up a change to add a newline with |
Thank you! 🎉 |
note: this PR is built on top of #97 and should not be reviewed/merged until that one lands. I'll keep it as a draft PR for now.
PR #97 adds the ability to create a populated weighted tree from a flux-accounting DB for testing purposes. That functionality will be required moving forward to handle #63.
To make this easier, this PR pulls the
load_accounting_db.*
files out of the "test" directory and up a level intoweighted_tree/
.Fixes #102