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

In memory testing #4562

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

SirTyson
Copy link
Contributor

@SirTyson SirTyson commented Nov 27, 2024

Description

Resolves #4501 and partially resolves 4502

This PR removes --in-memory. Specifically, core will not crash if this flag is passed in for Horizon compatibility reasons, but will ignore it and related flags.

Additionally, --in-memory has been cannibalized to use in testing. Previously, any test that committed changes directly to the root ltx was incompatible with BucketListDB and required SQL. This is an issue, as we are deprecating SQL for ledger state, and it would not make sense to maintain this SQL overhead for testing only. While I've removed most of the in-memory code, I've saved the bits regarding the never committing ledger root to use for the direct ltx commit test cases. Thus we remove the test dependency for SQL.

In order to properly test the orderbook, the in-memory testing mode still maintains and queries a SQL database just for offers (similar to what BucketListDB does).

Originally I did one PR for removing SQL, --in-memory and mandating background eviction. This was way to big to merge but may be helpful in providing context on what changes are in flight after this PR: #4504.

Currently everything works except for the "herder externalizes values" test. With BucketListDB testing mode, nodes can be restarted, but direct ltx commits are not supported. With the in-memory mode testing, ltx can be committed to directly, but nodes can not be restarted.

For all tests except for "herder externalizes values", this if fine. However, "herder externalizes values" is the only test that both directly commits to the ltx and restarts nodes. In particular, the setupUpgradeAtNextLedger function directly commits to the ltx. I've seperated the test into two helper functions, one that doesn't require restart and one that does. I think that the restart test doesn't actually require an upgrade to occur. I think the test just used upgrades in order to populate ledgers with some meaningful, detectable work to make sure externalized ledgers aren't applied several times. If the upgrade operation is not integral to this test, we can probably find a workaround. Alternatively, we can maybe go through the full upgrade arming process with BucketListDB support instead of cutting corners with direct ltx commits. I'm not well versed in herder tests though, so I've left the failing test as is. If we can remove the upgrade and check the condition some other way, this is the path of least resistance.

Test has been fixed to use upgrades compatible with BucketListDB.

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

@dmkozh
Copy link
Contributor

dmkozh commented Nov 27, 2024

I think the test just used upgrades in order to populate ledgers with some meaningful,

I don't think that's the reason, the upgrade is there to make sure that ledgers with upgrades can be externalized out of order (that's important due to how config changes impact the internal core state). #4012 is the issue for which this has been introduced. So I don't think we should remove this.

Alternatively, we can maybe go through the full upgrade arming process with BucketListDB support instead of cutting corners with direct ltx commits.

Yeah, I think that's the right course of the action.

Copy link
Contributor

@bboston7 bboston7 left a comment

Choose a reason for hiding this comment

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

I agree with @dmkozh that the upgrade-specific logic seems important to test here.

Alternatively, we can maybe go through the full upgrade arming process with BucketListDB support instead of cutting corners with direct ltx commits.

I think this is a good idea even independent of the details of this specific test. When possible, avoiding the corner-cutting should lead to a more realistic and better overall test IMO.

// in-memory ltx. However, we still want to test SQL backed offers. The
// "never" committing root sets this flag to true such that offer-related
// calls get based to the real SQL backed root
AbstractLedgerTxnParent* const mRealRootForOffers;
Copy link
Contributor

Choose a reason for hiding this comment

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

Storing raw pointers like this always makes me a little nervous about the potential for dangling pointers. From the comment it looks like this is only intended to be used for testing, so maybe it's OK. If that's the case then the constructor should document this and throw if realRoot != nullptr when BUILD_TESTS isn't set. Otherwise I think this should be a smart pointer or optional type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Going through the PR a bit further, it looks like this whole class is only used for testing? If that's the case, then maybe the entire class should be behind BUILD_TESTS so no one tries to use it inappropriately.

Copy link
Contributor Author

@SirTyson SirTyson Nov 28, 2024

Choose a reason for hiding this comment

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

InMemoryLedgerTxn classes now behind BUILD_TESTS. I think the raw pointer was left over from the initial prod implementation, but has been refactored to a reference.

@@ -1221,25 +1168,19 @@ int
runNewDB(CommandLineArgs const& args)
{
CommandLine::ConfigOption configOption;
bool minimalForInMemoryMode = false;
[[maybe_unused]] bool minimalForInMemoryMode = false;
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 reason to keep this variable around instead of removing 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.

See below

Comment on lines +1480 to +1482
[[maybe_unused]] bool inMemory = false;
[[maybe_unused]] uint32_t startAtLedger = 0;
[[maybe_unused]] std::string startAtHash;
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 reason to keep these variables around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, I want clara to be able to parse the flags so we don't throw and crash, but I don't want to actually use the variables. It takes a reference and idk what clara is doing under the hood, so I used separate variables like the library intended to be on the safe side.

@@ -419,23 +371,21 @@ clara::Opt
inMemoryParser(bool& inMemory)
{
return clara::Opt{inMemory}["--in-memory"](
"(DEPRECATED) store working ledger in memory rather than database");
"(DEPRECATED) flag is ignored and will be removed soon.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not remove the argument altogether and let core fail to start? Same question goes for --start-at-ledger and --start-at-hash. I think that provides a better user experience than ignoring flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was specifically a request from platform. there are some Horizon configs that use this flag that are niche and no longer supported, but still exist in the codebase. They wanted us to just ignore the flags for now and not crash so that we don't have a breaking point release.

@SirTyson
Copy link
Contributor Author

Got the test to work with BucketList friendly upgrades and pushed some cleanups around BUILD_TESTS flags, should be good to go now.

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.

Deprecate --in-memory mode
3 participants