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

SQLite: Allow configurable sqlite database pragma variables. #5135

Merged
merged 15 commits into from
Sep 20, 2024

Conversation

dangell7
Copy link
Collaborator

@dangell7 dangell7 commented Sep 15, 2024

High Level Overview of Change

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

Attention: Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.2%. Comparing base (0ece395) to head (dadc84a).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/app/rdb/detail/Vacuum.cpp 0.0% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           develop   #5135   +/-   ##
=======================================
  Coverage     76.2%   76.2%           
=======================================
  Files          760     760           
  Lines        61550   61568   +18     
  Branches      8125    8123    -2     
=======================================
+ Hits         46881   46905   +24     
+ Misses       14669   14663    -6     
Files with missing lines Coverage Δ
src/xrpld/app/rdb/backend/detail/Node.cpp 58.4% <100.0%> (ø)
src/xrpld/app/rdb/detail/Wallet.cpp 78.6% <100.0%> (ø)
src/xrpld/core/DatabaseCon.h 100.0% <ø> (ø)
src/xrpld/core/detail/DatabaseCon.cpp 90.6% <100.0%> (+1.7%) ⬆️
src/xrpld/app/rdb/detail/Vacuum.cpp 0.0% <0.0%> (ø)

... and 4 files with indirect coverage changes

Impacted file tree graph

@vvysokikh1
Copy link
Collaborator

vvysokikh1 commented Sep 17, 2024

hey, I've been testing this PR and I can't make page_size work. It always sets it to 4096 with brand new transaction.db file. Does it work for you?

UPD: I think I've found the problem after debugging it for some time. Looks like the following code has an issue:

    template <std::size_t N, std::size_t M>
    DatabaseCon(
        boost::filesystem::path const& pPath,
        std::vector<std::string> const* commonPragma,
        std::array<std::string, N> const& pragma,
        std::array<char const*, M> const& initSQL,
        beast::Journal journal)
        : session_(std::make_shared<soci::session>()), j_(journal)
    {
        open(*session_, "sqlite", pPath.string());

        if (commonPragma)
        {
            for (auto const& p : *commonPragma) <<< some of the statement here creates a page in DB file, lockoing it to default 4096
            {
                soci::statement st = session_->prepare << p;
                st.execute(true);
            }
        }
        for (auto const& p : pragma) <<< This is the place where we set page_size
        {
            soci::statement st = session_->prepare << p;
            st.execute(true);
        }
        for (auto const& sql : initSQL)
        {
            soci::statement st = session_->prepare << sql;
            st.execute(true);
        }
    }

Changing the ordering of commonPragma and pragma helps to set the correct page_size. I'm not entirely sure this is correct solution though

UPD2: I understand this issue is not directly linked to your PR so I can take over the fix in this/other branch if you don't want to bother

Copy link
Collaborator

@vvysokikh1 vvysokikh1 left a comment

Choose a reason for hiding this comment

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

As mentioned in previous comment, this change doesn't actually work. I've debugged the main problem and here're some nitpicks mostly

src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
src/xrpld/core/DatabaseCon.h Show resolved Hide resolved
cfg/rippled-example.cfg Outdated Show resolved Hide resolved
src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
@dangell7
Copy link
Collaborator Author

hey, I've been testing this PR and I can't make page_size work. It always sets it to 4096 with brand new transaction.db file. Does it work for you?

UPD: I think I've found the problem after debugging it for some time. Looks like the following code has an issue:

    template <std::size_t N, std::size_t M>
    DatabaseCon(
        boost::filesystem::path const& pPath,
        std::vector<std::string> const* commonPragma,
        std::array<std::string, N> const& pragma,
        std::array<char const*, M> const& initSQL,
        beast::Journal journal)
        : session_(std::make_shared<soci::session>()), j_(journal)
    {
        open(*session_, "sqlite", pPath.string());

        if (commonPragma)
        {
            for (auto const& p : *commonPragma) <<< some of the statement here creates a page in DB file, lockoing it to default 4096
            {
                soci::statement st = session_->prepare << p;
                st.execute(true);
            }
        }
        for (auto const& p : pragma) <<< This is the place where we set page_size
        {
            soci::statement st = session_->prepare << p;
            st.execute(true);
        }
        for (auto const& sql : initSQL)
        {
            soci::statement st = session_->prepare << sql;
            st.execute(true);
        }
    }

Changing the ordering of commonPragma and pragma helps to set the correct page_size. I'm not entirely sure this is correct solution though

UPD2: I understand this issue is not directly linked to your PR so I can take over the fix in this/other branch if you don't want to bother

Thank you for looking into it. You're welcome to take over.

cfg/rippled-example.cfg Outdated Show resolved Hide resolved
Copy link
Collaborator

@vvysokikh1 vvysokikh1 left a comment

Choose a reason for hiding this comment

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

I've tested the last change and looks good to me. Ideally I would prefer the tests to check those <512 and >65536 and not power of 2 values but it's good to go anyways

@dangell7
Copy link
Collaborator Author

dangell7 commented Sep 18, 2024

I've tested the last change and looks good to me. Ideally I would prefer the tests to check those <512 and >65536 and not power of 2 values but it's good to go anyways

Agree tests are a must before this is merged. I'll write them today.

src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
@intelliot intelliot mentioned this pull request Sep 19, 2024
1 task
cfg/rippled-example.cfg Show resolved Hide resolved
cfg/rippled-example.cfg Show resolved Hide resolved
src/test/nodestore/Database_test.cpp Outdated Show resolved Hide resolved
src/test/nodestore/Database_test.cpp Outdated Show resolved Hide resolved
src/xrpld/core/detail/DatabaseCon.cpp Outdated Show resolved Hide resolved
@intelliot intelliot mentioned this pull request Sep 20, 2024
1 task
Copy link
Collaborator

@Bronek Bronek left a comment

Choose a reason for hiding this comment

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

Just two more minor changes in the configuration documentation section, this aside this is good.

cfg/rippled-example.cfg Outdated Show resolved Hide resolved
cfg/rippled-example.cfg Outdated Show resolved Hide resolved
intelliot pushed a commit that referenced this pull request Sep 20, 2024
The page_size will soon be made configurable with #5135, making this
re-ordering necessary.

When opening SQLite connection, there are specific pragmas set with
commonPragmas.

In particular, PRAGMA journal_mode creates journal file and locks the
page_size; as of this commit, this sets the page size to the default
value of 4096. Coincidentally, the hardcoded page_size was also 4096, so
no issue was noticed.
@Bronek
Copy link
Collaborator

Bronek commented Sep 20, 2024

@dangell7 can you please merge into your branch from develop branch ? Please remember to use -S. Thanks !

@Bronek
Copy link
Collaborator

Bronek commented Sep 20, 2024

@dangell7 thank you for merging current develop; do you think this PR is ready for merge ?

@dangell7
Copy link
Collaborator Author

@Bronek yes thank you! LGTM

@intelliot intelliot added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Sep 20, 2024
@intelliot intelliot merged commit a753099 into XRPLF:develop Sep 20, 2024
20 checks passed
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