From c63a34f1a21f19951cf157f380c7f3e3fab78d09 Mon Sep 17 00:00:00 2001 From: qima Date: Mon, 20 May 2024 23:44:53 +0800 Subject: [PATCH] fix(node): notify fetch completion earlier to avoid being skipped --- .github/workflows/memcheck.yml | 10 ++++++++++ sn_client/src/register.rs | 2 +- sn_node/src/put_validation.rs | 8 +++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/memcheck.yml b/.github/workflows/memcheck.yml index 0ac8e540a9..cdbdd0b250 100644 --- a/.github/workflows/memcheck.yml +++ b/.github/workflows/memcheck.yml @@ -440,6 +440,16 @@ jobs: fi if: always() + - name: check there is no failed replication fetch + shell: bash + timeout-minutes: 1 + run: | + if grep -r "failed to fetch" $NODE_DATA_PATH + then + echo "We find failed replication fetch" + exit 1 + fi + - name: Upload payment wallet initialization log uses: actions/upload-artifact@main with: diff --git a/sn_client/src/register.rs b/sn_client/src/register.rs index 60b410b68f..430d12092b 100644 --- a/sn_client/src/register.rs +++ b/sn_client/src/register.rs @@ -526,7 +526,7 @@ impl ClientRegister { // any error here will result in a repayment of the register // TODO: be smart about this and only pay for storage if we need to Err(err) => { - debug!("Failed to fetch register: {err:?}"); + debug!("Failed to get register: {err:?}"); debug!("Creating Register as it doesn't exist at {addr:?}!"); let cmd = RegisterCmd::Create { register: self.register.clone(), diff --git a/sn_node/src/put_validation.rs b/sn_node/src/put_validation.rs index 94e0c029c5..6988a8a9ce 100644 --- a/sn_node/src/put_validation.rs +++ b/sn_node/src/put_validation.rs @@ -31,6 +31,11 @@ impl Node { pub(crate) async fn validate_and_store_record(&self, record: Record) -> Result { let record_header = RecordHeader::from_record(&record)?; + // Notify replication_fetcher to mark the attempt as completed. + // Send the notification earlier to avoid it got skipped due to: + // the record becomes stored during the fetch because of other interleaved process. + self.network.notify_fetch_completed(record.key.clone()); + match record_header.kind { RecordKind::ChunkWithPayment => { let record_key = record.key.clone(); @@ -89,9 +94,6 @@ impl Node { record_key, RecordType::NonChunk(content_hash), ); - } else { - // Notify replication_fetcher to mark the attempt as completed. - self.network.notify_fetch_completed(record.key.clone()); } result }