Remove RwLock on AccountsUpdateNotifier (#33960)
This commit is contained in:
parent
da130b87d3
commit
8c69a0ec38
|
@ -56,8 +56,7 @@ impl AccountsDb {
|
||||||
}
|
}
|
||||||
|
|
||||||
let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap();
|
let accounts_update_notifier = self.accounts_update_notifier.as_ref().unwrap();
|
||||||
let notifier = &accounts_update_notifier.read().unwrap();
|
accounts_update_notifier.notify_end_of_restore_from_snapshot();
|
||||||
notifier.notify_end_of_restore_from_snapshot();
|
|
||||||
notify_stats.report();
|
notify_stats.report();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +71,7 @@ impl AccountsDb {
|
||||||
P: Iterator<Item = u64>,
|
P: Iterator<Item = u64>,
|
||||||
{
|
{
|
||||||
if let Some(accounts_update_notifier) = &self.accounts_update_notifier {
|
if let Some(accounts_update_notifier) = &self.accounts_update_notifier {
|
||||||
let notifier = &accounts_update_notifier.read().unwrap();
|
accounts_update_notifier.notify_account_update(
|
||||||
notifier.notify_account_update(
|
|
||||||
slot,
|
slot,
|
||||||
account,
|
account,
|
||||||
txn,
|
txn,
|
||||||
|
@ -121,13 +119,7 @@ impl AccountsDb {
|
||||||
mut accounts_to_stream: HashMap<Pubkey, StoredAccountMeta>,
|
mut accounts_to_stream: HashMap<Pubkey, StoredAccountMeta>,
|
||||||
notify_stats: &mut GeyserPluginNotifyAtSnapshotRestoreStats,
|
notify_stats: &mut GeyserPluginNotifyAtSnapshotRestoreStats,
|
||||||
) {
|
) {
|
||||||
let notifier = self
|
let notifier = self.accounts_update_notifier.as_ref().unwrap();
|
||||||
.accounts_update_notifier
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.read()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut measure_notify = Measure::start("accountsdb-plugin-notifying-accounts");
|
let mut measure_notify = Measure::start("accountsdb-plugin-notifying-accounts");
|
||||||
let local_write_version = 0;
|
let local_write_version = 0;
|
||||||
for (_, mut account) in accounts_to_stream.drain() {
|
for (_, mut account) in accounts_to_stream.drain() {
|
||||||
|
@ -177,7 +169,7 @@ pub mod tests {
|
||||||
},
|
},
|
||||||
std::sync::{
|
std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
Arc, RwLock,
|
Arc,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,12 +238,11 @@ pub mod tests {
|
||||||
|
|
||||||
accounts.store_uncached(slot0, &[(&key2, &account2)]);
|
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.set_geyser_plugin_notifer(Some(notifier.clone()));
|
||||||
|
|
||||||
accounts.notify_account_restore_from_snapshot();
|
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().len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
notifier.accounts_notified.get(&key1).unwrap()[0]
|
notifier.accounts_notified.get(&key1).unwrap()[0]
|
||||||
|
@ -303,12 +294,11 @@ pub mod tests {
|
||||||
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
|
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
|
||||||
accounts.store_uncached(slot1, &[(&key3, &account3)]);
|
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.set_geyser_plugin_notifer(Some(notifier.clone()));
|
||||||
|
|
||||||
accounts.notify_account_restore_from_snapshot();
|
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().len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
notifier.accounts_notified.get(&key1).unwrap()[0]
|
notifier.accounts_notified.get(&key1).unwrap()[0]
|
||||||
|
@ -342,7 +332,7 @@ pub mod tests {
|
||||||
|
|
||||||
let notifier = GeyserTestPlugin::default();
|
let notifier = GeyserTestPlugin::default();
|
||||||
|
|
||||||
let notifier = Arc::new(RwLock::new(notifier));
|
let notifier = Arc::new(notifier);
|
||||||
accounts.set_geyser_plugin_notifer(Some(notifier.clone()));
|
accounts.set_geyser_plugin_notifer(Some(notifier.clone()));
|
||||||
|
|
||||||
// Account with key1 is updated twice in two different slots -- should only get notified twice.
|
// Account with key1 is updated twice in two different slots -- should only get notified twice.
|
||||||
|
@ -372,7 +362,6 @@ pub mod tests {
|
||||||
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
|
AccountSharedData::new(account3_lamports, 1, AccountSharedData::default().owner());
|
||||||
accounts.store_cached((slot1, &[(&key3, &account3)][..]), None);
|
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().len(), 2);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
notifier.accounts_notified.get(&key1).unwrap()[0]
|
notifier.accounts_notified.get(&key1).unwrap()[0]
|
||||||
|
|
|
@ -3,7 +3,7 @@ use {
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::AccountSharedData, clock::Slot, pubkey::Pubkey, transaction::SanitizedTransaction,
|
account::AccountSharedData, clock::Slot, pubkey::Pubkey, transaction::SanitizedTransaction,
|
||||||
},
|
},
|
||||||
std::sync::{Arc, RwLock},
|
std::sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait AccountsUpdateNotifierInterface: std::fmt::Debug {
|
pub trait AccountsUpdateNotifierInterface: std::fmt::Debug {
|
||||||
|
@ -25,4 +25,4 @@ pub trait AccountsUpdateNotifierInterface: std::fmt::Debug {
|
||||||
fn notify_end_of_restore_from_snapshot(&self);
|
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>;
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl GeyserPluginService {
|
||||||
if account_data_notifications_enabled {
|
if account_data_notifications_enabled {
|
||||||
let accounts_update_notifier =
|
let accounts_update_notifier =
|
||||||
AccountsUpdateNotifierImpl::new(plugin_manager.clone());
|
AccountsUpdateNotifierImpl::new(plugin_manager.clone());
|
||||||
Some(Arc::new(RwLock::new(accounts_update_notifier)))
|
Some(Arc::new(accounts_update_notifier))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue