-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
indexer-alt: wal_obj_types pipeline #20116
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
crates/sui-indexer-alt/migrations/2024-10-30-214852_wal_obj_types/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 |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS wal_obj_types; |
76 changes: 76 additions & 0 deletions
76
crates/sui-indexer-alt/migrations/2024-10-30-214852_wal_obj_types/up.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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
-- Write-ahead log for `sum_obj_types`. | ||
-- | ||
-- It contains the same columns and indices as `sum_obj_types`, but with the | ||
-- following changes: | ||
-- | ||
-- - A `cp_sequence_number` column (and an index on it), to support pruning by | ||
-- checkpoint. | ||
-- | ||
-- - The primary key includes the version, as the table may contain multiple | ||
-- versions per object ID. | ||
-- | ||
-- - The `owner_kind` column is nullable, because this table also tracks | ||
-- deleted and wrapped objects (where all the fields except the ID, version, | ||
-- and checkpoint are NULL). | ||
-- | ||
-- - There is an additional index on ID and version for querying the latest | ||
-- version of every object. | ||
-- | ||
-- This table is used in conjunction with `sum_obj_types` to support consistent | ||
-- live object set queries: `sum_obj_types` holds the state of the live object | ||
-- set at some checkpoint `C < T` where `T` is the tip of the chain, and | ||
-- `wal_obj_types` stores all the updates and deletes between `C` and `T`. | ||
-- | ||
-- To reconstruct the the live object set at some snapshot checkpoint `S` | ||
-- between `C` and `T`, a query can be constructed that starts with the set | ||
-- from `sum_obj_types` and adds updates in `wal_obj_types` from | ||
-- `cp_sequence_number <= S`. | ||
-- | ||
-- See `up.sql` for the original `sum_obj_types` table for documentation on | ||
-- columns. | ||
CREATE TABLE IF NOT EXISTS wal_obj_types | ||
( | ||
object_id BYTEA NOT NULL, | ||
object_version BIGINT NOT NULL, | ||
owner_kind SMALLINT, | ||
owner_id BYTEA, | ||
package BYTEA, | ||
module TEXT, | ||
name TEXT, | ||
instantiation BYTEA, | ||
cp_sequence_number BIGINT NOT NULL, | ||
PRIMARY KEY (object_id, object_version) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_cp_sequence_number | ||
ON wal_obj_types (cp_sequence_number); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_version | ||
ON wal_obj_types (object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_owner | ||
ON wal_obj_types (owner_kind, owner_id, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_pkg | ||
ON wal_obj_types (package, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_mod | ||
ON wal_obj_types (package, module, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_name | ||
ON wal_obj_types (package, module, name, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_inst | ||
ON wal_obj_types (package, module, name, instantiation, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_owner_pkg | ||
ON wal_obj_types (owner_kind, owner_id, package, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_owner_mod | ||
ON wal_obj_types (owner_kind, owner_id, package, module, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_owner_name | ||
ON wal_obj_types (owner_kind, owner_id, package, module, name, object_id, object_version); | ||
|
||
CREATE INDEX IF NOT EXISTS wal_obj_types_owner_inst | ||
ON wal_obj_types (owner_kind, owner_id, package, module, name, instantiation, object_id, object_version); |
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,62 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
use diesel_async::RunQueryDsl; | ||
use sui_types::full_checkpoint_content::CheckpointData; | ||
|
||
use crate::{ | ||
db, | ||
models::objects::{StoredObjectUpdate, StoredSumObjType, StoredWalObjType}, | ||
pipeline::{concurrent::Handler, Processor}, | ||
schema::wal_obj_types, | ||
}; | ||
|
||
use super::sum_obj_types::SumObjTypes; | ||
|
||
pub struct WalObjTypes; | ||
|
||
impl Processor for WalObjTypes { | ||
const NAME: &'static str = "wal_obj_types"; | ||
|
||
type Value = StoredObjectUpdate<StoredSumObjType>; | ||
|
||
fn process(checkpoint: &Arc<CheckpointData>) -> Result<Vec<Self::Value>> { | ||
SumObjTypes::process(checkpoint) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Handler for WalObjTypes { | ||
const MIN_EAGER_ROWS: usize = 100; | ||
const MAX_CHUNK_ROWS: usize = 1000; | ||
const MAX_PENDING_ROWS: usize = 10000; | ||
|
||
async fn commit(values: &[Self::Value], conn: &mut db::Connection<'_>) -> Result<usize> { | ||
let values: Vec<_> = values | ||
.iter() | ||
.map(|value| StoredWalObjType { | ||
object_id: value.object_id.to_vec(), | ||
object_version: value.object_version as i64, | ||
|
||
owner_kind: value.update.as_ref().map(|o| o.owner_kind), | ||
owner_id: value.update.as_ref().and_then(|o| o.owner_id.clone()), | ||
|
||
package: value.update.as_ref().and_then(|o| o.package.clone()), | ||
module: value.update.as_ref().and_then(|o| o.module.clone()), | ||
name: value.update.as_ref().and_then(|o| o.name.clone()), | ||
instantiation: value.update.as_ref().and_then(|o| o.instantiation.clone()), | ||
|
||
cp_sequence_number: value.cp_sequence_number as i64, | ||
}) | ||
.collect(); | ||
|
||
Ok(diesel::insert_into(wal_obj_types::table) | ||
.values(&values) | ||
.on_conflict_do_nothing() | ||
.execute(conn) | ||
.await?) | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sum_obj_types is objects_snapshot and wal_obj_types is objects_history, kind of?
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.
That's right -- but without object contents, or coin info.