Skip to content

core: separated databases for block data#2227

Merged
zzzckck merged 10 commits intobnb-chain:developfrom
jingjunLi:impl_block_store
Apr 18, 2024
Merged

core: separated databases for block data#2227
zzzckck merged 10 commits intobnb-chain:developfrom
jingjunLi:impl_block_store

Conversation

@jingjunLi
Copy link
Copy Markdown
Contributor

@jingjunLi jingjunLi commented Feb 21, 2024

Description

This pull request uses the finalized block tag as the indicator for chain freezing and introduces the separation of block data into a dedicated blockdb. The principle support of PR: BEP-365: Support multi-database based on data pattern

uses the finalized block tag as the indicator for chain freezing

Originally, the latest 90K blocks will be retained in the key-value store by default, which is regarded as "non-finalized" in the context of Proof-of-work. However, in Proof-of-Stake, we do have the concrete finalized block tag from the consensus client. Therefore, it makes more sense to directly rely on the Finalized for chain freezing.

By deploying it on a full node, we can see there are only 23 blocks left in the key-value store.
image

introduces the separation of block data into a dedicated blockdb

  • Background
    recent blocks are first stored in a key-value (KV) database. Once they reach the ancient threshold, they will be moved to the ancient database, which wastes some disk bandwidth. Another thing that we should be aware of is EIP-4844. Once BSC supports EIP-4844, the block size will increase due to the inclusion of blobs. The size of the blob storage may not increase over time, but it will still demand extra disk space from the node operators.
  • Implement
    Split database by data pattern will make disk bandwidth usage more reasonable and improve the whole performance.

Rationale

tell us why we need these changes...

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@fynnss fynnss requested a review from RenRick February 22, 2024 02:26
node/node.go Outdated

if config.SeparateDB {
log.Info("SeparateDB is enabled, open block database, %s", config.DatabaseBlock)
blockStore, err = n.OpenBlockDatabase(name, config.DatabaseHandles-chainDataHandles, config.DatabaseBlock, namespace, readonly)
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.

config.DatabaseHandles-chainDataHandles euqals zero , it it no meaning.
You can consider allocating 1/10 of the handlers to the block store

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.

Cache and handles usage is modified as follows:
image

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.

We have a new Resource allocation rules:

  1. Allocate a fixed percentage of memory for chainDb based on chainDbMemoryPercentage & chainDbHandlesPercentage.
  2. Allocate a fixed size for blockDb based on blockDbCacheSize & blockDbHandlesSize.
  3. Allocate the remaining resources to stateDb.

@jingjunLi jingjunLi closed this Mar 6, 2024
@jingjunLi jingjunLi reopened this Mar 6, 2024
@jingjunLi jingjunLi changed the title core: Impl block store core: separated databases for block data Mar 6, 2024
node/node.go Outdated
runningState
closedState
blockDbCacheSize = 256
blockDbHandlesSize = 2000
Copy link
Copy Markdown
Contributor

@flywukong flywukong Mar 12, 2024

Choose a reason for hiding this comment

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

if handler/10 < 2000 {
	blockDbHandlesSize  = 1000 
}else {
	blockDbHandlesSize   = 2000
}  

Adjust this variable

@jingjunLi jingjunLi force-pushed the impl_block_store branch 2 times, most recently from afc3eac to 89b7d3a Compare March 12, 2024 09:39
@jingjunLi jingjunLi force-pushed the impl_block_store branch 3 times, most recently from 3e6149f to 7e3e660 Compare March 20, 2024 05:19
@jingjunLi jingjunLi requested a review from unclezoro as a code owner April 3, 2024 02:19
@jingjunLi jingjunLi added the r4r ready for review label Apr 11, 2024
@jingjunLi jingjunLi force-pushed the impl_block_store branch 2 times, most recently from 5640825 to 288c534 Compare April 15, 2024 03:03
@fynnss fynnss requested review from flywukong and fynnss April 18, 2024 01:22
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

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

@zzzckck zzzckck merged commit c0afdc9 into bnb-chain:develop Apr 18, 2024
Copy link
Copy Markdown

@Pjrich1313 Pjrich1313 left a comment

Choose a reason for hiding this comment

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

O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r4r ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants