From aa1fdd367d4269a8e1dd128f1beaf8877a9f5ae0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Tue, 23 Apr 2019 14:41:38 -0600 Subject: [PATCH] nevermind on ns lookup, because thats just configsvr on mongo --- client/client.go | 18 +++++++++++++++--- notes/consistent_and_namespaces | 14 +++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/client.go b/client/client.go index 5997a6d..461e1ee 100644 --- a/client/client.go +++ b/client/client.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "strings" + "time" "github.com/buraksezer/consistent" "github.com/cespare/xxhash" @@ -98,7 +99,12 @@ func (c *Client) scatterGather(key string, forEach func(addr string, each chan r out := make(map[string]int) done := false for i := 0; i < len(members); i++ { - one := <-each + var one result + select { + case <-time.After(time.Second * 10): + continue + case one = <-each: + } if done { continue } @@ -111,12 +117,18 @@ func (c *Client) scatterGather(key string, forEach func(addr string, each chan r done = true } } + close(each) if !done { final <- result{err: errors.New("no consensus")} } + close(final) }() - consensus := <-final - return consensus.b, consensus.err + select { + case <-time.After(time.Second * 10): + return nil, errors.New("timeout on consensus") + case consensus := <-final: + return consensus.b, consensus.err + } } func (c *Client) Get(key string) ([]byte, error) { diff --git a/notes/consistent_and_namespaces b/notes/consistent_and_namespaces index 478afe7..05c8dbb 100644 --- a/notes/consistent_and_namespaces +++ b/notes/consistent_and_namespaces @@ -1,9 +1,9 @@ a key goes to a consistent hash to determine a partition id. Look up the addr which holds that partition ID. -end:1 key -> client -client:1 key -> 1+ partitionID -client:1 partitionID -> serverAddr -client:partition,key,serverAddr -> server -server:partition,key -> value -1+ server:value -> client -client:1+ value -> 1 end:value + end:1 key -> client + client:1 key -> 1+ partitionID + client:1 partitionID -> serverAddr + client:partition,key,serverAddr -> server +x server:partition,key -> value + 1+ server:value -> client + client:1+ value -> 1 end:value