Skip to content

Commit

Permalink
Remove RwLock on AccountsUpdateNotifier (solana-labs#33960)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunwangs authored Nov 6, 2023
1 parent da130b8 commit 8c69a0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
25 changes: 7 additions & 18 deletions accounts-db/src/accounts_db/geyser_plugin_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl AccountsDb {
}

let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap();
let notifier = &accounts_update_notifier.read().unwrap();
notifier.notify_end_of_restore_from_snapshot();
accounts_update_notifier.notify_end_of_restore_from_snapshot();
notify_stats.report();
}

Expand All @@ -72,8 +71,7 @@ impl AccountsDb {
P: Iterator<Item = u64>,
{
if let Some(accounts_update_notifier) = &self.accounts_update_notifier {
let notifier = &accounts_update_notifier.read().unwrap();
notifier.notify_account_update(
accounts_update_notifier.notify_account_update(
slot,
account,
txn,
Expand Down Expand Up @@ -121,13 +119,7 @@ impl AccountsDb {
mut accounts_to_stream: HashMap<Pubkey, StoredAccountMeta>,
notify_stats: &mut GeyserPluginNotifyAtSnapshotRestoreStats,
) {
let notifier = self
.accounts_update_notifier
.as_ref()
.unwrap()
.read()
.unwrap();

let notifier = self.accounts_update_notifier.as_ref().unwrap();
let mut measure_notify = Measure::start("accountsdb-plugin-notifying-accounts");
let local_write_version = 0;
for (_, mut account) in accounts_to_stream.drain() {
Expand Down Expand Up @@ -177,7 +169,7 @@ pub mod tests {
},
std::sync::{
atomic::{AtomicBool, Ordering},
Arc, RwLock,
Arc,
},
};

Expand Down Expand Up @@ -246,12 +238,11 @@ pub mod tests {

accounts.store_uncached(slot0, &[(&key2, &account2)]);

let notifier = Arc::new(RwLock::new(notifier));
let notifier = Arc::new(notifier);
accounts.set_geyser_plugin_notifer(Some(notifier.clone()));

accounts.notify_account_restore_from_snapshot();

let notifier = notifier.write().unwrap();
assert_eq!(notifier.accounts_notified.get(&key1).unwrap().len(), 1);
assert_eq!(
notifier.accounts_notified.get(&key1).unwrap()[0]
Expand Down Expand Up @@ -303,12 +294,11 @@ pub mod tests {
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
accounts.store_uncached(slot1, &[(&key3, &account3)]);

let notifier = Arc::new(RwLock::new(notifier));
let notifier = Arc::new(notifier);
accounts.set_geyser_plugin_notifer(Some(notifier.clone()));

accounts.notify_account_restore_from_snapshot();

let notifier = notifier.write().unwrap();
assert_eq!(notifier.accounts_notified.get(&key1).unwrap().len(), 1);
assert_eq!(
notifier.accounts_notified.get(&key1).unwrap()[0]
Expand Down Expand Up @@ -342,7 +332,7 @@ pub mod tests {

let notifier = GeyserTestPlugin::default();

let notifier = Arc::new(RwLock::new(notifier));
let notifier = Arc::new(notifier);
accounts.set_geyser_plugin_notifer(Some(notifier.clone()));

// Account with key1 is updated twice in two different slots -- should only get notified twice.
Expand Down Expand Up @@ -372,7 +362,6 @@ pub mod tests {
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
accounts.store_cached((slot1, &[(&key3, &account3)][..]), None);

let notifier = notifier.write().unwrap();
assert_eq!(notifier.accounts_notified.get(&key1).unwrap().len(), 2);
assert_eq!(
notifier.accounts_notified.get(&key1).unwrap()[0]
Expand Down
4 changes: 2 additions & 2 deletions accounts-db/src/accounts_update_notifier_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
solana_sdk::{
account::AccountSharedData, clock::Slot, pubkey::Pubkey, transaction::SanitizedTransaction,
},
std::sync::{Arc, RwLock},
std::sync::Arc,
};

pub trait AccountsUpdateNotifierInterface: std::fmt::Debug {
Expand All @@ -25,4 +25,4 @@ pub trait AccountsUpdateNotifierInterface: std::fmt::Debug {
fn notify_end_of_restore_from_snapshot(&self);
}

pub type AccountsUpdateNotifier = Arc<RwLock<dyn AccountsUpdateNotifierInterface + Sync + Send>>;
pub type AccountsUpdateNotifier = Arc<dyn AccountsUpdateNotifierInterface + Sync + Send>;
2 changes: 1 addition & 1 deletion geyser-plugin-manager/src/geyser_plugin_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl GeyserPluginService {
if account_data_notifications_enabled {
let accounts_update_notifier =
AccountsUpdateNotifierImpl::new(plugin_manager.clone());
Some(Arc::new(RwLock::new(accounts_update_notifier)))
Some(Arc::new(accounts_update_notifier))
} else {
None
};
Expand Down

0 comments on commit 8c69a0e

Please sign in to comment.