more strictness; cargo fmt+clippy
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Alex 2022-04-22 18:05:42 +02:00
parent 140994c830
commit ae0e6c6d27
Signed by: lx
GPG key ID: 0E496D15096376BE
3 changed files with 48 additions and 35 deletions

View file

@ -126,7 +126,8 @@ response = requests.post('http://localhost:3812/alex?search',
{"partitionKey": "root"},
{"partitionKey": "root", "tombstones": true},
{"partitionKey": "root", "tombstones": true, "limit": 2},
{"partitionKey": "root", "start": "c", "singleItem": true}
{"partitionKey": "root", "start": "c", "singleItem": true},
{"partitionKey": "root", "start": "b", "end": "d", "tombstones": true}
]
''')
print(response.headers)

View file

@ -6,6 +6,8 @@ use serde::{Deserialize, Serialize};
use garage_util::data::*;
use garage_util::error::Error as GarageError;
use garage_table::TableSchema;
use garage_model::garage::Garage;
use garage_model::k2v::causality::*;
use garage_model::k2v::item_table::*;
@ -55,8 +57,10 @@ pub async fn handle_read_batch(
serde_json::from_slice(&body).ok_or_bad_request("Invalid JSON")?;
let resp_results = futures::future::join_all(
queries.into_iter()
.map(|q| handle_read_batch_query(&garage, bucket_id, q)))
queries
.into_iter()
.map(|q| handle_read_batch_query(&garage, bucket_id, q)),
)
.await;
let mut resps: Vec<ReadBatchResponse> = vec![];
@ -86,15 +90,20 @@ async fn handle_read_batch_query(
};
let (items, more, next_start) = if query.single_item {
let sk = query.start.as_ref()
if query.prefix.is_some() || query.end.is_some() || query.limit.is_some() {
return Err(Error::BadRequest("Batch query parameters 'prefix', 'end' and 'limit' must not be set when singleItem is true.".into()));
}
let sk = query
.start
.as_ref()
.ok_or_bad_request("start should be specified if single_item is set")?;
let item = garage
.k2v_item_table
.get(&partition, sk)
.await?;
.await?
.filter(|e| K2VItemTable::matches_filter(e, &filter));
match item {
Some(i) => (vec![ReadBatchResponseItem::from(i)],
false, None),
Some(i) => (vec![ReadBatchResponseItem::from(i)], false, None),
None => (vec![], false, None),
}
} else {
@ -105,11 +114,13 @@ async fn handle_read_batch_query(
&query.start,
&query.end,
query.limit,
Some(filter)
).await?;
Some(filter),
)
.await?;
let items = items.into_iter()
.map(|i| ReadBatchResponseItem::from(i))
let items = items
.into_iter()
.map(ReadBatchResponseItem::from)
.collect::<Vec<_>>();
(items, more, next_start)
@ -188,7 +199,8 @@ struct ReadBatchResponseItem {
impl ReadBatchResponseItem {
fn from(i: K2VItem) -> Self {
let ct = i.causality_context().serialize();
let v = i.values()
let v = i
.values()
.iter()
.map(|v| match v {
DvvsValue::Value(x) => Some(base64::encode(x)),

View file

@ -2,10 +2,10 @@ use garage_util::data::*;
use crate::index_counter::*;
pub const ENTRIES: &'static str = "entries";
pub const CONFLICTS: &'static str = "conflicts";
pub const VALUES: &'static str = "values";
pub const BYTES: &'static str = "bytes";
pub const ENTRIES: &str = "entries";
pub const CONFLICTS: &str = "conflicts";
pub const VALUES: &str = "values";
pub const BYTES: &str = "bytes";
#[derive(PartialEq, Clone)]
pub struct K2VCounterTable;