nevermind on ns lookup, because thats just configsvr on mongo

master
Bel LaPointe 2019-04-23 14:41:38 -06:00
parent 73423064a8
commit aa1fdd367d
2 changed files with 22 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import (
"net" "net"
"net/http" "net/http"
"strings" "strings"
"time"
"github.com/buraksezer/consistent" "github.com/buraksezer/consistent"
"github.com/cespare/xxhash" "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) out := make(map[string]int)
done := false done := false
for i := 0; i < len(members); i++ { 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 { if done {
continue continue
} }
@ -111,13 +117,19 @@ func (c *Client) scatterGather(key string, forEach func(addr string, each chan r
done = true done = true
} }
} }
close(each)
if !done { if !done {
final <- result{err: errors.New("no consensus")} final <- result{err: errors.New("no consensus")}
} }
close(final)
}() }()
consensus := <-final select {
case <-time.After(time.Second * 10):
return nil, errors.New("timeout on consensus")
case consensus := <-final:
return consensus.b, consensus.err return consensus.b, consensus.err
} }
}
func (c *Client) Get(key string) ([]byte, error) { func (c *Client) Get(key string) ([]byte, error) {
return c.scatterGather(key, func(addr string, each chan result) { return c.scatterGather(key, func(addr string, each chan result) {

View File

@ -3,7 +3,7 @@ end:1 key -> client
client:1 key -> 1+ partitionID client:1 key -> 1+ partitionID
client:1 partitionID -> serverAddr client:1 partitionID -> serverAddr
client:partition,key,serverAddr -> server client:partition,key,serverAddr -> server
server:partition,key -> value x server:partition,key -> value
1+ server:value -> client 1+ server:value -> client
client:1+ value -> 1 end:value client:1+ value -> 1 end:value