nevermind on ns lookup, because thats just configsvr on mongo
parent
73423064a8
commit
aa1fdd367d
|
|
@ -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,12 +117,18 @@ 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 {
|
||||||
return consensus.b, consensus.err
|
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) {
|
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.
|
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
|
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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue