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

Tx tables fix #3888

Closed
wants to merge 2 commits into from
Closed

Tx tables fix #3888

wants to merge 2 commits into from

Conversation

undertome
Copy link
Contributor

This is just an extension for a previously approved PR - #3815 which is from a deleted repository.

I added some changes in an attempt to improve logic and readbility. Fortunately these changes are included in a separate commit to make things easier.

Copy link
Contributor

@cjcobb23 cjcobb23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of places where we have to check the value of useTxTables_. It's seems like this might be a little error prone. What do you think of creating two separate classes, one for when useTxTables_ is true, and one for when it's false? The class used in the false case would just return an empty optional for all of the functions that query the tx tables.

@@ -277,7 +277,11 @@ getTxHistory(
* @param j Journal.
* @return Vector of pairs of found transactions and their metadata
* sorted in ascending order by account sequence.
* Also number of transactions processed.
* Also number of transactions processed or skpiied.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on skpiied

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return true;
});
/* else use shard databases, if available */
if (shardStoreExists() && useTxTables_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these functions can just return early if useTxTables_ is false. There's no need to do anything else. So at the top of the function:

if(!useTxTables_)
    return {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* Also number of transactions processed or skpiied.
* If this number is >= 0, then it means number of transactions
* processed, if it is < 0, then ~number means number of transactions
* skipped. We need to skip some quantity of transactions if option
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning ~number for the number of transactions skipped is a very strange interface. I'd suggest returning -number instead - unless there's some strange reason why ~number is better, in which case we should document that reason (here and other functions as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change the interface. My guess is that he went with ~number to avoid the awkward case of effectively saying something like total = -total where total == 0. But that's not really a big deal; the 0 case still works with the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return !res;
});
return res;
/* else use shard databases, if available */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is better off without comments that repeat what the next line of code does (here and in many other places in this file). You don't need to change that now (it's a minor nit), but new code should not include such comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I'll consider removing these as I dig deeper into refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up removing them when addressing CJ's comment about returning early when transaction tables are disabled. Done

Copy link
Collaborator

@mtrippled mtrippled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested that this works with use_tx_tables = 0, so it fixes the original problem.

Looks good to me besides the casting I mentioned.

* @return True if node ledger DB exists.
*/
bool
existsLedger()
{
return !!lgrdb_;
return (bool)lgrdb_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bool() operator automatically evaluates whether a unique_ptr contains something, so casting is redundant.

Also, the way to cast this if you really needed to would be by using something like static_cast(anotherpodtype);

Copy link
Contributor Author

@undertome undertome Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler actually doesn't invoke the bool operator without the cast. Changed to static_cast instead.

* @return True if node transaction DB exists.
*/
bool
existsTransaction()
{
return !!txdb_;
return (bool)txdb_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See casting comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to static_cast

Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for changing the interface to use -number instead of ~number.

@undertome
Copy link
Contributor Author

There are a lot of places where we have to check the value of useTxTables_. It's seems like this might be a little error prone. What do you think of creating two separate classes, one for when useTxTables_ is true, and one for when it's false? The class used in the false case would just return an empty optional for all of the functions that query the tx tables.

I like that approach in certain scenarios. For instance I used it with the ShardArchiveHandler where a derived type is instantiated when the handler is starting in recovery mode. But I think its a bit heavy handed to create a separate class with separate functions just for this single bool.

Copy link
Collaborator

@mtrippled mtrippled left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@undertome undertome added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Jul 29, 2021
@undertome
Copy link
Contributor Author

LGTM +1

Ran the test again - it checks out.

Copy link
Contributor

@cjcobb23 cjcobb23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@manojsdoshi manojsdoshi mentioned this pull request Sep 9, 2021
@nbougalis nbougalis mentioned this pull request Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants