aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-06-13 17:02:42 +0200
committerAlex Auvolat <alex@adnab.me>2023-06-13 17:14:11 +0200
commit90b2d43eb49d49c3aef4f501a30cf2f181adb183 (patch)
treef7f7c15547e2f2072a1841fcb2350c272faf3c9d /src/garage
parentbf19a44fd93584d5250a2e98e5b1d3a2de6d59d1 (diff)
parent01346143ca09eab262f0d8f8a0a744c2f6d667cc (diff)
downloadgarage-90b2d43eb49d49c3aef4f501a30cf2f181adb183.tar.gz
garage-90b2d43eb49d49c3aef4f501a30cf2f181adb183.zip
Merge branch 'main' into next
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/Cargo.toml3
-rw-r--r--src/garage/admin/mod.rs3
-rw-r--r--src/garage/cli/cmd.rs2
-rw-r--r--src/garage/cli/layout.rs2
-rw-r--r--src/garage/cli/util.rs9
-rw-r--r--src/garage/tests/common/custom_requester.rs1
-rw-r--r--src/garage/tests/common/mod.rs14
-rw-r--r--src/garage/tests/k2v_client/mod.rs1
-rw-r--r--src/garage/tests/k2v_client/simple.rs60
-rw-r--r--src/garage/tests/lib.rs2
10 files changed, 92 insertions, 5 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml
index 7f7c3287..f9fc206b 100644
--- a/src/garage/Cargo.toml
+++ b/src/garage/Cargo.toml
@@ -21,6 +21,7 @@ path = "tests/lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+format_table.workspace = true
garage_db.workspace = true
garage_api.workspace = true
garage_block.workspace = true
@@ -72,6 +73,8 @@ assert-json-diff = "2.0"
serde_json = "1.0"
base64 = "0.21"
+k2v-client.workspace = true
+
[features]
default = [ "bundled-libs", "metrics", "sled", "lmdb", "sqlite", "k2v" ]
diff --git a/src/garage/admin/mod.rs b/src/garage/admin/mod.rs
index 33c21eba..b6f9c426 100644
--- a/src/garage/admin/mod.rs
+++ b/src/garage/admin/mod.rs
@@ -9,10 +9,11 @@ use std::sync::Arc;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
+use format_table::format_table_to_string;
+
use garage_util::background::BackgroundRunner;
use garage_util::data::*;
use garage_util::error::Error as GarageError;
-use garage_util::formater::format_table_to_string;
use garage_table::replication::*;
use garage_table::*;
diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs
index 045f050c..48359614 100644
--- a/src/garage/cli/cmd.rs
+++ b/src/garage/cli/cmd.rs
@@ -1,8 +1,8 @@
use std::collections::HashSet;
use std::time::Duration;
+use format_table::format_table;
use garage_util::error::*;
-use garage_util::formater::format_table;
use garage_rpc::layout::*;
use garage_rpc::system::*;
diff --git a/src/garage/cli/layout.rs b/src/garage/cli/layout.rs
index cf8631a4..3932f115 100644
--- a/src/garage/cli/layout.rs
+++ b/src/garage/cli/layout.rs
@@ -1,8 +1,8 @@
use bytesize::ByteSize;
+use format_table::format_table;
use garage_util::crdt::Crdt;
use garage_util::error::*;
-use garage_util::formater::format_table;
use garage_rpc::layout::*;
use garage_rpc::system::*;
diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs
index d87f9eab..2232d395 100644
--- a/src/garage/cli/util.rs
+++ b/src/garage/cli/util.rs
@@ -1,11 +1,11 @@
use std::collections::HashMap;
use std::time::Duration;
+use format_table::format_table;
use garage_util::background::*;
use garage_util::crdt::*;
use garage_util::data::*;
use garage_util::error::*;
-use garage_util::formater::format_table;
use garage_util::time::*;
use garage_block::manager::BlockResyncErrorInfo;
@@ -383,13 +383,18 @@ pub fn print_block_error_list(el: Vec<BlockResyncErrorInfo>) {
let mut table = vec!["Hash\tRC\tErrors\tLast error\tNext try".into()];
for e in el {
+ let next_try = if e.next_try > now {
+ tf2.convert(Duration::from_millis(e.next_try - now))
+ } else {
+ "asap".to_string()
+ };
table.push(format!(
"{}\t{}\t{}\t{}\tin {}",
hex::encode(e.hash.as_slice()),
e.refcount,
e.error_count,
tf.convert(Duration::from_millis(now - e.last_try)),
- tf2.convert(Duration::from_millis(e.next_try - now))
+ next_try
));
}
format_table(table);
diff --git a/src/garage/tests/common/custom_requester.rs b/src/garage/tests/common/custom_requester.rs
index 609eda97..4133bb8b 100644
--- a/src/garage/tests/common/custom_requester.rs
+++ b/src/garage/tests/common/custom_requester.rs
@@ -209,6 +209,7 @@ impl<'a> RequestBuilder<'a> {
all_headers.extend(self.unsigned_headers.clone());
let canonical_request = signature::payload::canonical_request(
+ self.service,
&self.method,
&Uri::try_from(&uri).unwrap(),
&all_headers,
diff --git a/src/garage/tests/common/mod.rs b/src/garage/tests/common/mod.rs
index eca3e42b..0b8c6755 100644
--- a/src/garage/tests/common/mod.rs
+++ b/src/garage/tests/common/mod.rs
@@ -1,5 +1,6 @@
use aws_sdk_s3::{Client, Region};
use ext::*;
+use k2v_client::K2vClient;
#[macro_use]
pub mod macros;
@@ -68,6 +69,19 @@ impl Context {
bucket_name
}
+
+ /// Build a K2vClient for a given bucket
+ pub fn k2v_client(&self, bucket: &str) -> K2vClient {
+ let config = k2v_client::K2vClientConfig {
+ region: REGION.to_string(),
+ endpoint: self.garage.k2v_uri().to_string(),
+ aws_access_key_id: self.key.id.clone(),
+ aws_secret_access_key: self.key.secret.clone(),
+ bucket: bucket.to_string(),
+ user_agent: None,
+ };
+ K2vClient::new(config).expect("Could not create K2V client")
+ }
}
pub fn context() -> Context {
diff --git a/src/garage/tests/k2v_client/mod.rs b/src/garage/tests/k2v_client/mod.rs
new file mode 100644
index 00000000..b252f36b
--- /dev/null
+++ b/src/garage/tests/k2v_client/mod.rs
@@ -0,0 +1 @@
+pub mod simple;
diff --git a/src/garage/tests/k2v_client/simple.rs b/src/garage/tests/k2v_client/simple.rs
new file mode 100644
index 00000000..1a3118ef
--- /dev/null
+++ b/src/garage/tests/k2v_client/simple.rs
@@ -0,0 +1,60 @@
+use std::time::Duration;
+
+use k2v_client::*;
+
+use crate::common;
+
+#[tokio::test]
+async fn test_simple() {
+ let ctx = common::context();
+ let bucket = ctx.create_bucket("test-k2v-client-simple");
+ let k2v_client = ctx.k2v_client(&bucket);
+
+ k2v_client
+ .insert_item("root", "test1", b"Hello, world!".to_vec(), None)
+ .await
+ .unwrap();
+
+ let res = k2v_client.read_item("root", "test1").await.unwrap();
+
+ assert_eq!(res.value.len(), 1);
+ assert_eq!(res.value[0], K2vValue::Value(b"Hello, world!".to_vec()));
+}
+
+#[tokio::test]
+async fn test_special_chars() {
+ let ctx = common::context();
+ let bucket = ctx.create_bucket("test-k2v-client-simple-special-chars");
+ let k2v_client = ctx.k2v_client(&bucket);
+
+ let (pk, sk) = ("root@plépp", "≤≤««");
+ k2v_client
+ .insert_item(pk, sk, b"Hello, world!".to_vec(), None)
+ .await
+ .unwrap();
+
+ let res = k2v_client.read_item(pk, sk).await.unwrap();
+ assert_eq!(res.value.len(), 1);
+ assert_eq!(res.value[0], K2vValue::Value(b"Hello, world!".to_vec()));
+
+ // sleep a bit before read_index
+ tokio::time::sleep(Duration::from_secs(1)).await;
+ let res = k2v_client.read_index(Default::default()).await.unwrap();
+ assert_eq!(res.items.len(), 1);
+ assert_eq!(res.items.keys().next().unwrap(), pk);
+
+ let res = k2v_client
+ .read_batch(&[BatchReadOp {
+ partition_key: pk,
+ filter: Default::default(),
+ single_item: false,
+ conflicts_only: false,
+ tombstones: false,
+ }])
+ .await
+ .unwrap();
+ assert_eq!(res.len(), 1);
+ let res = &res[0];
+ assert_eq!(res.items.len(), 1);
+ assert_eq!(res.items.keys().next().unwrap(), sk);
+}
diff --git a/src/garage/tests/lib.rs b/src/garage/tests/lib.rs
index 87be1327..e450baac 100644
--- a/src/garage/tests/lib.rs
+++ b/src/garage/tests/lib.rs
@@ -8,3 +8,5 @@ mod s3;
#[cfg(feature = "k2v")]
mod k2v;
+#[cfg(feature = "k2v")]
+mod k2v_client;