Skip to content

Commit 1532396

Browse files
iwanbkLeeSmet
authored andcommitted
fix(scan): handle "No: more data" error.
zdb return "No: more data" string when the scan is finished. This commit handle it properly instead of logging an error.
1 parent 1ebf9b7 commit 1532396

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

zstor/src/zdb.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ impl InternalZdb {
541541
internal: ErrorCause::Redis(e),
542542
})
543543
}
544-
async fn scan(&self, cursor: Option<Vec<u8>>) -> ZdbResult<(Vec<u8>, Vec<ScanEntry>)> {
544+
545+
async fn scan(&self, cursor: Option<Vec<u8>>) -> ZdbResult<(Option<Vec<u8>>, Vec<ScanEntry>)> {
545546
trace!(
546547
"scanning namespace {} ",
547548
self.ci.namespace.as_deref().unwrap_or("default"),
@@ -554,17 +555,24 @@ impl InternalZdb {
554555
}
555556

556557
let mut conn = self.conn.clone();
557-
let res: (Vec<u8>, Vec<ScanEntry>) = match scan_cmd.query_async(&mut conn).await {
558-
Ok(r) => r,
559-
Err(e) => {
560-
return Err(ZdbError {
561-
kind: ZdbErrorKind::Read,
562-
remote: self.ci.clone(),
563-
internal: ErrorCause::Redis(e),
564-
})
565-
}
566-
};
567-
Ok(res)
558+
let (new_cursor, entries): (Vec<u8>, Vec<ScanEntry>) =
559+
match scan_cmd.query_async(&mut conn).await {
560+
Ok(r) => r,
561+
Err(e) => {
562+
// zdb will return `No: more data` error when the scan is done. This is not an
563+
// error, but a signal that the scan is done.
564+
if e.to_string() == "No: more data" {
565+
return Ok((None, Vec::new()));
566+
} else {
567+
return Err(ZdbError {
568+
kind: ZdbErrorKind::Read,
569+
remote: self.ci.clone(),
570+
internal: ErrorCause::Redis(e),
571+
});
572+
}
573+
}
574+
};
575+
Ok((Some(new_cursor), entries))
568576
}
569577

570578
/// Get a stream of all the keys in the namespace
@@ -819,7 +827,7 @@ impl UserKeyZdb {
819827
prefix: Option<&str>,
820828
max_timestamp: Option<u64>,
821829
) -> ZdbResult<(Option<Vec<u8>>, Vec<String>)> {
822-
let (cursor, entries): (Vec<u8>, Vec<ScanEntry>) = self.internal.scan(cursor).await?;
830+
let (new_cursor, entries) = self.internal.scan(cursor).await?;
823831

824832
let mut keys = Vec::new();
825833
for entry in &entries {
@@ -841,7 +849,7 @@ impl UserKeyZdb {
841849
}
842850
}
843851

844-
Ok((Some(cursor), keys))
852+
Ok((new_cursor, keys))
845853
}
846854

847855
/// Get a stream which yields all the keys in the namespace.

0 commit comments

Comments
 (0)