From c3e5927d166a383227f26ebdcc1c6843e47ee247 Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Wed, 17 Nov 2021 07:11:16 -0600 Subject: [PATCH] Constrain memory ordering on AccountsDb::write_version (#21312) --- runtime/src/accounts_db.rs | 6 +++--- runtime/src/serde_snapshot.rs | 2 +- runtime/src/serde_snapshot/future.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index b8874f49fe..8a9e1c17f3 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4391,7 +4391,7 @@ impl AccountsDb { fn bulk_assign_write_version(&self, count: usize) -> StoredMetaWriteVersion { self.write_version - .fetch_add(count as StoredMetaWriteVersion, Ordering::Relaxed) + .fetch_add(count as StoredMetaWriteVersion, Ordering::AcqRel) } fn write_accounts_to_storage Arc>( @@ -9193,8 +9193,8 @@ pub mod tests { let daccounts = reconstruct_accounts_db_via_serialization(&accounts, latest_slot); assert_eq!( - daccounts.write_version.load(Ordering::Relaxed), - accounts.write_version.load(Ordering::Relaxed) + daccounts.write_version.load(Ordering::Acquire), + accounts.write_version.load(Ordering::Acquire) ); // Get the hash for the latest slot, which should be the only hash in the diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 825b806d9e..ef0ea8e5ac 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -536,7 +536,7 @@ where .store(next_append_vec_id, Ordering::Relaxed); accounts_db .write_version - .fetch_add(snapshot_version, Ordering::Relaxed); + .fetch_add(snapshot_version, Ordering::Release); let mut measure_notify = Measure::start("accounts_notify"); diff --git a/runtime/src/serde_snapshot/future.rs b/runtime/src/serde_snapshot/future.rs index c358235577..0a951f0628 100644 --- a/runtime/src/serde_snapshot/future.rs +++ b/runtime/src/serde_snapshot/future.rs @@ -242,7 +242,7 @@ impl<'a> TypeContext<'a> for Context { let version = serializable_db .accounts_db .write_version - .load(Ordering::Relaxed); + .load(Ordering::Acquire); // (1st of 3 elements) write the list of account storage entry lists out as a map let entry_count = RefCell::::new(0);