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

feat: support separate trie database #2021

Merged
merged 18 commits into from
Mar 8, 2024

Conversation

flywukong
Copy link
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
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
miner/stress/clique/main.go Outdated Show resolved Hide resolved
@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
cmd/utils/flags.go Outdated Show resolved Hide resolved
cmd/utils/flags.go Outdated Show resolved Hide resolved
cmd/geth/chaincmd.go Outdated Show resolved Hide resolved
@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
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
core/rawdb/database.go Outdated Show resolved Hide resolved
@sysvm
Copy link
Contributor

sysvm commented Jan 31, 2024

Can users merge separate trie db?

@flywukong
Copy link
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
cmd/geth/snapshot.go Outdated Show resolved Hide resolved
cmd/utils/flags.go Outdated Show resolved Hide resolved
core/blockchain.go Outdated Show resolved Hide resolved
cmd/geth/dbcmd.go Outdated Show resolved Hide resolved
core/rawdb/accessors_trie.go Outdated Show resolved Hide resolved
core/rawdb/accessors_trie.go Outdated Show resolved Hide resolved
@@ -659,14 +690,14 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
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
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
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
Contributor

Choose a reason for hiding this comment

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

Got it.

fynnss
fynnss previously approved these changes Mar 6, 2024
Copy link
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

@@ -91,7 +91,8 @@ func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) {
infos = append(infos, info)

case StateFreezerName:
if ReadStateScheme(db) != PathScheme {
if
ReadStateScheme(db) != PathScheme {
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -659,14 +690,14 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
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
Contributor

Choose a reason for hiding this comment

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

Got it.

Copy link

@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
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

@flywukong flywukong merged commit def3512 into bnb-chain:develop Mar 8, 2024
7 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.

5 participants