Skip to content

Commit

Permalink
add lock operation
Browse files Browse the repository at this point in the history
  • Loading branch information
baotiao committed Sep 19, 2017
1 parent d99e115 commit daa4814
Show file tree
Hide file tree
Showing 43 changed files with 2,222 additions and 32,969 deletions.
6 changes: 5 additions & 1 deletion floyd/example/simple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CXXFLAGS+=-I../../.. \
-I$(PINK_INCLUDE_DIR) \
-I$(ROCKSDB_INCLUDE_DIR)

OBJECT = t t1 t2 t3 t4 t5 t6 t7 t8
OBJECT = t t1 t2 t3 t4 t5 t6 t7 t8 test_lock test_lock1
SRC_DIR = ./
THIRD_PATH = ../../third
OUTPUT = ./output
Expand Down Expand Up @@ -99,6 +99,10 @@ t7: t7.cc
$(CXX) $(CXXFLAGS) -o $@ $^ $(INCLUDE_PATH) $(LIB_PATH) $(LIBS)
t8: t8.cc
$(CXX) $(CXXFLAGS) -o $@ $^ $(INCLUDE_PATH) $(LIB_PATH) $(LIBS)
test_lock: test_lock.cc
$(CXX) $(CXXFLAGS) -o $@ $^ $(INCLUDE_PATH) $(LIB_PATH) $(LIBS)
test_lock1: test_lock1.cc
$(CXX) $(CXXFLAGS) -o $@ $^ $(INCLUDE_PATH) $(LIB_PATH) $(LIBS)
$(OBJS): %.o : %.cc
$(CXX) $(CXXFLAGS) -c $< -o $@ $(INCLUDE_PATH)

Expand Down
3 changes: 2 additions & 1 deletion floyd/include/floyd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class Floyd {
virtual ~Floyd();

virtual Status Write(const std::string& key, const std::string& value) = 0;
virtual Status DirtyWrite(const std::string& key, const std::string& value) = 0;
virtual Status Delete(const std::string& key) = 0;
virtual Status Read(const std::string& key, std::string* value) = 0;
virtual Status DirtyRead(const std::string& key, std::string* value) = 0;
virtual Status TryLock(const std::string& name, uint64_t* session) = 0;
virtual Status UnLock(const std::string& name, const uint64_t session) = 0;

// return true if leader has been elected
virtual bool GetLeader(std::string* ip_port) = 0;
Expand Down
37 changes: 25 additions & 12 deletions floyd/proto/floyd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ enum Type {
// User cmd
kRead = 0;
kWrite = 1;
kDirtyWrite = 2;
kDelete = 3;
kTryLock = 5;
kUnLock = 6;

// Raft RPC
kRequestVote = 8;
Expand All @@ -19,11 +20,14 @@ message Entry {
kRead = 0;
kWrite = 1;
kDelete = 2;
kTryLock= 4;
kUnLock = 5;
}
required uint64 term = 1;
required string key = 2;
optional bytes value = 3;
required OpType optype = 4;
optional uint64 session = 5;
}

message CmdRequest {
Expand All @@ -35,12 +39,6 @@ message CmdRequest {
}
optional Kv kv = 2;

message User {
required bytes ip = 1;
required int32 port = 2;
}
optional User user = 3;

message RequestVote {
required uint64 term = 1;
required bytes ip = 2;
Expand Down Expand Up @@ -68,6 +66,12 @@ message CmdRequest {
optional int32 port = 4;
}
optional ServerStatus server_status = 6;

message LockRequest {
required bytes name = 1;
optional uint64 session = 2;
}
optional LockRequest lock_request = 7;
}

enum StatusCode {
Expand All @@ -86,11 +90,6 @@ message CmdResponse {
}
optional Kv kv = 4;

message Kvs {
repeated Kv kv = 1;
}
optional Kvs kvs = 5;

message RequestVoteResponse {
required uint64 term = 1;
required bool vote_granted = 2;
Expand All @@ -117,4 +116,18 @@ message CmdResponse {
optional uint64 last_applied = 10;
}
optional ServerStatus server_status = 8;

message LockResponse {
required uint64 session = 1;
}
optional LockResponse lock_response = 9;
}

/*
* protos used in lock API
*/

message Lock {
required uint64 lease_end = 1;
required uint64 session = 2;
}
3 changes: 1 addition & 2 deletions floyd/proto/pr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -x

###################
# floyd.proto
Expand All @@ -7,6 +8,4 @@ FILE1="floyd"
for file in $FILE1 ; do
protoc -I=./ --cpp_out=./ ./$file.proto
cp $file.pb.h $file.pb.cc ../src
cp $file.pb.h $file.pb.cc ../tools/log_parse
mv $file.pb.h $file.pb.cc ../tools/floyd_upgrade
done
2,327 changes: 1,330 additions & 997 deletions floyd/src/floyd.pb.cc

Large diffs are not rendered by default.

Loading

0 comments on commit daa4814

Please sign in to comment.