Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Accounts bloom#2357

Merged
arkpar merged 21 commits into
betafrom
state-cache-bloom
Sep 29, 2016
Merged

Accounts bloom#2357
arkpar merged 21 commits into
betafrom
state-cache-bloom

Conversation

@NikVolf
Copy link
Copy Markdown
Contributor

@NikVolf NikVolf commented Sep 27, 2016

on top of @arkpar #2308

still missing:

  • snapshot restoration bloom update
  • miration

@NikVolf NikVolf added the A0-pleasereview 🤓 Pull request needs code review. label Sep 27, 2016
@rphmeier
Copy link
Copy Markdown
Contributor

rphmeier commented Sep 27, 2016

could we put the source for bloom filter in this repo? /util/bloomfilter would be a good place. It's hard to review code in multiple places at once.

@NikVolf NikVolf added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 27, 2016
@NikVolf
Copy link
Copy Markdown
Contributor Author

NikVolf commented Sep 27, 2016

@rphmeier it's a fork from other guy crate

@gavofyork gavofyork added this to the 1.3.2 milestone Sep 27, 2016
@gavofyork gavofyork added B0-patch M4-core ⛓ Core client code / Rust. labels Sep 27, 2016
@gavofyork
Copy link
Copy Markdown
Contributor

can be made against master now.

Comment thread ethcore/src/state_db.rs Outdated
pub const ACCOUNT_BLOOM_SPACE: usize = 1048576;
pub const DEFAULT_ACCOUNT_PRESET: usize = 1000000;

pub const ACCOUNT_BLOOM_SPACE_COLUMN: &'static[u8] = b"accounts_bloom";
Copy link
Copy Markdown
Collaborator

@arkpar arkpar Sep 27, 2016

Choose a reason for hiding this comment

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

Should be called ACCOUNT_BLOOM_SPACE_KEY, Column is something else in rocksdb terms.

@NikVolf NikVolf changed the base branch from state-cache to beta September 27, 2016 19:41
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.051% when pulling 5c29d1e on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.05% when pulling 5c29d1e on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.037% when pulling 33e181a on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.039% when pulling c2022fa on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.036% when pulling f3b094a on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.4%) to 87.039% when pulling f3b094a on state-cache-bloom into facab31 on beta.

@NikVolf NikVolf added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 28, 2016
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.04%) to 87.375% when pulling ee36df0 on state-cache-bloom into facab31 on beta.

Comment thread ethcore/src/migrations/account_bloom.rs Outdated
let account_trie = try!(TrieDB::new(state_db.as_hashdb(), &state_root).map_err(|e| Error::Custom(format!("Cannot open trie: {:?}", e))));
for (ref account_key, _) in account_trie.iter() {
let account_key_hash = H256::from_slice(&account_key);
bloom.set(account_key_hash.sha3().as_slice());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

account_key_hash is an address hash already, no need to sha3() it here

Comment thread ethcore/src/migrations/account_bloom.rs Outdated
try!(db.write(batch));

trace!(target: "migration", "Finished bloom update");
println!("Done.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should be removed

Comment thread ethcore/src/state_db.rs Outdated
}

let bloom = Bloom::from_parts(&bloom_parts, hash_count as u32);
trace!(target: "account_bloom", "Bloom is {:?} full, hash functions number = {:?}", bloom.how_full(), hash_count);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"hash functions number" -> "hash function count" or "number of hash functions"


trace!(target: "migration", "Generated {} bloom updates", bloom_journal.entries.len());

let batch = DBTransaction::new(&db);
Copy link
Copy Markdown
Contributor Author

@NikVolf NikVolf Sep 28, 2016

Choose a reason for hiding this comment

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

Unsure if this can or can not happend concurrently
would be nice if @rphmeier review this

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.

Becomes a non-issue if you switch the strategy to the one described in my other comment.
DBTransaction exists entirely outside of the rocksdb layer so it's safe itself, and then db.write may race against any other writes. Afaik the migrations are single-threaded so it probably shouldn't.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.03%) to 87.377% when pulling 039c345 on state-cache-bloom into facab31 on beta.

