nevermind on ns lookup, because thats just configsvr on mongo
parent
73423064a8
commit
aa1fdd367d
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue