@@ -42,7 +42,7 @@ use std::{
42
42
ops:: RangeBounds ,
43
43
path:: { Path , PathBuf } ,
44
44
sync:: atomic:: { AtomicBool , AtomicU64 , AtomicUsize , Ordering } ,
45
- sync:: { Arc , Mutex , RwLock } ,
45
+ sync:: { Arc , Mutex , RwLock , RwLockReadGuard } ,
46
46
time:: Instant ,
47
47
} ;
48
48
use tempfile:: TempDir ;
@@ -964,10 +964,21 @@ impl AccountsDB {
964
964
F : Fn ( & StoredAccount , AppendVecId , & mut B ) + Send + Sync ,
965
965
B : Send + Default ,
966
966
{
967
- let storage_maps: Vec < Arc < AccountStorageEntry > > = self
968
- . storage
969
- . read ( )
970
- . unwrap ( )
967
+ self . scan_account_storage_inner ( slot, scan_func, & self . storage . read ( ) . unwrap ( ) )
968
+ }
969
+
970
+ // The input storage must come from self.storage.read().unwrap()
971
+ fn scan_account_storage_inner < F , B > (
972
+ & self ,
973
+ slot : Slot ,
974
+ scan_func : F ,
975
+ storage : & RwLockReadGuard < AccountStorage > ,
976
+ ) -> Vec < B >
977
+ where
978
+ F : Fn ( & StoredAccount , AppendVecId , & mut B ) + Send + Sync ,
979
+ B : Send + Default ,
980
+ {
981
+ let storage_maps: Vec < Arc < AccountStorageEntry > > = storage
971
982
. 0
972
983
. get ( & slot)
973
984
. unwrap_or ( & HashMap :: new ( ) )
@@ -1806,10 +1817,10 @@ impl AccountsDB {
1806
1817
}
1807
1818
1808
1819
pub fn generate_index ( & self ) {
1820
+ let mut accounts_index = self . accounts_index . write ( ) . unwrap ( ) ;
1809
1821
let storage = self . storage . read ( ) . unwrap ( ) ;
1810
1822
let mut slots: Vec < Slot > = storage. 0 . keys ( ) . cloned ( ) . collect ( ) ;
1811
1823
slots. sort ( ) ;
1812
- let mut accounts_index = self . accounts_index . write ( ) . unwrap ( ) ;
1813
1824
1814
1825
let mut last_log_update = Instant :: now ( ) ;
1815
1826
for ( index, slot) in slots. iter ( ) . enumerate ( ) {
@@ -1820,7 +1831,7 @@ impl AccountsDB {
1820
1831
}
1821
1832
1822
1833
let accumulator: Vec < HashMap < Pubkey , Vec < ( u64 , AccountInfo ) > > > = self
1823
- . scan_account_storage (
1834
+ . scan_account_storage_inner (
1824
1835
* slot,
1825
1836
|stored_account : & StoredAccount ,
1826
1837
store_id : AppendVecId ,
@@ -1835,6 +1846,7 @@ impl AccountsDB {
1835
1846
. or_insert_with ( Vec :: new) ;
1836
1847
entry. push ( ( stored_account. meta . write_version , account_info) ) ;
1837
1848
} ,
1849
+ & storage,
1838
1850
) ;
1839
1851
1840
1852
let mut accounts_map: HashMap < Pubkey , Vec < ( u64 , AccountInfo ) > > = HashMap :: new ( ) ;
0 commit comments