|
@@ -18,7 +18,7 @@ use crate::common::{
|
|
|
use crate::snapshot_holder::SnapshotHolder;
|
|
use crate::snapshot_holder::SnapshotHolder;
|
|
|
|
|
|
|
|
pub struct KVServer {
|
|
pub struct KVServer {
|
|
|
- me: AtomicUsize,
|
|
|
|
|
|
|
+ me: usize,
|
|
|
state: Mutex<KVServerState>,
|
|
state: Mutex<KVServerState>,
|
|
|
rf: Raft<UniqueKVOp>,
|
|
rf: Raft<UniqueKVOp>,
|
|
|
keep_running: AtomicBool,
|
|
keep_running: AtomicBool,
|
|
@@ -107,7 +107,7 @@ impl KVServer {
|
|
|
let snapshot_holder = Arc::new(SnapshotHolder::default());
|
|
let snapshot_holder = Arc::new(SnapshotHolder::default());
|
|
|
let snapshot_holder_clone = snapshot_holder.clone();
|
|
let snapshot_holder_clone = snapshot_holder.clone();
|
|
|
let ret = Arc::new(Self {
|
|
let ret = Arc::new(Self {
|
|
|
- me: AtomicUsize::new(me),
|
|
|
|
|
|
|
+ me,
|
|
|
state: Default::default(),
|
|
state: Default::default(),
|
|
|
rf: Raft::new(
|
|
rf: Raft::new(
|
|
|
servers,
|
|
servers,
|
|
@@ -177,7 +177,7 @@ impl KVServer {
|
|
|
// This KV server might not be the same leader that committed the
|
|
// This KV server might not be the same leader that committed the
|
|
|
// query. We are not sure if it is a duplicate or a conflict. To
|
|
// query. We are not sure if it is a duplicate or a conflict. To
|
|
|
// tell the difference, terms of all queries must be stored.
|
|
// tell the difference, terms of all queries must be stored.
|
|
|
- *result_holder.result.lock() = if leader == self.me() {
|
|
|
|
|
|
|
+ *result_holder.result.lock() = if leader == self.me {
|
|
|
Ok(result)
|
|
Ok(result)
|
|
|
} else {
|
|
} else {
|
|
|
Err(CommitError::NotMe(result))
|
|
Err(CommitError::NotMe(result))
|
|
@@ -204,7 +204,7 @@ impl KVServer {
|
|
|
) {
|
|
) {
|
|
|
let this = Arc::downgrade(self);
|
|
let this = Arc::downgrade(self);
|
|
|
let logger = LocalLogger::inherit();
|
|
let logger = LocalLogger::inherit();
|
|
|
- let me = self.me();
|
|
|
|
|
|
|
+ let me = self.me;
|
|
|
std::thread::spawn(move || {
|
|
std::thread::spawn(move || {
|
|
|
logger.attach();
|
|
logger.attach();
|
|
|
log::info!("KVServer {} waiting for commands ...", me);
|
|
log::info!("KVServer {} waiting for commands ...", me);
|
|
@@ -304,7 +304,7 @@ impl KVServer {
|
|
|
if start {
|
|
if start {
|
|
|
let op = UniqueKVOp {
|
|
let op = UniqueKVOp {
|
|
|
op,
|
|
op,
|
|
|
- me: self.me(),
|
|
|
|
|
|
|
+ me: self.me,
|
|
|
unique_id,
|
|
unique_id,
|
|
|
};
|
|
};
|
|
|
let start = self.rf.start(op);
|
|
let start = self.rf.start(op);
|
|
@@ -422,10 +422,6 @@ impl KVServer {
|
|
|
PutAppendReply { result }
|
|
PutAppendReply { result }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn me(&self) -> usize {
|
|
|
|
|
- self.me.load(Ordering::Relaxed)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
pub fn raft(&self) -> &Raft<UniqueKVOp> {
|
|
pub fn raft(&self) -> &Raft<UniqueKVOp> {
|
|
|
&self.rf
|
|
&self.rf
|
|
|
}
|
|
}
|