Skip to content

Commit a56cc78

Browse files
committed
graph, node, store: Remove ttl_max_contracts from clear_stale_call_cache
The ttl_max_contracts parameter limited how many contracts got processed per invocation. With the upcoming switch to a more efficient delete strategy that doesn't iterate by contract, this parameter no longer maps to anything meaningful. Remove it from the trait, CLI, and all implementations.
1 parent cb37899 commit a56cc78

6 files changed

Lines changed: 6 additions & 48 deletions

File tree

graph/src/blockchain/mock.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,7 @@ impl ChainStore for MockChainStore {
592592
async fn clear_call_cache(&self, _from: BlockNumber, _to: BlockNumber) -> Result<(), Error> {
593593
unimplemented!()
594594
}
595-
async fn clear_stale_call_cache(
596-
&self,
597-
_ttl_days: usize,
598-
_ttl_max_contracts: Option<usize>,
599-
) -> Result<(), Error> {
595+
async fn clear_stale_call_cache(&self, _ttl_days: usize) -> Result<(), Error> {
600596
unimplemented!()
601597
}
602598
async fn chain_identifier(&self) -> Result<ChainIdentifier, Error> {

graph/src/components/store/traits.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,7 @@ pub trait ChainStore: ChainHeadStore {
658658
async fn clear_call_cache(&self, from: BlockNumber, to: BlockNumber) -> Result<(), Error>;
659659

660660
/// Clears stale call cache entries for the given TTL in days.
661-
async fn clear_stale_call_cache(
662-
&self,
663-
ttl_days: usize,
664-
ttl_max_contracts: Option<usize>,
665-
) -> Result<(), Error>;
661+
async fn clear_stale_call_cache(&self, ttl_days: usize) -> Result<(), Error>;
666662

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

node/src/bin/manager.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ pub enum CallCacheCommand {
621621
/// Remove the cache for contracts that have not been accessed in the last <TTL_DAYS> days
622622
#[clap(long, conflicts_with_all = &["from", "to", "remove-entire-cache"], value_parser = clap::value_parser!(u32).range(1..))]
623623
ttl_days: Option<usize>,
624-
/// Limits the number of contracts to consider for cache removal when using --ttl_days
625-
#[clap(long, conflicts_with_all = &["remove-entire-cache", "to", "from"], requires = "ttl_days", value_parser = clap::value_parser!(u64).range(1..))]
626-
ttl_max_contracts: Option<usize>,
627624
/// Starting block number
628625
#[clap(long, short, conflicts_with = "remove-entire-cache", requires = "to")]
629626
from: Option<i32>,
@@ -1549,14 +1546,12 @@ async fn main() -> anyhow::Result<()> {
15491546
to,
15501547
remove_entire_cache,
15511548
ttl_days,
1552-
ttl_max_contracts,
15531549
} => {
15541550
let chain_store = ctx.chain_store(&chain_name).await?;
15551551
if let Some(ttl_days) = ttl_days {
15561552
return commands::chain::clear_stale_call_cache(
15571553
chain_store,
15581554
ttl_days,
1559-
ttl_max_contracts,
15601555
)
15611556
.await;
15621557
}

node/src/manager/commands/chain.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,12 @@ pub async fn clear_call_cache(
8484
pub async fn clear_stale_call_cache(
8585
chain_store: Arc<ChainStore>,
8686
ttl_days: usize,
87-
ttl_max_contracts: Option<usize>,
8887
) -> Result<(), Error> {
8988
println!(
9089
"Removing stale entries from the call cache for `{}`",
9190
chain_store.chain
9291
);
93-
chain_store
94-
.clear_stale_call_cache(ttl_days, ttl_max_contracts)
95-
.await?;
92+
chain_store.clear_stale_call_cache(ttl_days).await?;
9693
Ok(())
9794
}
9895

store/postgres/src/chain_store.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,11 +3276,7 @@ impl ChainStoreTrait for ChainStore {
32763276
Ok(())
32773277
}
32783278

3279-
async fn clear_stale_call_cache(
3280-
&self,
3281-
ttl_days: usize,
3282-
ttl_max_contracts: Option<usize>,
3283-
) -> Result<(), Error> {
3279+
async fn clear_stale_call_cache(&self, ttl_days: usize) -> Result<(), Error> {
32843280
let conn = &mut self.pool.get_permitted().await?;
32853281

32863282
self.storage
@@ -3289,35 +3285,13 @@ impl ChainStoreTrait for ChainStore {
32893285

32903286
let mut total_calls: usize = 0;
32913287
let mut total_contracts: usize = 0;
3292-
// We process contracts in batches to avoid loading too many
3293-
// entries into memory at once. Each contract can have many
3294-
// calls, so we delete calls in adaptive batches that
3295-
// self-tune based on query duration.
32963288
let contracts_batch_size: usize = ENV_VARS.store.stale_call_cache_contracts_batch_size;
32973289
let mut batch_size = AdaptiveBatchSize::with_size(100);
32983290

3299-
// Limits the number of contracts to process if ttl_max_contracts is set.
3300-
// Used also to adjust the final batch size, so we don't process more
3301-
// contracts than the set limit.
3302-
let remaining_contracts = |processed: usize| -> Option<usize> {
3303-
ttl_max_contracts.map(|limit| limit.saturating_sub(processed))
3304-
};
3305-
33063291
loop {
3307-
if let Some(0) = remaining_contracts(total_contracts) {
3308-
info!(self.logger,
3309-
"Finished cleaning call cache: deleted {} entries for {} contracts (limit reached)",
3310-
total_calls, total_contracts);
3311-
break;
3312-
}
3313-
3314-
let batch_limit = remaining_contracts(total_contracts)
3315-
.map(|left| left.min(contracts_batch_size))
3316-
.unwrap_or(contracts_batch_size);
3317-
33183292
let stale_contracts = self
33193293
.storage
3320-
.stale_contracts(conn, batch_limit, ttl_days)
3294+
.stale_contracts(conn, contracts_batch_size, ttl_days)
33213295
.await?;
33223296

33233297
if stale_contracts.is_empty() {

store/test-store/tests/postgres/chain_head.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ fn test_clear_stale_call_cache() {
636636
.await
637637
.unwrap();
638638
}
639-
let result = chain_store.clear_stale_call_cache(7, None).await;
639+
let result = chain_store.clear_stale_call_cache(7).await;
640640
assert!(result.is_ok());
641641

642642
// Confirm the call cache entry was removed

0 commit comments

Comments
 (0)