Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func main() {
client, _ := mokv.NewClient("localhost:8400")
client, _ := mokv.NewClient("addr")
defer client.Close()

ctx := context.Background()
Expand Down
7 changes: 4 additions & 3 deletions discovery/picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ func (p *Picker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
}

methodName := info.FullMethodName
isWrite := strings.Contains(methodName, "Set") ||
strings.Contains(methodName, "Delete")

// No available connections
if p.leader == nil && len(p.followers) == 0 {
Expand All @@ -78,10 +76,13 @@ func (p *Picker) Pick(info balancer.PickInfo) (balancer.PickResult, error) {
return result, balancer.ErrNoSubConnAvailable
}

isWrite := strings.Contains(methodName, "Set") ||
strings.Contains(methodName, "Delete")

// Write operations must go to leader
if isWrite {
if p.leader == nil {
log.Debug().
log.Warn().
Str("method", methodName).
Msg("pick failed: write operation but no leader")
return result, balancer.ErrNoSubConnAvailable
Expand Down