aboutsummaryrefslogtreecommitdiff
path: root/src/k2v-client
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-08-29 11:32:42 +0200
committerAlex Auvolat <alex@adnab.me>2023-08-29 11:32:42 +0200
commit2e90e1c124ea298de5e613de5a672f7c90ab6704 (patch)
tree76d1b50c353048d36e01ffcc8dda2223c0c4545d /src/k2v-client
parent8ef42c9609bcefc642cc9739acb921dffba49b89 (diff)
parent32e5686ad8354a2b2b37807ba6d7add73a6d23ee (diff)
downloadgarage-2e90e1c124ea298de5e613de5a672f7c90ab6704.tar.gz
garage-2e90e1c124ea298de5e613de5a672f7c90ab6704.zip
Merge branch 'main' into nextv0.9.0-beta1
Diffstat (limited to 'src/k2v-client')
-rw-r--r--src/k2v-client/bin/k2v-cli.rs18
-rw-r--r--src/k2v-client/lib.rs17
2 files changed, 22 insertions, 13 deletions
diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs
index 5a2422ab..b9461c89 100644
--- a/src/k2v-client/bin/k2v-cli.rs
+++ b/src/k2v-client/bin/k2v-cli.rs
@@ -311,23 +311,19 @@ impl BatchOutputKind {
.collect::<Vec<_>>()
}
- fn display_poll_range_output(
- &self,
- seen_marker: String,
- values: BTreeMap<String, CausalValue>,
- ) -> ! {
+ fn display_poll_range_output(&self, poll_range: PollRangeResult) -> ! {
if self.json {
let json = serde_json::json!({
- "values": self.values_json(values),
- "seen_marker": seen_marker,
+ "values": self.values_json(poll_range.items),
+ "seen_marker": poll_range.seen_marker,
});
let stdout = std::io::stdout();
serde_json::to_writer_pretty(stdout, &json).unwrap();
exit(0)
} else {
- println!("seen marker: {}", seen_marker);
- self.display_human_output(values)
+ println!("seen marker: {}", poll_range.seen_marker);
+ self.display_human_output(poll_range.items)
}
}
@@ -501,8 +497,8 @@ async fn main() -> Result<(), Error> {
)
.await?;
match res {
- Some((items, seen_marker)) => {
- output_kind.display_poll_range_output(seen_marker, items);
+ Some(poll_range_output) => {
+ output_kind.display_poll_range_output(poll_range_output);
}
None => {
if output_kind.json {
diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs
index 425c351f..4aa7a20a 100644
--- a/src/k2v-client/lib.rs
+++ b/src/k2v-client/lib.rs
@@ -182,7 +182,7 @@ impl K2vClient {
filter: Option<PollRangeFilter<'_>>,
seen_marker: Option<&str>,
timeout: Option<Duration>,
- ) -> Result<Option<(BTreeMap<String, CausalValue>, String)>, Error> {
+ ) -> Result<Option<PollRangeResult>, Error> {
let timeout = timeout.unwrap_or(DEFAULT_POLL_TIMEOUT);
let request = PollRangeRequest {
@@ -217,7 +217,10 @@ impl K2vClient {
})
.collect::<BTreeMap<_, _>>();
- Ok(Some((items, resp.seen_marker)))
+ Ok(Some(PollRangeResult {
+ items,
+ seen_marker: resp.seen_marker,
+ }))
}
/// Perform an InsertItem request, inserting a value for a single pk+sk.
@@ -570,6 +573,7 @@ pub struct Filter<'a> {
pub reverse: bool,
}
+/// Filter for a poll range operations.
#[derive(Debug, Default, Clone, Serialize)]
pub struct PollRangeFilter<'a> {
pub start: Option<&'a str>,
@@ -577,6 +581,15 @@ pub struct PollRangeFilter<'a> {
pub prefix: Option<&'a str>,
}
+/// Response to a poll_range query
+#[derive(Debug, Default, Clone, Serialize)]
+pub struct PollRangeResult {
+ /// List of items that have changed since last PollRange call.
+ pub items: BTreeMap<String, CausalValue>,
+ /// opaque string representing items already seen for future PollRange calls.
+ pub seen_marker: String,
+}
+
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct PollRangeRequest<'a> {