Skip to content

Commit 4ada602

Browse files
lutterclaude
andcommitted
store: Replace std::sync::RwLock with parking_lot::RwLock in BlockStore
Replace std::sync::RwLock with parking_lot::RwLock for the chain stores map in BlockStore. This reduces lock contention when looking up or modifying chain stores. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c935301 commit 4ada602

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

store/postgres/src/block_store.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::{
2-
collections::HashMap,
3-
sync::{Arc, RwLock},
4-
time::Duration,
5-
};
1+
use std::{collections::HashMap, sync::Arc, time::Duration};
2+
3+
use graph::parking_lot::RwLock;
64

75
use anyhow::anyhow;
86
use async_trait::async_trait;
@@ -321,7 +319,6 @@ impl BlockStore {
321319
let configured_chains = block_store
322320
.stores
323321
.read()
324-
.unwrap()
325322
.keys()
326323
.cloned()
327324
.collect::<Vec<_>>();
@@ -410,7 +407,6 @@ impl BlockStore {
410407
let store = Arc::new(store);
411408
self.stores
412409
.write()
413-
.unwrap()
414410
.insert(chain.name.clone(), store.clone());
415411
Ok(store)
416412
}
@@ -475,12 +471,7 @@ impl BlockStore {
475471
}
476472

477473
async fn store(&self, chain: &str) -> Option<Arc<ChainStore>> {
478-
let store = self
479-
.stores
480-
.read()
481-
.unwrap()
482-
.get(chain)
483-
.map(CheapClone::cheap_clone);
474+
let store = self.stores.read().get(chain).map(CheapClone::cheap_clone);
484475
if store.is_some() {
485476
return store;
486477
}
@@ -506,7 +497,7 @@ impl BlockStore {
506497

507498
chain_store.drop_chain().await?;
508499

509-
self.stores.write().unwrap().remove(chain);
500+
self.stores.write().remove(chain);
510501

511502
Ok(())
512503
}
@@ -516,7 +507,6 @@ impl BlockStore {
516507
fn stores(&self) -> Vec<Arc<ChainStore>> {
517508
self.stores
518509
.read()
519-
.unwrap()
520510
.values()
521511
.map(CheapClone::cheap_clone)
522512
.collect()

0 commit comments

Comments
 (0)