Comment thread ethcore/src/migrations/account_bloom.rs Outdated
return Ok(())
}

println!("Adding accounts bloom (one-time upgrade). Please don't close parity.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use info! instead of println!
"Please don't close" should be irrelevant. The whole upgrade should be one transaction or pa process that can be canceled

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.

All migration messages are displayed using println!

It is indeed in one transaction, so i will remove this pray

@gavofyork
Copy link
Copy Markdown
Contributor

@rphmeier should sign off, too.

Copy link
Copy Markdown
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

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

couple issues with the migration, haven't looked at the bloom filter crate itself but the API calls look right.

Comment thread parity/migration.rs
// in-place upgrades that do nothing when called repeatedly
fn run_inplace_upgrades(path: &Path) -> Result<(), Error> {
try!(migrations::upgrade_account_bloom(path));
Ok(())
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.

I don't think this strategy will work once we add more migrations on top of this one, since we need this account bloom migration to happen before others which may affect it.

Why not change Migration to supply Arc<Database> as source, and copy everything over for each column, and then additionally if column == COL_STATE, you also do the same stuff as upgrade_account_bloom would?

I think this would also require backporting my pre_columns fixes from master as consolidated db migrations are currently broken.

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's perfectly safe to run this migration any time on the upgraded database - it just won't do anything

any further upgrades should just go after this line

i don't want to introduce any new logic to the migration in beta and at this pr


trace!(target: "migration", "Generated {} bloom updates", bloom_journal.entries.len());

let batch = DBTransaction::new(&db);
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.

Becomes a non-issue if you switch the strategy to the one described in my other comment.
DBTransaction exists entirely outside of the rocksdb layer so it's safe itself, and then db.write may race against any other writes. Afaik the migrations are single-threaded so it probably shouldn't.

Comment thread ethcore/src/migrations/account_bloom.rs Outdated
//! Bloom upgrade

use client::{DB_COL_EXTRA, DB_COL_HEADERS, DB_NO_OF_COLUMNS, DB_COL_STATE};
use state_db::{ACCOUNT_BLOOM_SPACE, DEFAULT_ACCOUNT_PRESET, StateDB};
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.

all constants should be reproduced in the migration implementation for backwards compatibility -- there is no guarantee that they will remain the same as they were at the database version you're migrating.

Copy link
Copy Markdown
Contributor Author

@NikVolf NikVolf Sep 28, 2016

Choose a reason for hiding this comment

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

it's not a migration strictly, it's inplace upgrade
it's perfectly guaranteed that the columns should be the same otherwise all other logic will instantly fail

Comment thread ethcore/src/state.rs
Ok(Some(acc)) => AccountEntry::Cached(Account::from_rlp(acc)),
Ok(None) => AccountEntry::Missing,
Err(e) => panic!("Potential DB corruption encountered: {}", e),
let maybe_acc = if self.db.check_account_bloom(a) {
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.

this check can be saved just by caching the value of the previous query

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.

can't see how

Comment thread ethcore/src/state_db.rs Outdated
pub const ACCOUNT_BLOOM_SPACE: usize = 1048576;
pub const DEFAULT_ACCOUNT_PRESET: usize = 1000000;

pub const ACCOUNT_BLOOM_HASHCOUNT_KEY: &'static[u8] = b"account_hash_count";
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.

style: &'static [u8]

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.

done

Comment thread ethcore/src/state_db.rs Outdated
.expect("Low-level database error");

hash_count_entry.is_some()
}
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.

this function is only used for the migration; maybe it should be implemented there? (especially as it relies on external constants)

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.

done

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.03%) to 87.377% when pulling e25441d on state-cache-bloom into facab31 on beta.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.02%) to 87.392% when pulling def6343 on state-cache-bloom into facab31 on beta.

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 29, 2016
@arkpar arkpar merged commit 4d11598 into beta Sep 29, 2016
@arkpar arkpar deleted the state-cache-bloom branch October 3, 2016 15:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants