Skip to content

feat: support separate trie database#2021

Merged
flywukong merged 18 commits intobnb-chain:developfrom
flywukong:support-speratedb
Mar 8, 2024
Merged

feat: support separate trie database#2021
flywukong merged 18 commits intobnb-chain:developfrom
flywukong:support-speratedb

Conversation

@flywukong
Copy link
Copy Markdown
Contributor

@flywukong flywukong commented Dec 1, 2023

Description

This PR introduces the functionality to run node with a separate trie database on a distinct disk or directory. This proposal aims to alleviate the bandwidth strain on the current key-value database, while also streamlining and simplifying the log-structured merge (LSM) of the database. These enhancements are anticipated to improve the read performance of the database and subsequently enhance the performance of geth.

Specifically, the PR includes the following features:

  1. Support for running geth with a separate trie database. Users can set the --separatetrie flag to enable a separate database for storing trie data. Both hash-based and path-based trie databases are supported.
  2. In the event of running with PBSS, the ancient state directory is also stored in the separate trie directory.
  3. If users intend to utilize this feature for running a fullnode or validator, they must either run --separatetrie from genesis or make use of the provided snapshot containing the separate trie database.
  4. The separate trie db use the subdirectory of /geth/chaindata which called "state". User can move the state subdirectory to any disk or directory and make a soft link called "state" under the /geth/chaindata

The inspected data below pertains to the execution of a fullnode in PBSS+Pebble mode across two separate disks.

This one shows the separate trie db
image

This one the db without trie data and ancient state
image

Rationale

Blow is the test result using different disk resource for trie.
image

avg import cost geth with single db is 324 ms while the cost of geth with seprated db is 291 ms.
The performance using seprated db has improve 10% (95 percent )

Example

// init geth with the separate trie db
./geth --datadir node  --state.scheme path --db.engine pebble --triedir trie init genesis.json

// run geth node with the separate  trie db
./geth --config config.toml --datadir node --triedir trie --cache 10000 --rpc.allow-unprotected-txs --syncmode full --state.scheme path

Changes

Notable changes:

  • N/A

@flywukong flywukong marked this pull request as draft December 4, 2023 03:27
@flywukong flywukong force-pushed the support-speratedb branch 3 times, most recently from 4fe0ab8 to 523ed87 Compare January 3, 2024 11:58
@flywukong flywukong marked this pull request as ready for review January 3, 2024 13:14
@flywukong flywukong changed the title feat: support speratedb feat: support sperated trie db Jan 3, 2024
@flywukong flywukong force-pushed the support-speratedb branch 4 times, most recently from 8b18c3d to 2b7cb26 Compare January 18, 2024 02:22
@flywukong flywukong force-pushed the support-speratedb branch 2 times, most recently from 8a4198b to aa616b6 Compare January 29, 2024 13:53
@flywukong flywukong changed the title feat: support sperated trie db feat: support separated trie database Jan 30, 2024
@sysvm
Copy link
Copy Markdown
Contributor

sysvm commented Jan 31, 2024

Can users merge separate trie db?

@flywukong
Copy link
Copy Markdown
Contributor Author

Can users merge separate trie db?

not needed for now

@flywukong flywukong changed the title feat: support separated trie database feat: support separate trie database Jan 31, 2024
bodies.Add(size)
case bytes.HasPrefix(key, blockReceiptsPrefix) && len(key) == (len(blockReceiptsPrefix)+8+common.HashLength):
receipts.Add(size)
case IsLegacyTrieNode(key, it.Value()):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why move it from 668-669 to 693-694?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is a known issue of inspect db , the precondition of the judgment conditions is used to avoid identifying some header metadata as hash trie data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it.

@flywukong flywukong force-pushed the support-speratedb branch from 38e115d to 8c13f99 Compare March 6, 2024 10:17
fynnss
fynnss previously approved these changes Mar 6, 2024
Copy link
Copy Markdown
Contributor

@fynnss fynnss left a comment

Choose a reason for hiding this comment

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

LGTM

case StateFreezerName:
if ReadStateScheme(db) != PathScheme {
if
ReadStateScheme(db) != PathScheme {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fix the lint error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

bodies.Add(size)
case bytes.HasPrefix(key, blockReceiptsPrefix) && len(key) == (len(blockReceiptsPrefix)+8+common.HashLength):
receipts.Add(size)
case IsLegacyTrieNode(key, it.Value()):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it.

@flywukong flywukong force-pushed the support-speratedb branch from 53f32a1 to 32159eb Compare March 8, 2024 07:18
Copy link
Copy Markdown

@RenRick RenRick 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
Copy Markdown
Contributor

@fynnss fynnss left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants