Эх сурвалжийг харах

Add RPC args and replies.

Jing Yang 5 жил өмнө
parent
commit
a10c1015a9

+ 44 - 4
tests/kvraft/common.rs

@@ -1,8 +1,9 @@
-use super::rand::RngCore;
-pub use anyhow::Result;
+use rand::{thread_rng, RngCore};
 use std::sync::atomic::{AtomicU64, Ordering};
 
-#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
+#[derive(
+    Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize,
+)]
 struct UniqueId {
     clerk_id: u64,
     sequence_id: u64,
@@ -17,7 +18,7 @@ struct UniqueIdSequence {
 impl UniqueIdSequence {
     pub fn new() -> Self {
         Self {
-            clerk_id: rand::thread_rng().next_u64(),
+            clerk_id: thread_rng().next_u64(),
             sequence_id: AtomicU64::new(0),
         }
     }
@@ -37,3 +38,42 @@ impl UniqueIdSequence {
         }
     }
 }
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+enum PutAppendEnum {
+    Put,
+    Append,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+struct PutAppendArgs {
+    key: String,
+    value: String,
+    op: PutAppendEnum,
+
+    unique_id: UniqueId,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+enum KvError {
+    NoKey,
+    Other(String),
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+struct PutAppendReply {
+    result: Result<(), KvError>,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+struct GetArgs {
+    key: String,
+
+    unique_id: UniqueId,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize)]
+struct GetReply {
+    result: Result<String, KvError>,
+    is_retry: bool,
+}

+ 2 - 2
tests/kvraft/mod.rs

@@ -1,3 +1,3 @@
-extern crate rand;
-
+mod client;
 mod common;
+mod server;