-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2505: feat: provide `--overwrite-spec` to override the chain spec in storage r=quake,yangby-cryptape a=keroro520 Ckb stores chain spec into the database and compare the configured chain spec on starting. A user may want to overwrite the stored chain spec when it changes the configured chain spec and makes sure the change is acceptable. Therefore this PR adds `--overwrite-spec` command option to overwrite the stored chain spec. --- * If you want to just skip the chain spec checking without overriding the stored one: ```shell ckb run --skip-spec-check ... ``` * If you want to overwrite the stored chain spec with the configured one: ```shell ckb run --overwrite-spec ... ``` 2526: feat: multi thread number_hash_mapping migration r=yangby-cryptape,quake a=zhangsoledad multi-thread number_hash_mapping migration extract multi-thread migration template: https://github.com/nervosnetwork/ckb/blob/e841287b9484ae325acc64e4e74c5fb705a09bcd/shared/src/migrations/add_number_hash_mapping.rs#L20-L21 Co-authored-by: keroro <keroroxx520@gmail.com> Co-authored-by: zhangsoledad <787953403@qq.com>
- Loading branch information
Showing
13 changed files
with
205 additions
and
121 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "ckb-migration-template" | ||
version = "0.40.0-pre" | ||
license = "MIT" | ||
authors = ["Nervos <dev@nervos.org>"] | ||
edition = "2018" | ||
description = "Provide proc-macros to setup migration." | ||
homepage = "https://github.com/nervosnetwork/ckb" | ||
repository = "https://github.com/nervosnetwork/ckb" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
quote = "1.0" | ||
syn = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//! Provide proc-macros to setup migration. | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::parse_macro_input; | ||
|
||
/// multi thread migration template | ||
#[proc_macro] | ||
pub fn multi_thread_migration(input: TokenStream) -> TokenStream { | ||
let block_expr = parse_macro_input!(input as syn::ExprBlock); | ||
let expanded = quote! { | ||
const MAX_THREAD: u64 = 6; | ||
const MIN_THREAD: u64 = 2; | ||
const BATCH: usize = 1_000; | ||
|
||
let chain_db = ChainDB::new(db, StoreConfig::default()); | ||
let tip = chain_db.get_tip_header().expect("db tip header index"); | ||
let tip_number = tip.number(); | ||
|
||
let tb_num = std::cmp::max(MIN_THREAD, num_cpus::get() as u64); | ||
let tb_num = std::cmp::min(tb_num, MAX_THREAD); | ||
let chunk_size = tip_number / tb_num; | ||
let remainder = tip_number % tb_num; | ||
let _barrier = ::std::sync::Arc::new(::std::sync::Barrier::new(tb_num as usize)); | ||
|
||
let handles: Vec<_> = (0..tb_num).map(|i| { | ||
let chain_db = chain_db.clone(); | ||
let pb = ::std::sync::Arc::clone(&pb); | ||
let barrier = Arc::clone(&_barrier); | ||
|
||
let last = i == (tb_num - 1); | ||
let size = if last { | ||
chunk_size + remainder | ||
} else { | ||
chunk_size | ||
}; | ||
let end = if last { | ||
tip_number + 1 | ||
} else { | ||
(i + 1) * chunk_size | ||
}; | ||
|
||
let pbi = pb(size * 2); | ||
pbi.set_style( | ||
ProgressStyle::default_bar() | ||
.template( | ||
"{prefix:.bold.dim} {spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta}) {msg}", | ||
) | ||
.progress_chars("#>-"), | ||
); | ||
pbi.set_position(0); | ||
pbi.enable_steady_tick(5000); | ||
::std::thread::spawn(move || { | ||
let mut wb = chain_db.new_write_batch(); | ||
|
||
#block_expr | ||
|
||
if !wb.is_empty() { | ||
chain_db.write(&wb).unwrap(); | ||
} | ||
pbi.finish_with_message("done!"); | ||
}) | ||
}).collect(); | ||
|
||
// Wait for other threads to finish. | ||
for handle in handles { | ||
handle.join().unwrap(); | ||
} | ||
Ok(chain_db.into_inner()) | ||
}; | ||
|
||
TokenStream::from(expanded) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.