aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-05-17 11:50:23 +0200
committerAlex Auvolat <alex@adnab.me>2022-05-17 11:50:23 +0200
commitc692f55d5ce2c3ed08db7fbc4844debcc0aeb134 (patch)
tree920712b4ccfa111f01c16e3314a872201ab04ccf
parent7b474855e3a8491fcdde69d12d3fbae27f520383 (diff)
downloadgarage-fix-k2v-305.tar.gz
garage-fix-k2v-305.zip
K2V: Fix `end` parameter and add tests (fix #305)fix-k2v-305
-rw-r--r--src/api/k2v/range.rs6
-rw-r--r--src/garage/tests/k2v/batch.rs89
2 files changed, 93 insertions, 2 deletions
diff --git a/src/api/k2v/range.rs b/src/api/k2v/range.rs
index cd019723..295c34aa 100644
--- a/src/api/k2v/range.rs
+++ b/src/api/k2v/range.rs
@@ -74,7 +74,11 @@ where
}
}
if let Some(e) = end {
- if entry.sort_key() == e {
+ let is_finished = match enumeration_order {
+ EnumerationOrder::Forward => entry.sort_key() >= e,
+ EnumerationOrder::Reverse => entry.sort_key() <= e,
+ };
+ if is_finished {
return Ok((entries, false, None));
}
}
diff --git a/src/garage/tests/k2v/batch.rs b/src/garage/tests/k2v/batch.rs
index 1182a298..acae1910 100644
--- a/src/garage/tests/k2v/batch.rs
+++ b/src/garage/tests/k2v/batch.rs
@@ -92,7 +92,9 @@ async fn test_batch() {
br#"[
{"partitionKey": "root"},
{"partitionKey": "root", "start": "c"},
+ {"partitionKey": "root", "start": "c", "end": "dynamite"},
{"partitionKey": "root", "start": "c", "reverse": true, "end": "a"},
+ {"partitionKey": "root", "start": "c", "reverse": true, "end": "azerty"},
{"partitionKey": "root", "limit": 1},
{"partitionKey": "root", "prefix": "d"}
]"#
@@ -151,6 +153,24 @@ async fn test_batch() {
"partitionKey": "root",
"prefix": null,
"start": "c",
+ "end": "dynamite",
+ "limit": null,
+ "reverse": false,
+ "conflictsOnly": false,
+ "tombstones": false,
+ "singleItem": false,
+ "items": [
+ {"sk": "c", "ct": ct.get("c").unwrap(), "v": [base64::encode(values.get("c").unwrap())]},
+ {"sk": "d.1", "ct": ct.get("d.1").unwrap(), "v": [base64::encode(values.get("d.1").unwrap())]},
+ {"sk": "d.2", "ct": ct.get("d.2").unwrap(), "v": [base64::encode(values.get("d.2").unwrap())]},
+ ],
+ "more": false,
+ "nextStart": null,
+ },
+ {
+ "partitionKey": "root",
+ "prefix": null,
+ "start": "c",
"end": "a",
"limit": null,
"reverse": true,
@@ -167,6 +187,23 @@ async fn test_batch() {
{
"partitionKey": "root",
"prefix": null,
+ "start": "c",
+ "end": "azerty",
+ "limit": null,
+ "reverse": true,
+ "conflictsOnly": false,
+ "tombstones": false,
+ "singleItem": false,
+ "items": [
+ {"sk": "c", "ct": ct.get("c").unwrap(), "v": [base64::encode(values.get("c").unwrap())]},
+ {"sk": "b", "ct": ct.get("b").unwrap(), "v": [base64::encode(values.get("b").unwrap())]},
+ ],
+ "more": false,
+ "nextStart": null,
+ },
+ {
+ "partitionKey": "root",
+ "prefix": null,
"start": null,
"end": null,
"limit": 1,
@@ -465,6 +502,34 @@ async fn test_batch() {
])
);
+ // update our known tombstones
+ for sk in ["a", "b", "d.1", "d.2"] {
+ let res = ctx
+ .k2v
+ .request
+ .builder(bucket.clone())
+ .path("root")
+ .query_param("sort_key", Some(sk))
+ .signed_header("accept", "application/octet-stream")
+ .send()
+ .await
+ .unwrap();
+ assert_eq!(res.status(), 204);
+ assert_eq!(
+ res.headers().get("content-type").unwrap().to_str().unwrap(),
+ "application/octet-stream"
+ );
+ ct.insert(
+ sk,
+ res.headers()
+ .get("x-garage-causality-token")
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .to_string(),
+ );
+ }
+
let res = ctx
.k2v
.request
@@ -473,7 +538,8 @@ async fn test_batch() {
.body(
br#"[
{"partitionKey": "root"},
- {"partitionKey": "root", "reverse": true}
+ {"partitionKey": "root", "reverse": true},
+ {"partitionKey": "root", "tombstones": true}
]"#
.to_vec(),
)
@@ -520,6 +586,27 @@ async fn test_batch() {
"more": false,
"nextStart": null,
},
+ {
+ "partitionKey": "root",
+ "prefix": null,
+ "start": null,
+ "end": null,
+ "limit": null,
+ "reverse": false,
+ "conflictsOnly": false,
+ "tombstones": true,
+ "singleItem": false,
+ "items": [
+ {"sk": "a", "ct": ct.get("a").unwrap(), "v": [null]},
+ {"sk": "b", "ct": ct.get("b").unwrap(), "v": [null]},
+ {"sk": "c", "ct": ct.get("c").unwrap(), "v": [base64::encode(values.get("c").unwrap()), base64::encode(values.get("c'").unwrap())]},
+ {"sk": "d.1", "ct": ct.get("d.1").unwrap(), "v": [null]},
+ {"sk": "d.2", "ct": ct.get("d.2").unwrap(), "v": [null]},
+ {"sk": "e", "ct": ct.get("e").unwrap(), "v": [base64::encode(values.get("e").unwrap())]},
+ ],
+ "more": false,
+ "nextStart": null,
+ },
])
);
}