forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
indexer pruner: add pruner and prune unpartitioned tables (MystenLabs…
…#18495) ## Description a separate pruner that use `epochs` table and `cp_tx` table to track progress of pruning and handle disaster recovery; and `checkpoints` table as available range data source. ## Test plan local run and verify via local client - progress tracking via epoch, cp, and tx ![epoch_progress](https://github.com/MystenLabs/sui/assets/106119108/f628c7b5-add7-4198-94e3-f2542dfd7890) ![tx_cp_progress](https://github.com/MystenLabs/sui/assets/106119108/4395ff7d-b79b-4a6d-aec6-243ac5c86c22) - verify on checkpoints & tx_ tables - make sure that the checkpoints table is indeed latest cp_tx cp + 1 ![check_cp](https://github.com/MystenLabs/sui/assets/106119108/13de7129-16b6-44e9-a922-c487100cb152) - make sure that all cp < min_tx in cp_tx have been pruned ![check_tx](https://github.com/MystenLabs/sui/assets/106119108/0708e667-135a-44be-be77-b1eb667ba640) --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
- Loading branch information
Showing
16 changed files
with
461 additions
and
5 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/sui-indexer/migrations/mysql/2024-04-24-180008_checkpoints/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
DROP TABLE IF EXISTS checkpoints; | ||
DROP TABLE IF EXISTS pruner_cp_watermark; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/sui-indexer/migrations/pg/2023-08-19-044044_checkpoints/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS checkpoints; | ||
DROP TABLE IF EXISTS pruner_cp_watermark; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::time::Duration; | ||
|
||
use tokio_util::sync::CancellationToken; | ||
use tracing::{error, info}; | ||
|
||
use crate::{metrics::IndexerMetrics, store::IndexerStore, types::IndexerResult}; | ||
|
||
pub struct Pruner<S> { | ||
pub store: S, | ||
pub epochs_to_keep: u64, | ||
pub metrics: IndexerMetrics, | ||
} | ||
|
||
impl<S> Pruner<S> | ||
where | ||
S: IndexerStore + Clone + Sync + Send + 'static, | ||
{ | ||
pub fn new(store: S, epochs_to_keep: u64, metrics: IndexerMetrics) -> Self { | ||
Self { | ||
store, | ||
epochs_to_keep, | ||
metrics, | ||
} | ||
} | ||
|
||
pub async fn start(&self, cancel: CancellationToken) -> IndexerResult<()> { | ||
loop { | ||
if cancel.is_cancelled() { | ||
info!("Pruner task cancelled."); | ||
return Ok(()); | ||
} | ||
|
||
let (mut min_epoch, mut max_epoch) = self.store.get_available_epoch_range().await?; | ||
while min_epoch + self.epochs_to_keep > max_epoch { | ||
if cancel.is_cancelled() { | ||
info!("Pruner task cancelled."); | ||
return Ok(()); | ||
} | ||
tokio::time::sleep(Duration::from_secs(5)).await; | ||
(min_epoch, max_epoch) = self.store.get_available_epoch_range().await?; | ||
} | ||
|
||
for epoch in min_epoch..=max_epoch - self.epochs_to_keep { | ||
if cancel.is_cancelled() { | ||
info!("Pruner task cancelled."); | ||
return Ok(()); | ||
} | ||
info!("Pruning epoch {}", epoch); | ||
self.store.prune_epoch(epoch).await.unwrap_or_else(|e| { | ||
error!("Failed to prune epoch {}: {}", epoch, e); | ||
}); | ||
self.metrics.last_pruned_epoch.set(epoch as i64); | ||
info!("Pruned epoch {}", epoch); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.