Skip to content

Commit f24650d

Browse files
committed
graph, node, store: Return eviction stats from clear_stale_call_cache
Return a StaleCallCacheResult struct with effective_ttl_days, cache_entries_deleted, and contracts_deleted so the graphman command can report what actually happened to the user.
1 parent 40bbfc9 commit f24650d

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

graph/src/blockchain/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
network_provider::ChainName,
77
store::{
88
BlockNumber, ChainHeadStore, ChainIdStore, DeploymentCursorTracker, DeploymentLocator,
9-
SourceableStore,
9+
SourceableStore, StaleCallCacheResult,
1010
},
1111
subgraph::InstanceDSTemplateInfo,
1212
},
@@ -596,7 +596,7 @@ impl ChainStore for MockChainStore {
596596
&self,
597597
_ttl_days: usize,
598598
_max_contracts: Option<usize>,
599-
) -> Result<(), Error> {
599+
) -> Result<StaleCallCacheResult, Error> {
600600
unimplemented!()
601601
}
602602
async fn chain_identifier(&self) -> Result<ChainIdentifier, Error> {

graph/src/components/store/traits.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,18 @@ pub trait ChainIdStore: Send + Sync + 'static {
530530
/// configuration can change this for individual chains
531531
pub const BLOCK_CACHE_SIZE: BlockNumber = i32::MAX;
532532

533+
/// Result of clearing stale call cache entries.
534+
pub struct StaleCallCacheResult {
535+
/// The effective TTL in days that was actually used for deletion.
536+
/// This may be larger than the requested TTL if `max_contracts`
537+
/// was set and caused the cutoff to be adjusted.
538+
pub effective_ttl_days: usize,
539+
/// Number of cache entries deleted from the call cache.
540+
pub cache_entries_deleted: usize,
541+
/// Number of contract entries deleted from call meta.
542+
pub contracts_deleted: usize,
543+
}
544+
533545
/// Common trait for blockchain store implementations.
534546
#[async_trait]
535547
pub trait ChainStore: ChainHeadStore {
@@ -664,7 +676,7 @@ pub trait ChainStore: ChainHeadStore {
664676
&self,
665677
ttl_days: usize,
666678
max_contracts: Option<usize>,
667-
) -> Result<(), Error>;
679+
) -> Result<StaleCallCacheResult, Error>;
668680

669681
/// Return the chain identifier for this store.
670682
async fn chain_identifier(&self) -> Result<ChainIdentifier, Error>;

graph/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ pub mod prelude {
128128
EntityCollection, EntityFilter, EntityLink, EntityOperation, EntityOrder,
129129
EntityOrderByChild, EntityOrderByChildInfo, EntityQuery, EntityRange, EntityWindow,
130130
EthereumCallCache, ParentLink, PartialBlockPtr, PoolWaitStats, QueryStore,
131-
QueryStoreManager, SeqGenerator, StoreError, StoreEvent, StoreEventStreamBox,
132-
SubgraphStore, UnfailOutcome, WindowAttribute, BLOCK_NUMBER_MAX,
131+
QueryStoreManager, SeqGenerator, StaleCallCacheResult, StoreError, StoreEvent,
132+
StoreEventStreamBox, SubgraphStore, UnfailOutcome, WindowAttribute, BLOCK_NUMBER_MAX,
133133
};
134134
pub use crate::components::subgraph::{
135135
BlockState, BlockStateCheckpoint, HostMetrics, InstanceDSTemplateInfo, RuntimeHost,

node/src/manager/commands/chain.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,21 @@ pub async fn clear_stale_call_cache(
9090
"Removing stale entries from the call cache for `{}`",
9191
chain_store.chain
9292
);
93-
chain_store
93+
let result = chain_store
9494
.clear_stale_call_cache(ttl_days, max_contracts)
9595
.await?;
96+
if result.effective_ttl_days != ttl_days {
97+
println!(
98+
"Effective TTL: {} days (adjusted from {} to stay within {} contracts)",
99+
result.effective_ttl_days,
100+
ttl_days,
101+
max_contracts.unwrap()
102+
);
103+
}
104+
println!(
105+
"Deleted {} cache entries for {} contracts",
106+
result.cache_entries_deleted, result.contracts_deleted
107+
);
96108
Ok(())
97109
}
98110

store/postgres/src/chain_store.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ use graph::cheap_clone::CheapClone;
3232
use graph::components::ethereum::CachedBlock;
3333
use graph::prelude::{
3434
serde_json as json, transaction_receipt::LightTransactionReceipt, BlockNumber, BlockPtr,
35-
CachedEthereumCall, ChainStore as ChainStoreTrait, Error, EthereumCallCache, StoreError,
35+
CachedEthereumCall, ChainStore as ChainStoreTrait, Error, EthereumCallCache,
36+
StaleCallCacheResult, StoreError,
3637
};
3738
use graph::{ensure, internal_error};
3839

@@ -3281,7 +3282,7 @@ impl ChainStoreTrait for ChainStore {
32813282
&self,
32823283
ttl_days: usize,
32833284
max_contracts: Option<usize>,
3284-
) -> Result<(), Error> {
3285+
) -> Result<StaleCallCacheResult, Error> {
32853286
const LOG_INTERVAL: Duration = Duration::from_mins(5);
32863287

32873288
let conn = &mut self.pool.get_permitted().await?;
@@ -3357,7 +3358,11 @@ impl ChainStoreTrait for ChainStore {
33573358
batch_count
33583359
);
33593360

3360-
Ok(())
3361+
Ok(StaleCallCacheResult {
3362+
effective_ttl_days: effective_ttl as usize,
3363+
cache_entries_deleted: total_deleted,
3364+
contracts_deleted,
3365+
})
33613366
}
33623367

33633368
async fn transaction_receipts_in_block(

0 commit comments

Comments
 (0)