Skip to content
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

feat: stream and nomral use same syncing status #107

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ethetl/src/etl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub use pipeline::Pipeline;
pub use stream::StreamEtl;
pub use worker::Worker;

// The syncing status file.
pub static SYNCING_STATUS_FILE: &str = "mars_syncing_status.json";

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct SyncingStatus {
start: usize,
Expand Down
11 changes: 4 additions & 7 deletions ethetl/src/etl/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use log::info;
use crate::contexts::ContextRef;
use crate::etl::Batch;
use crate::etl::SyncingStatus;

static NORMAL_SYNCING_STATUS_FILE: &str = "mars_normal_syncing_status.json";
use crate::etl::SYNCING_STATUS_FILE;

pub struct NormalEtl {
ctx: ContextRef,
Expand All @@ -37,21 +36,19 @@ impl NormalEtl {
// Fetch syncing file.
{
let op = self.ctx.get_storage();
if let Ok(data) = op.object(NORMAL_SYNCING_STATUS_FILE).read().await {
if let Ok(data) = op.object(SYNCING_STATUS_FILE).read().await {
let prev_syncing_status: SyncingStatus = serde_json::from_slice(&data)?;
start = prev_syncing_status.end + 1;
info!(
"Found normal syncing status file={}, status={:?}",
NORMAL_SYNCING_STATUS_FILE, prev_syncing_status
SYNCING_STATUS_FILE, prev_syncing_status
);
}
}

if start <= end {
let batch = Batch::create(self.ctx.clone());
batch
.syncing(start, end, NORMAL_SYNCING_STATUS_FILE)
.await?;
batch.syncing(start, end, SYNCING_STATUS_FILE).await?;
}

Ok(())
Expand Down
11 changes: 4 additions & 7 deletions ethetl/src/etl/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use crate::chains::eth::BlockNumber;
use crate::contexts::ContextRef;
use crate::etl::Batch;
use crate::etl::SyncingStatus;

static STREAM_SYNCING_STATUS_FILE: &str = "mars_stream_syncing_status.json";
use crate::etl::SYNCING_STATUS_FILE;

pub struct StreamEtl {
ctx: ContextRef,
Expand All @@ -40,12 +39,12 @@ impl StreamEtl {
// Fetch syncing file.
{
let op = self.ctx.get_storage();
if let Ok(data) = op.object(STREAM_SYNCING_STATUS_FILE).read().await {
if let Ok(data) = op.object(SYNCING_STATUS_FILE).read().await {
let prev_syncing_status: SyncingStatus = serde_json::from_slice(&data)?;
start = prev_syncing_status.end + 1;
info!(
"Found syncing status file={}, status={:?}",
STREAM_SYNCING_STATUS_FILE, prev_syncing_status
SYNCING_STATUS_FILE, prev_syncing_status
);
}
}
Expand All @@ -63,9 +62,7 @@ impl StreamEtl {
};
if start <= end {
let batch = Batch::create(self.ctx.clone());
batch
.syncing(start, end, STREAM_SYNCING_STATUS_FILE)
.await?;
batch.syncing(start, end, SYNCING_STATUS_FILE).await?;
start = end + 1;
}
}
Expand Down