-
Notifications
You must be signed in to change notification settings - Fork 82
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
Migrate Events Processor to Use New Version Tracker Impl #560
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a3651e
Migrate events processor to use new version tracker impl
dermanyang fe0f28d
Formatting
dermanyang 0a66385
Merge branch 'main' into sdy/restart_behavior_changes
dermanyang ba8df18
Undo typo
dermanyang f4ee554
Changes from comments
dermanyang 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 2 additions & 0 deletions
2
...processor/src/db/postgres/migrations/2024-10-22-214753_backfill_processor_status/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,2 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS backfill_processor_status; |
11 changes: 11 additions & 0 deletions
11
rust/processor/src/db/postgres/migrations/2024-10-22-214753_backfill_processor_status/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,11 @@ | ||
-- Your SQL goes here | ||
CREATE TABLE backfill_processor_status ( | ||
backfill_alias VARCHAR(50) NOT NULL, | ||
backfill_status VARCHAR(50) NOT NULL, | ||
last_success_version BIGINT NOT NULL, | ||
last_updated TIMESTAMP NOT NULL DEFAULT NOW(), | ||
last_transaction_timestamp TIMESTAMP NULL, | ||
backfill_start_version BIGINT NOT NULL, | ||
backfill_end_version BIGINT NULL, | ||
PRIMARY KEY (backfill_alias) | ||
); |
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
89 changes: 89 additions & 0 deletions
89
rust/sdk-processor/src/db/common/models/backfill_processor_status.rs
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,89 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![allow(clippy::extra_unused_lifetimes)] | ||
|
||
use crate::utils::database::DbPoolConnection; | ||
use diesel::{ | ||
deserialize, | ||
deserialize::{FromSql, FromSqlRow}, | ||
expression::AsExpression, | ||
pg::{Pg, PgValue}, | ||
serialize, | ||
serialize::{IsNull, Output, ToSql}, | ||
sql_types::Text, | ||
AsChangeset, ExpressionMethods, Insertable, OptionalExtension, QueryDsl, Queryable, | ||
}; | ||
use diesel_async::RunQueryDsl; | ||
use processor::schema::backfill_processor_status; | ||
use std::io::Write; | ||
|
||
const IN_PROGRESS: &[u8] = b"in_progress"; | ||
const COMPLETE: &[u8] = b"complete"; | ||
|
||
#[derive(Debug, PartialEq, FromSqlRow, AsExpression, Eq)] | ||
#[diesel(sql_type = Text)] | ||
pub enum BackfillStatus { | ||
// #[diesel(rename = "in_progress")] | ||
InProgress, | ||
// #[diesel(rename = "complete")] | ||
Complete, | ||
} | ||
|
||
impl ToSql<Text, Pg> for BackfillStatus { | ||
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> serialize::Result { | ||
match *self { | ||
BackfillStatus::InProgress => out.write_all(IN_PROGRESS)?, | ||
BackfillStatus::Complete => out.write_all(COMPLETE)?, | ||
} | ||
Ok(IsNull::No) | ||
} | ||
} | ||
|
||
impl FromSql<Text, Pg> for BackfillStatus { | ||
fn from_sql(bytes: PgValue<'_>) -> deserialize::Result<Self> { | ||
match bytes.as_bytes() { | ||
b"in_progress" => Ok(BackfillStatus::InProgress), | ||
b"complete" => Ok(BackfillStatus::Complete), | ||
_ => Err("Unrecognized enum variant".into()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(AsChangeset, Debug, Insertable)] | ||
#[diesel(table_name = backfill_processor_status)] | ||
/// Only tracking the latest version successfully processed | ||
pub struct BackfillProcessorStatus { | ||
pub backfill_alias: String, | ||
pub backfill_status: BackfillStatus, | ||
pub last_success_version: i64, | ||
pub last_transaction_timestamp: Option<chrono::NaiveDateTime>, | ||
pub backfill_start_version: i64, | ||
pub backfill_end_version: Option<i64>, | ||
} | ||
|
||
#[derive(AsChangeset, Debug, Queryable)] | ||
#[diesel(table_name = backfill_processor_status)] | ||
/// Only tracking the latest version successfully processed | ||
pub struct BackfillProcessorStatusQuery { | ||
pub backfill_alias: String, | ||
pub backfill_status: BackfillStatus, | ||
pub last_success_version: i64, | ||
pub last_updated: chrono::NaiveDateTime, | ||
pub last_transaction_timestamp: Option<chrono::NaiveDateTime>, | ||
pub backfill_start_version: i64, | ||
pub backfill_end_version: Option<i64>, | ||
} | ||
|
||
impl BackfillProcessorStatusQuery { | ||
pub async fn get_by_processor( | ||
backfill_alias: &str, | ||
conn: &mut DbPoolConnection<'_>, | ||
) -> diesel::QueryResult<Option<Self>> { | ||
backfill_processor_status::table | ||
.filter(backfill_processor_status::backfill_alias.eq(backfill_alias)) | ||
.first::<Self>(conn) | ||
.await | ||
.optional() | ||
} | ||
} |
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 @@ | ||
pub mod backfill_processor_status; | ||
pub mod events_models; | ||
pub mod processor_status; |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod latest_processed_version_tracker; | ||
pub mod processor_status_saver; | ||
|
||
pub use processor_status_saver::get_processor_status_saver; |
Oops, something went wrong.
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.
This needed to be changed around otherwise whenever the migrations are re-ran, the ordering of the produced struct's constructor changes causing some issues.
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.
to add a bit of context: this is reverting the change I made manually. this order should be always the same unless we change in sql file.