Uses SeqLock for CachedAccountInner::hash (#33696)

This commit is contained in:
Brooks 2023-10-18 10:43:35 -04:00 committed by GitHub
parent c699bc9cab
commit e96678b302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 6 deletions

10
Cargo.lock generated
View File

@ -4745,6 +4745,15 @@ dependencies = [
"pest", "pest",
] ]
[[package]]
name = "seqlock"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5c67b6f14ecc5b86c66fa63d76b5092352678545a8a3cdae80aef5128371910"
dependencies = [
"parking_lot 0.12.1",
]
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.189" version = "1.0.189"
@ -5210,6 +5219,7 @@ dependencies = [
"rayon", "rayon",
"regex", "regex",
"rustc_version 0.4.0", "rustc_version 0.4.0",
"seqlock",
"serde", "serde",
"serde_derive", "serde_derive",
"solana-accounts-db", "solana-accounts-db",

View File

@ -286,6 +286,7 @@ rustls = { version = "0.21.7", default-features = false, features = ["quic"] }
rustversion = "1.0.14" rustversion = "1.0.14"
scopeguard = "1.2.0" scopeguard = "1.2.0"
semver = "1.0.20" semver = "1.0.20"
seqlock = "0.2.0"
serde = "1.0.189" serde = "1.0.189"
serde_bytes = "0.11.12" serde_bytes = "0.11.12"
serde_derive = "1.0.103" serde_derive = "1.0.103"

View File

@ -40,6 +40,7 @@ qualifier_attr = { workspace = true }
rand = { workspace = true } rand = { workspace = true }
rayon = { workspace = true } rayon = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
seqlock = { workspace = true }
serde = { workspace = true, features = ["rc"] } serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true } serde_derive = { workspace = true }
solana-bucket-map = { workspace = true } solana-bucket-map = { workspace = true }

View File

@ -4,6 +4,7 @@ use {
accounts_hash::AccountHash, accounts_hash::AccountHash,
}, },
dashmap::DashMap, dashmap::DashMap,
seqlock::SeqLock,
solana_sdk::{ solana_sdk::{
account::{AccountSharedData, ReadableAccount}, account::{AccountSharedData, ReadableAccount},
clock::Slot, clock::Slot,
@ -77,7 +78,7 @@ impl SlotCacheInner {
let data_len = account.data().len() as u64; let data_len = account.data().len() as u64;
let item = Arc::new(CachedAccountInner { let item = Arc::new(CachedAccountInner {
account, account,
hash: RwLock::new(None), hash: SeqLock::new(None),
slot, slot,
pubkey: *pubkey, pubkey: *pubkey,
include_slot_in_hash, include_slot_in_hash,
@ -143,7 +144,7 @@ pub type CachedAccount = Arc<CachedAccountInner>;
#[derive(Debug)] #[derive(Debug)]
pub struct CachedAccountInner { pub struct CachedAccountInner {
pub account: AccountSharedData, pub account: AccountSharedData,
hash: RwLock<Option<AccountHash>>, hash: SeqLock<Option<AccountHash>>,
slot: Slot, slot: Slot,
pubkey: Pubkey, pubkey: Pubkey,
/// temporarily here during feature activation /// temporarily here during feature activation
@ -153,18 +154,17 @@ pub struct CachedAccountInner {
impl CachedAccountInner { impl CachedAccountInner {
pub fn hash(&self) -> AccountHash { pub fn hash(&self) -> AccountHash {
let hash = self.hash.read().unwrap(); let hash = self.hash.read();
match *hash { match hash {
Some(hash) => hash, Some(hash) => hash,
None => { None => {
drop(hash);
let hash = AccountsDb::hash_account( let hash = AccountsDb::hash_account(
self.slot, self.slot,
&self.account, &self.account,
&self.pubkey, &self.pubkey,
self.include_slot_in_hash, self.include_slot_in_hash,
); );
*self.hash.write().unwrap() = Some(hash); *self.hash.lock_write() = Some(hash);
hash hash
} }
} }

View File

@ -4133,6 +4133,15 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "seqlock"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5c67b6f14ecc5b86c66fa63d76b5092352678545a8a3cdae80aef5128371910"
dependencies = [
"parking_lot 0.12.1",
]
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.189" version = "1.0.189"
@ -4501,6 +4510,7 @@ dependencies = [
"rayon", "rayon",
"regex", "regex",
"rustc_version", "rustc_version",
"seqlock",
"serde", "serde",
"serde_derive", "serde_derive",
"solana-bucket-map", "solana-bucket-map",