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

Transaction writeset store #3903

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

Transaction writeset store #3903

wants to merge 14 commits into from

Conversation

welbon
Copy link
Contributor

@welbon welbon commented Jun 1, 2023

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Other information

@nkysg
Copy link
Collaborator

nkysg commented Jun 1, 2023

运行下 ./scripts/check_commit.sh

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Benchmark for cc04b9c

Click to view benchmark
Test Base PR %
accumulator_append 615.0±33.23µs 615.0±29.00µs 0.00%
block_apply/block_apply_10 357.1±2.28ms 357.2±0.72ms +0.03%
block_apply/block_apply_1000 37.1±0.05s 37.3±0.11s +0.54%
get_with_proof/db_store 36.4±0.21µs 36.8±0.23µs +1.10%
get_with_proof/mem_store 31.7±0.52µs 31.7±0.31µs 0.00%
put_and_commit/db_store/1 97.6±5.39µs 97.8±5.00µs +0.20%
put_and_commit/db_store/10 882.0±43.10µs 874.9±40.35µs -0.80%
put_and_commit/db_store/100 7.5±0.30ms 7.5±0.27ms 0.00%
put_and_commit/db_store/5 447.2±22.99µs 426.2±22.88µs -4.70%
put_and_commit/db_store/50 3.9±0.16ms 3.9±0.17ms 0.00%
put_and_commit/mem_store/1 62.6±5.93µs 62.6±5.91µs 0.00%
put_and_commit/mem_store/10 588.2±51.67µs 583.2±48.48µs -0.85%
put_and_commit/mem_store/100 5.7±0.87ms 5.7±0.35ms 0.00%
put_and_commit/mem_store/5 296.0±27.02µs 294.3±25.27µs -0.57%
put_and_commit/mem_store/50 2.9±0.19ms 2.9±0.19ms 0.00%
query_block/query_block_in(10)_times(100) 5.0±0.15ms 5.0±0.15ms 0.00%
query_block/query_block_in(10)_times(1000) 50.9±1.56ms 49.9±0.85ms -1.96%
query_block/query_block_in(10)_times(10000) 505.0±7.54ms 500.4±11.04ms -0.91%
query_block/query_block_in(1000)_times(100) 1011.0±9.15µs 989.4±5.58µs -2.14%
query_block/query_block_in(1000)_times(1000) 10.1±0.05ms 10.0±0.11ms -0.99%
query_block/query_block_in(1000)_times(10000) 100.7±0.90ms 100.4±1.05ms -0.30%
storage_transaction 1151.3±388.43µs 1000.3±308.88µs -13.12%
vm/transaction_execution/1 406.0±1.09ms 407.9±1.07ms +0.47%
vm/transaction_execution/10 124.6±1.96ms 124.5±0.20ms -0.08%
vm/transaction_execution/20 115.7±5.37ms 114.6±0.65ms -0.95%
vm/transaction_execution/5 152.9±0.30ms 154.3±0.89ms +0.92%
vm/transaction_execution/50 128.9±0.87ms 129.7±0.53ms +0.62%

@@ -138,9 +143,11 @@ static VEC_PREFIX_NAME_V3: Lazy<Vec<ColumnFamilyName>> = Lazy::new(|| {
TRANSACTION_INFO_HASH_PREFIX_NAME,
CONTRACT_EVENT_PREFIX_NAME,
FAILED_BLOCK_PREFIX_NAME,
WRITE_SET_PRIFIX_NAME,
Copy link
Collaborator

@nkysg nkysg Jun 1, 2023

Choose a reason for hiding this comment

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

这里确认下可以直接加吗?dbupgrade相关逻辑

Copy link
Contributor Author

Choose a reason for hiding this comment

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

刚看了下升级这块,应该都是涉及到修改现有的结构,新增的话应该是不需要upgrade流程的

@welbon welbon requested a review from nkysg June 2, 2023 09:35

fn to_write_set(access_path: AccessPath, value: Vec<u8>) -> WriteSet {
WriteSetMut::new(vec![
(
Copy link
Collaborator

Choose a reason for hiding this comment

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

table item这个测试是不是也需要加一个

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已加

@@ -23,6 +26,7 @@ impl Default for BlockExecutedData {
state_root: HashValue::zero(),
txn_events: vec![],
txn_infos: vec![],
txn_write_sets: HashMap::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里为什么用HashMap,之前都是vec!, 这里有快速查找和插入需求吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里因为一个block涉及到多个transaction,map实现起来比较方便

Copy link
Collaborator

Choose a reason for hiding this comment

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

是L80还是哪里?方便给我说下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里改成了vec,没改之前的考虑是方便说外面一对一的去取;改了之后的考虑是1. 如果有重复hashvalue则不会覆盖造成数据丢失,2. 存数据库时也是用的顺序存储

@codecov
Copy link

codecov bot commented Jun 2, 2023

Codecov Report

Merging #3903 (5f39577) into master (397b411) will increase coverage by 0.10%.
Report is 18 commits behind head on master.
The diff coverage is 65.70%.

❗ Current head 5f39577 differs from pull request most recent head 1b6e033. Consider uploading reports for the commit 1b6e033 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3903      +/-   ##
==========================================
+ Coverage   53.68%   53.77%   +0.10%     
==========================================
  Files         618      622       +4     
  Lines       67991    68216     +225     
==========================================
+ Hits        36492    36675     +183     
- Misses      31499    31541      +42     
Flag Coverage Δ
unittests 53.77% <65.70%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
chain/api/src/message.rs 0.00% <ø> (ø)
chain/api/src/service.rs 17.34% <0.00%> (-0.63%) ⬇️
chain/service/src/chain_service.rs 34.44% <0.00%> (-0.57%) ⬇️
config/src/lib.rs 60.08% <0.00%> (-0.65%) ⬇️
rpc/api/src/chain/mod.rs 100.00% <ø> (ø)
rpc/server/src/module/chain_rpc.rs 3.15% <0.00%> (-0.11%) ⬇️
...rcoin-transactional-test-harness/src/fork_chain.rs 0.00% <0.00%> (ø)
vm/types/src/on_chain_config/mod.rs 71.14% <ø> (ø)
rpc/api/src/types.rs 15.78% <4.17%> (-0.28%) ⬇️
vm/transaction-builder/src/lib.rs 32.65% <50.00%> (+0.29%) ⬆️
... and 8 more

... and 65 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 626325a...1b6e033. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Jun 2, 2023

Benchmark for aeda101

Click to view benchmark
Test Base PR %
accumulator_append 609.9±28.32µs 610.1±27.64µs +0.03%
block_apply/block_apply_10 357.8±1.55ms 359.1±0.91ms +0.36%
block_apply/block_apply_1000 36.8±0.04s 37.2±0.03s +1.09%
get_with_proof/db_store 37.3±0.33µs 37.2±0.33µs -0.27%
get_with_proof/mem_store 31.8±0.49µs 32.0±0.19µs +0.63%
put_and_commit/db_store/1 96.4±4.96µs 97.4±4.75µs +1.04%
put_and_commit/db_store/10 871.5±43.33µs 869.3±55.10µs -0.25%
put_and_commit/db_store/100 7.4±0.27ms 7.4±0.29ms 0.00%
put_and_commit/db_store/5 446.5±34.46µs 445.6±22.13µs -0.20%
put_and_commit/db_store/50 3.8±0.14ms 3.9±0.16ms +2.63%
put_and_commit/mem_store/1 62.8±5.68µs 62.8±5.71µs 0.00%
put_and_commit/mem_store/10 586.3±47.06µs 591.0±59.13µs +0.80%
put_and_commit/mem_store/100 5.8±0.83ms 5.7±0.35ms -1.72%
put_and_commit/mem_store/5 296.3±24.57µs 296.9±24.88µs +0.20%
put_and_commit/mem_store/50 2.9±0.19ms 2.9±0.19ms 0.00%
query_block/query_block_in(10)_times(100) 5.1±0.13ms 5.1±0.17ms 0.00%
query_block/query_block_in(10)_times(1000) 51.4±1.48ms 51.2±1.55ms -0.39%
query_block/query_block_in(10)_times(10000) 512.5±14.86ms 513.9±11.18ms +0.27%
query_block/query_block_in(1000)_times(100) 1008.7±14.68µs 1009.7±10.90µs +0.10%
query_block/query_block_in(1000)_times(1000) 10.0±0.12ms 10.1±0.10ms +1.00%
query_block/query_block_in(1000)_times(10000) 100.6±0.77ms 100.7±0.74ms +0.10%
storage_transaction 995.0±299.14µs 1043.6±375.72µs +4.88%
vm/transaction_execution/1 406.6±1.65ms 407.4±5.38ms +0.20%
vm/transaction_execution/10 123.8±0.32ms 124.5±1.32ms +0.57%
vm/transaction_execution/20 113.9±0.25ms 113.9±0.39ms 0.00%
vm/transaction_execution/5 153.3±1.48ms 153.5±1.83ms +0.13%
vm/transaction_execution/50 128.9±0.48ms 128.8±0.23ms -0.08%

@nkysg nkysg self-requested a review June 5, 2023 03:57
@@ -505,6 +506,10 @@ impl BlockChain {

storage.save_block_info(block_info.clone())?;

for (hash_value, write_set) in txn_write_set.iter() {
Copy link
Collaborator

@simonjiao simonjiao Jun 26, 2023

Choose a reason for hiding this comment

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

we can consume the txn_write_set, becase it will not be used any more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passed it into batch save function

Copy link
Collaborator

@simonjiao simonjiao left a comment

Choose a reason for hiding this comment

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

Please check out the comment. @welbon

@@ -505,6 +506,11 @@ impl BlockChain {

storage.save_block_info(block_info.clone())?;

for (hash_value, write_set) in txn_write_set{
storage.save_write_set(hash_value, write_set)?;
Copy link
Collaborator

@nkysg nkysg Jun 28, 2023

Choose a reason for hiding this comment

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

看起来 storage.save_write_set可以弄成一个batch_write,你参考下save_transaction_batch看看是不是这样, batch_write主要是少了几次rocksdb调用,这个调用虽然比较小,再就是现在是一次性写入,现在是rocksdb异步刷盘,不是每次都flush磁盘,如果是同步就会每次都flush磁盘就很慢了. @welbon @simonjiao

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里考虑上线之前加一下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里加了batch处理

@nkysg
Copy link
Collaborator

nkysg commented Jun 29, 2023

It has some big change about WriteOp in move. WriteOp originals has two kinds of operations, Value and Delete. Now It becomes three kinds, Insert, Update and Delete. I think starcoin will consider to upgrade it.

Copy link
Collaborator

@simonjiao simonjiao left a comment

Choose a reason for hiding this comment

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

LGTM

@nkysg
Copy link
Collaborator

nkysg commented Aug 7, 2023

LGTM

@nkysg nkysg self-requested a review August 7, 2023 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants