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

Adds poolshare index for BucketsDB #4224

Merged
merged 1 commit into from Mar 18, 2024

Conversation

SirTyson
Copy link
Contributor

Description

Resolves #4223

This extends BucketIndex to include a map of Asset -> poolID in order to optimize loadPoolShareTrustLinesByAccountAndAsset. This change improves query performance by around ~2500x and minimally impacts memory overhead. I suspect the memory increase is approximately 1.5 MB, but this is so small that I was not able to measure a change during testing.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

@@ -37,6 +37,9 @@ class BucketManager;
// BucketIndex abstract interface
class BucketIndex : public NonMovableOrCopyable
{
protected:
static const inline std::vector<PoolID> kEmptyVec = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't follow the naming style. Also I don't think it needs to be a class member as it's only used in a single function (so could be defined right there).

@@ -45,7 +49,7 @@ template <class IndexT> class BucketIndexImpl : public BucketIndex
void
load(Archive& ar)
{
ar(keysToOffset, filter);
ar(assetToPoolID, keysToOffset, filter);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a risk of loading the old version with the new code (or vice versa)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, in BucketIndex::load, we load the version and pageSize first. These two values are always serialized first no matter the index version. Then we check the index version, and if the on-disk version number doesn't match the expected version number, we drop the on-disk index and reindex from scratch.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we delete the outdated index right away instead of keeping both until the bucket gets cleaned up? (so that we don't accidentally use it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't actually have both indexes persisted, but we generate a new index, then rename the new index the the same name as the old index. On linux, this deletes the old file. However, I looked up in the standard and this behavior is implementation defined, so I agree we should delete explicitly here.

Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@marta-lokhova marta-lokhova left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -45,7 +49,7 @@ template <class IndexT> class BucketIndexImpl : public BucketIndex
void
load(Archive& ar)
{
ar(keysToOffset, filter);
ar(assetToPoolID, keysToOffset, filter);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we delete the outdated index right away instead of keeping both until the bucket gets cleaned up? (so that we don't accidentally use it)

@marta-lokhova
Copy link
Contributor

r+ 66c6f1f

@latobarita latobarita merged commit c8832e7 into stellar:master Mar 18, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve loadPoolShareTrustLinesByAccountAndAsset in BucketListDB
5 participants