Skip to content

Commit f593c69

Browse files
committed
s/StoreValue/Value
1 parent 6aec007 commit f593c69

File tree

9 files changed

+26
-28
lines changed

9 files changed

+26
-28
lines changed

benches/sqrl_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn write_direct(c: &mut criterion::Criterion) {
99

1010
c.bench_with_input(BenchmarkId::new("write", "store"), &store, |b, s| {
1111
b.to_async(&rt).iter(|| async {
12-
s.set("key".to_string(), "value".to_string()).await.unwrap();
12+
s.set("key".to_string(), "value".into()).await.unwrap();
1313
})
1414
});
1515
}

src/bin/sqrl-client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clap::Parser;
22

33
use sqrl::action::Action;
44
use sqrl::client::{Client, RemoteNodeClient};
5-
use sqrl::StoreValue;
5+
use sqrl::Value;
66

77
#[derive(Debug, Parser)]
88
#[command(author, version, about, long_about = None)]
@@ -21,9 +21,7 @@ async fn main() -> anyhow::Result<()> {
2121

2222
match cli.subcmd {
2323
Action::Set { key, value } => {
24-
client
25-
.set(key, StoreValue(Some(value.into_bytes())))
26-
.await?;
24+
client.set(key, Value(Some(value.into_bytes()))).await?;
2725
}
2826
Action::Get { key } => {
2927
let response = client.get(key).await?;

src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use crate::proto::action_client::ActionClient;
66
use crate::proto::{Acknowledgement, GetResponse, RemoveRequest};
77
use crate::proto::{GetRequest, SetRequest};
88
pub use crate::replication::ReplicatedServer;
9-
use crate::store::StoreValue;
9+
use crate::store::Value;
1010
use crate::Result;
1111

1212
/// A client used for interacting with the [`KvStore`] via gRPC requests.
1313
#[tonic::async_trait]
1414
pub trait Client {
1515
async fn get(&mut self, key: String) -> anyhow::Result<Option<GetResponse>>;
1616

17-
async fn set(&mut self, key: String, value: StoreValue) -> anyhow::Result<Acknowledgement>;
17+
async fn set(&mut self, key: String, value: Value) -> anyhow::Result<Acknowledgement>;
1818

1919
async fn remove(&mut self, key: String) -> anyhow::Result<Acknowledgement>;
2020
}
@@ -46,7 +46,7 @@ impl RemoteNodeClient {
4646

4747
#[tonic::async_trait]
4848
impl Client for RemoteNodeClient {
49-
async fn set(&mut self, key: String, value: StoreValue) -> anyhow::Result<Acknowledgement> {
49+
async fn set(&mut self, key: String, value: Value) -> anyhow::Result<Acknowledgement> {
5050
let value = value.0.unwrap_or_default();
5151
let req = tonic::Request::new(SetRequest {
5252
key,

src/engine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::future::Future;
22

3-
use crate::{store::StoreValue, Result};
3+
use crate::{store::Value, Result};
44

55
/// Generic trait implementation for pluggable storage engines outside of the one
66
/// implemented by this crate.
@@ -12,7 +12,7 @@ use crate::{store::StoreValue, Result};
1212
///
1313
/// [`KvStore`]: crate::store::KvStore
1414
pub trait KvsEngine: Clone + Send + Sync + 'static {
15-
fn set(&self, key: String, value: StoreValue) -> impl Future<Output = Result<()>>;
16-
fn get(&self, key: String) -> impl Future<Output = Result<Option<StoreValue>>>;
15+
fn set(&self, key: String, value: Value) -> impl Future<Output = Result<()>>;
16+
fn get(&self, key: String) -> impl Future<Output = Result<Option<Value>>>;
1717
fn remove(&self, key: String) -> impl Future<Output = Result<()>>;
1818
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod store;
2727
pub use engine::KvsEngine;
2828
pub use error::Error as KvStoreError;
2929
pub use server::StandaloneServer;
30-
pub use store::{KvStore, StoreValue};
30+
pub use store::{KvStore, Value};
3131
pub mod action;
3232
pub mod client;
3333

src/replication/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tracing::{debug, info};
88
use crate::client::{Client, RemoteNodeClient};
99
use crate::proto::action_server::{Action, ActionServer};
1010
use crate::proto::{Acknowledgement, GetRequest, GetResponse, RemoveRequest, SetRequest};
11-
use crate::store::StoreValue;
11+
use crate::store::Value;
1212
use crate::{KvsEngine, StandaloneServer};
1313

1414
/// Wrapped implementation of a [`StandaloneServer`] with an awareness of multiple
@@ -68,7 +68,7 @@ impl Action for ReplicatedServer {
6868
let key = req.key.clone();
6969
let response = match self.server.store.get(key).await.unwrap() {
7070
Some(r) => r,
71-
None => StoreValue(None),
71+
None => Value(None),
7272
};
7373
Ok(tonic::Response::new(GetResponse { value: response.0 }))
7474
}
@@ -81,14 +81,14 @@ impl Action for ReplicatedServer {
8181
debug!("Setting value to local store");
8282
self.server
8383
.store
84-
.set(req.key.clone(), StoreValue(Some(req.value.clone())))
84+
.set(req.key.clone(), Value(Some(req.value.clone())))
8585
.await
8686
.unwrap();
8787

8888
debug!("Replicating to remote replicas");
8989
futures::stream::iter(self.remote_replicas.lock().await.iter_mut())
9090
.for_each(|r| async {
91-
r.set(req.key.clone(), StoreValue(Some(req.value.clone())))
91+
r.set(req.key.clone(), Value(Some(req.value.clone())))
9292
.await
9393
.unwrap();
9494
})

src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::proto::{
22
action_server::{Action, ActionServer},
33
Acknowledgement, GetRequest, GetResponse, RemoveRequest, SetRequest,
44
};
5-
use crate::store::StoreValue;
5+
use crate::store::Value;
66
use crate::KvStore;
77
use crate::KvsEngine;
88
use std::{net::SocketAddr, sync::Arc};
@@ -58,7 +58,7 @@ impl Action for StandaloneServer {
5858
) -> tonic::Result<tonic::Response<Acknowledgement>, tonic::Status> {
5959
let req = req.into_inner();
6060
self.store
61-
.set(req.key, StoreValue(Some(req.value)))
61+
.set(req.key, Value(Some(req.value)))
6262
.await
6363
.unwrap();
6464
Ok(tonic::Response::new(Acknowledgement { success: true }))

src/store.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub enum Operation {
2424
}
2525

2626
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
27-
pub struct StoreValue(pub Option<Vec<u8>>);
27+
pub struct Value(pub Option<Vec<u8>>);
2828

29-
impl From<&str> for StoreValue {
29+
impl From<&str> for Value {
3030
fn from(value: &str) -> Self {
31-
StoreValue(Some(value.into()))
31+
Value(Some(value.into()))
3232
}
3333
}
3434

35-
impl From<String> for StoreValue {
35+
impl From<String> for Value {
3636
fn from(value: String) -> Self {
37-
StoreValue(Some(value.into_bytes()))
37+
Value(Some(value.into_bytes()))
3838
}
3939
}
4040

@@ -92,7 +92,7 @@ struct LogEntry {
9292
/// the entry with the most recent timestamp wins.
9393
timestamp: i64,
9494
key: String,
95-
value: Option<StoreValue>,
95+
value: Option<Value>,
9696
}
9797

9898
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -118,7 +118,7 @@ struct StoreConfig {
118118

119119
impl KvsEngine for KvStore {
120120
/// Set the value of a key by inserting the value into the store for the given key.
121-
async fn set(&self, key: String, value: StoreValue) -> Result<()> {
121+
async fn set(&self, key: String, value: Value) -> Result<()> {
122122
debug!(key, "Setting key");
123123
let timestamp = chrono::Utc::now().timestamp();
124124
let entry = LogEntry {
@@ -165,7 +165,7 @@ impl KvsEngine for KvStore {
165165
///
166166
/// The timestamp is typically used with replication, as the value acts as
167167
/// a version number and conflict resolution mechanism.
168-
async fn get(&self, key: String) -> Result<Option<StoreValue>> {
168+
async fn get(&self, key: String) -> Result<Option<Value>> {
169169
debug!(key, "Getting key");
170170
match self.keydir.get(&key) {
171171
Some(entry) => {

tests/kv_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rand::Rng;
2-
use sqrl::{KvStore, KvsEngine, Result, StoreValue};
2+
use sqrl::{KvStore, KvsEngine, Result, Value};
33
use std::{collections::HashMap, sync::Arc};
44
use tempfile::TempDir;
55
use tokio::sync::Barrier;
@@ -161,7 +161,7 @@ async fn randomised_retrieval() -> Result<()> {
161161
let temp_dir = TempDir::new().expect("unable to create temporary working directory");
162162
let store = KvStore::open(temp_dir.path())?;
163163

164-
let mut value_tracker: HashMap<String, StoreValue> = HashMap::new();
164+
let mut value_tracker: HashMap<String, Value> = HashMap::new();
165165
let mut rng = rand::thread_rng();
166166
for i in 0..1000 {
167167
let key = format!("key{}", i);

0 commit comments

Comments
 (0)