Browse Source

Retry on time out error as well.

Jing Yang 4 năm trước cách đây
mục cha
commit
8da548536f
1 tập tin đã thay đổi với 11 bổ sung8 xóa
  1. 11 8
      kvraft/src/common.rs

+ 11 - 8
kvraft/src/common.rs

@@ -103,20 +103,23 @@ pub trait ValidReply {
     fn is_reply_valid(&self) -> bool;
 }
 
+impl<T> ValidReply for Result<T, KVError> {
+    fn is_reply_valid(&self) -> bool {
+        return match self.as_ref().err() {
+            Some(KVError::TimedOut) | Some(KVError::NotLeader) => false,
+            _ => true,
+        };
+    }
+}
+
 impl ValidReply for PutAppendReply {
     fn is_reply_valid(&self) -> bool {
-        if let Err(KVError::NotLeader) = &self.result {
-            return false;
-        }
-        return true;
+        self.result.is_reply_valid()
     }
 }
 
 impl ValidReply for GetReply {
     fn is_reply_valid(&self) -> bool {
-        if let Err(KVError::NotLeader) = &self.result {
-            return false;
-        }
-        return true;
+        self.result.is_reply_valid()
     }
 }