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

[mtg-778] Clean asset slot update idx #325

Merged
merged 6 commits into from
Nov 27, 2024
Merged

Conversation

kstepanovdev
Copy link
Contributor

After each synchronization redundant idxs will be removed from the rocksDb

@kstepanovdev kstepanovdev force-pushed the clean-asset-slot-update-idx branch from 037fea8 to 2f8e7ee Compare November 26, 2024 10:34
return Ok(());
}

let mut batch = rocksdb::WriteBatchWithTransaction::<false>::default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the reason for using batch here? It seems like you perform a single operation on this batch, so does it make sense to use it at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore, indeed. Previously it was multiple deletions via iterator

@@ -270,4 +270,13 @@ impl BatchSaveStorage {
}
Ok(())
}

pub fn clean_syncronized_idxs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need such wrapper functions?

Comment on lines 3781 to 3798
let mut number_of_fungible_idxs = 0;
let mut number_of_non_fungible_idxs = 0;
let mut idx_fungible_asset_iter = env
.rocks_env
.storage
.fungible_assets_update_idx
.iter_start();
let mut idx_non_fungible_asset_iter = env.rocks_env.storage.assets_update_idx.iter_start();

while let Some(_) = idx_fungible_asset_iter.next() {
number_of_fungible_idxs += 1;
}
assert_eq!(number_of_fungible_idxs, 1);

while let Some(_) = idx_non_fungible_asset_iter.next() {
number_of_non_fungible_idxs += 1;
}
assert_eq!(number_of_non_fungible_idxs, 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can use iter_start().count()

@RequescoS
Copy link
Contributor

Great job, thank you! Left only a couple of minor comments

SyncStatus::NoSyncRequired => {}
}

if let Some(encoded_key) = self.index_storage.fetch_last_synced_id(asset_type).await? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always expert fetch_last_synced_id() return here Some(_) because if we receive None it will mean that some jobs are incomplete or we have some bug in code. So, maybe use ok_or()? Or at least add an error log if fetch_last_synced_id returned None

@kstepanovdev kstepanovdev force-pushed the clean-asset-slot-update-idx branch from 306dcd9 to 7bfba09 Compare November 26, 2024 14:20
&& called cleaning up from the ingester instead of the synchronizer
@kstepanovdev kstepanovdev force-pushed the clean-asset-slot-update-idx branch from 7bfba09 to 3e3f044 Compare November 26, 2024 14:34
assert_eq!(idx_fungible_asset_iter.count(), 1);
assert_eq!(idx_non_fungible_asset_iter.count(), cnt + 2);

for asset_type in ASSET_TYPES {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: wdyt about wrapping part of this stuff with function? then we should not copy past it from ingester/main.rs

@kstepanovdev kstepanovdev requested a review from n00m4d November 26, 2024 15:47
@kstepanovdev kstepanovdev force-pushed the clean-asset-slot-update-idx branch from b35fa92 to 42f5add Compare November 26, 2024 15:51
@kstepanovdev kstepanovdev force-pushed the clean-asset-slot-update-idx branch from 42f5add to eadeb0d Compare November 26, 2024 15:53
@@ -75,6 +76,7 @@ pub const DEFAULT_ROCKSDB_PATH: &str = "./my_rocksdb";
pub const ARWEAVE_WALLET_PATH: &str = "./arweave_wallet.json";
pub const DEFAULT_MIN_POSTGRES_CONNECTIONS: u32 = 100;
pub const DEFAULT_MAX_POSTGRES_CONNECTIONS: u32 = 100;
pub const SECONDS_TO_RETRY_IDXS_CLEANUP: u64 = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make if less often, like once in 15 mins

error!("Failed to clean synchronized indexes for {:?} with error {}", asset_type, e);
}
}
tokio::time::sleep(Duration::from_secs(SECONDS_TO_RETRY_IDXS_CLEANUP)).await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does it work with termination (ctrl+c) of the app? we usually switch on it and the shutdown_rx

@kstepanovdev kstepanovdev requested a review from StanChe November 27, 2024 12:35
};

let from = vec![];
self.db.delete_range_cf(&cf, from, last_synced_key)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some additional metrics to track the execution time of this operation?

}
Err(e) => {
error!("Failed to clean synchronized indexes for {:?} with error {}", asset_type, e);
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll stop trying after 1 error, that's not ideal solution

tokio::select! {
_ = rx.recv() => {}
_ = async move {
loop {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokio::select should be inside the loop, as we'll not exit from inside this loop on termination signal, will we?

Copy link
Contributor

@StanChe StanChe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just drop that break and we're good to go

@kstepanovdev kstepanovdev merged commit afeb76e into main Nov 27, 2024
2 checks passed
@kstepanovdev kstepanovdev deleted the clean-asset-slot-update-idx branch November 27, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants