Skip to content

improve sync command#66

Open
sonlexuan3000 wants to merge 1 commit intoAI-Decenter:mainfrom
sonlexuan3000:main
Open

improve sync command#66
sonlexuan3000 wants to merge 1 commit intoAI-Decenter:mainfrom
sonlexuan3000:main

Conversation

@sonlexuan3000
Copy link
Contributor

No description provided.

@NQKhaixyz NQKhaixyz requested a review from Copilot September 25, 2025 08:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR significantly improves the sync command by transitioning from a simple flat Merkle tree comparison to a recursive prefix-based synchronization approach. The new implementation uses tree traversal with configurable fanout and depth limits for more efficient synchronization of large datasets.

Key changes:

  • Replaced flat Merkle tree diff with recursive prefix-based synchronization using a 64-character fanout
  • Added support for remote HASH commands to compare subtree hashes before full reconciliation
  • Introduced configurable max depth and leaf threshold parameters with sensible defaults

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


/// GET one key: "GET <key>\r\n" → "VALUE <plain>\r\n" or "NOT_FOUND\r\n"
async fn read_remote_value_plain(&self, addr: &str, key: &str) -> Result<Option<String>> {
/// GET key → "VALUE <val>" hoặc "NOT_FOUND"
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The comment contains Vietnamese text 'hoặc' which should be 'or' in English to maintain consistency with the rest of the codebase.

Suggested change
/// GET key → "VALUE <val>" hoặc "NOT_FOUND"
/// GET key → "VALUE <val>" or "NOT_FOUND"

Copilot uses AI. Check for mistakes.
let (t, _map) = self.build_local_merkle_snapshot(prefix).await?;
Ok(match t.get_root_hash() {
Some(h) => to_hex(h),
None => "0".repeat(64),
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

Magic number 64 should be defined as a constant (e.g., const HASH_HEX_LENGTH: usize = 64) since it's used multiple times in the code for hash validation and generation.

Copilot uses AI. Check for mistakes.
Comment on lines +194 to +196
if hex.len() != 64 {
return Err(anyhow!("bad HASH hex length: {}", hex));
}
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

This uses the same magic number 64 as in the previous comment. Both instances should reference a shared constant for hash hex length.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +75
fn sync_prefix_recursive<'a>(
&'a self,
addr: &'a str,
prefix: String,
depth: usize,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> {
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The prefix parameter should be &str instead of String to avoid unnecessary allocations during recursive calls. The function can clone the prefix only when needed for the recursive call.

Copilot uses AI. Check for mistakes.
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.

2 participants