-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[indexer-alt] add prune impls for each pipeline #20635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::ops::Range; | ||
use std::sync::Arc; | ||
|
||
use anyhow::{bail, Context, Result}; | ||
use diesel::{ExpressionMethods, QueryDsl}; | ||
use diesel_async::RunQueryDsl; | ||
use sui_indexer_alt_framework::pipeline::{concurrent::Handler, Processor}; | ||
use sui_indexer_alt_framework::{ | ||
models::cp_sequence_numbers::epoch_interval, | ||
pipeline::{concurrent::Handler, Processor}, | ||
}; | ||
use sui_indexer_alt_schema::{epochs::StoredEpochEnd, schema::kv_epoch_ends}; | ||
use sui_pg_db as db; | ||
use sui_types::{ | ||
|
@@ -125,4 +130,23 @@ impl Handler for KvEpochEnds { | |
.execute(conn) | ||
.await?) | ||
} | ||
|
||
async fn prune( | ||
&self, | ||
from: u64, | ||
to_exclusive: u64, | ||
conn: &mut db::Connection<'_>, | ||
) -> Result<usize> { | ||
let Range { | ||
start: from_epoch, | ||
end: to_epoch, | ||
} = epoch_interval(conn, from..to_exclusive).await?; | ||
if from_epoch < to_epoch { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check strictly necessary? If they were equal, the The reason I'm asking is that it piqued my interest that this impl had this check, but the previous ones didn't. If there was a correctness reason to have this check (i.e. that we will get some sort of error by having the bounds passed to If there is not a correctness reason to have this test, then the only other reason I could think of was performance, but this is one of the cheapest tables we have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think Postgres has an issue with
If you do run a query ... |
||
let filter = kv_epoch_ends::table | ||
.filter(kv_epoch_ends::epoch.between(from_epoch as i64, to_epoch as i64 - 1)); | ||
Ok(diesel::delete(filter).execute(conn).await?) | ||
} else { | ||
Ok(0) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
use std::sync::Arc; | ||
|
||
use anyhow::{Context, Result}; | ||
use diesel::{ExpressionMethods, QueryDsl}; | ||
use diesel_async::RunQueryDsl; | ||
use sui_indexer_alt_framework::pipeline::{concurrent::Handler, Processor}; | ||
use sui_indexer_alt_schema::{schema::kv_transactions, transactions::StoredTransaction}; | ||
|
@@ -66,4 +67,19 @@ impl Handler for KvTransactions { | |
.execute(conn) | ||
.await?) | ||
} | ||
|
||
async fn prune( | ||
&self, | ||
from: u64, | ||
to_exclusive: u64, | ||
conn: &mut db::Connection<'_>, | ||
) -> Result<usize> { | ||
// TODO: use tx_interval. `tx_sequence_number` needs to be added to this table, and an index | ||
// created as its primary key is on `tx_digest`. | ||
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's keep this table as it is. Its schema needs to match the schema and indices need to match what is offered in the KV store as much as possible. |
||
let filter = kv_transactions::table.filter( | ||
kv_transactions::cp_sequence_number.between(from as i64, to_exclusive as i64 - 1), | ||
); | ||
|
||
Ok(diesel::delete(filter).execute(conn).await?) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
- 1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
to_tx
is the first tx of the to_exclusive checkpoint and should not be pruned