Skip to content

Commit

Permalink
fix: extra preflight check on write operations to ensure leadership
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Jul 29, 2023
1 parent cce00a5 commit eced44f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/raft/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ type raftStorage struct {

// Put sets the value of a key.
func (rs *raftStorage) Put(ctx context.Context, key, value string) error {
if !rs.raft.IsLeader() {
return ErrNotLeader
}
logEntry := &v1.RaftLogEntry{
Type: v1.RaftCommandType_PUT,
Key: key,
Expand All @@ -155,6 +158,9 @@ func (rs *raftStorage) Put(ctx context.Context, key, value string) error {

// Delete removes a key.
func (rs *raftStorage) Delete(ctx context.Context, key string) error {
if !rs.raft.IsLeader() {
return ErrNotLeader
}
logEntry := &v1.RaftLogEntry{
Type: v1.RaftCommandType_DELETE,
Key: key,
Expand Down

0 comments on commit eced44f

Please sign in to comment.