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

fix(scan): handle "No: more data" error. #144

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
36 changes: 22 additions & 14 deletions zstor/src/zdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ impl InternalZdb {
internal: ErrorCause::Redis(e),
})
}
async fn scan(&self, cursor: Option<Vec<u8>>) -> ZdbResult<(Vec<u8>, Vec<ScanEntry>)> {

async fn scan(&self, cursor: Option<Vec<u8>>) -> ZdbResult<(Option<Vec<u8>>, Vec<ScanEntry>)> {
trace!(
"scanning namespace {} ",
self.ci.namespace.as_deref().unwrap_or("default"),
Expand All @@ -554,17 +555,24 @@ impl InternalZdb {
}

let mut conn = self.conn.clone();
let res: (Vec<u8>, Vec<ScanEntry>) = match scan_cmd.query_async(&mut conn).await {
Ok(r) => r,
Err(e) => {
return Err(ZdbError {
kind: ZdbErrorKind::Read,
remote: self.ci.clone(),
internal: ErrorCause::Redis(e),
})
}
};
Ok(res)
let (new_cursor, entries): (Vec<u8>, Vec<ScanEntry>) =
match scan_cmd.query_async(&mut conn).await {
Ok(r) => r,
Err(e) => {
// zdb will return `No: more data` error when the scan is done. This is not an
// error, but a signal that the scan is done.
if e.to_string() == "No: more data" {
return Ok((None, Vec::new()));
} else {
return Err(ZdbError {
kind: ZdbErrorKind::Read,
remote: self.ci.clone(),
internal: ErrorCause::Redis(e),
});
}
}
};
Ok((Some(new_cursor), entries))
}

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

let mut keys = Vec::new();
for entry in &entries {
Expand All @@ -841,7 +849,7 @@ impl UserKeyZdb {
}
}

Ok((Some(cursor), keys))
Ok((new_cursor, keys))
}

/// Get a stream which yields all the keys in the namespace.
Expand Down
Loading