From b6d59ec19a3d41ce581716cf0dda5d47c2785843 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 4 Jul 2022 14:00:02 +0200 Subject: Fix poll item when item didn't change --- src/k2v-client/bin/k2v-cli.rs | 9 ++++++++- src/k2v-client/lib.rs | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index 884e7438..925ebeb8 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use k2v_client::*; use garage_util::formater::format_table; @@ -64,6 +66,9 @@ enum Command { /// Causality information #[clap(short, long)] causality: String, + /// Timeout, in seconds + #[clap(short, long)] + timeout: Option, /// Output formating #[clap(flatten)] output_kind: ReadOutputKind, @@ -341,10 +346,12 @@ async fn main() -> Result<(), Error> { partition_key, sort_key, causality, + timeout, output_kind, } => { + let timeout = timeout.map(Duration::from_secs); let res_opt = client - .poll_item(&partition_key, &sort_key, causality.into(), None) + .poll_item(&partition_key, &sort_key, causality.into(), timeout) .await?; if let Some(res) = res_opt { output_kind.display_output(res); diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index 95974d7a..c2606af4 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -122,14 +122,14 @@ impl K2vClient { let res = self.dispatch(req, Some(timeout + DEFAULT_TIMEOUT)).await?; - let causality = res - .causality_token - .ok_or_else(|| Error::InvalidResponse("missing causality token".into()))?; - if res.status == StatusCode::NOT_MODIFIED { return Ok(None); } + let causality = res + .causality_token + .ok_or_else(|| Error::InvalidResponse("missing causality token".into()))?; + if res.status == StatusCode::NO_CONTENT { return Ok(Some(CausalValue { causality, -- cgit v1.2.3 From fe3fa83de74b79ffeeb2042c58b9360defa65431 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 4 Jul 2022 18:27:25 +0200 Subject: Publish k2v-client crate to crates.io (#337) Co-authored-by: Alex Auvolat Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/337 Co-authored-by: Alex Co-committed-by: Alex --- src/k2v-client/Cargo.toml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml index 224414ab..2f8a2679 100644 --- a/src/k2v-client/Cargo.toml +++ b/src/k2v-client/Cargo.toml @@ -1,7 +1,12 @@ [package] name = "k2v-client" -version = "0.1.0" +version = "0.0.1" +authors = ["Trinity Pointard ", "Alex Auvolat "] edition = "2018" +license = "AGPL-3.0" +description = "Client library for the Garage K2V protocol" +repository = "https://git.deuxfleurs.fr/Deuxfleurs/garage" +readme = "../../README.md" [dependencies] base64 = "0.13.0" @@ -17,7 +22,7 @@ tokio = "1.17.0" # cli deps clap = { version = "3.1.18", optional = true, features = ["derive", "env"] } -garage_util = { path = "../util", optional = true } +garage_util = { version = "0.7.0", path = "../util", optional = true } [features] -- cgit v1.2.3 From aab34bfe5415e9584432bf32e29a151dc5af9ebd Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 4 Jul 2022 12:53:47 +0200 Subject: add delays in k2v test_items_and_indices --- src/garage/tests/k2v/item.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/garage/tests/k2v/item.rs b/src/garage/tests/k2v/item.rs index bf2b01f8..32537336 100644 --- a/src/garage/tests/k2v/item.rs +++ b/src/garage/tests/k2v/item.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use crate::common; use assert_json_diff::assert_json_eq; @@ -86,6 +88,7 @@ async fn test_items_and_indices() { assert_eq!(res_body, content); // ReadIndex -- now there should be some stuff + tokio::time::sleep(Duration::from_secs(1)).await; let res = ctx .k2v .request @@ -154,6 +157,7 @@ async fn test_items_and_indices() { assert_eq!(res_body, content2); // ReadIndex -- now there should be some stuff + tokio::time::sleep(Duration::from_secs(1)).await; let res = ctx .k2v .request @@ -222,6 +226,7 @@ async fn test_items_and_indices() { ); // ReadIndex -- now there should be some stuff + tokio::time::sleep(Duration::from_secs(1)).await; let res = ctx .k2v .request @@ -290,6 +295,7 @@ async fn test_items_and_indices() { assert_eq!(res.status(), 204); // ReadIndex -- now there should be some stuff + tokio::time::sleep(Duration::from_secs(1)).await; let res = ctx .k2v .request -- cgit v1.2.3