enable single servers with cli/client

This commit is contained in:
Bel LaPointe
2019-04-23 18:55:48 -06:00
parent aa1fdd367d
commit f912272912
3 changed files with 37 additions and 23 deletions

View File

@@ -3,30 +3,24 @@ package main
import (
"bufio"
"fmt"
"local/args"
"log"
"os"
"strconv"
"strings"
)
func main() {
rConcernS, ok := os.LookupEnv("RCONCERN")
if !ok {
rConcernS = "1"
}
wConcernS, ok := os.LookupEnv("WCONCERN")
if !ok {
wConcernS = "1"
}
rConcern, err := strconv.Atoi(rConcernS)
if err != nil {
as := args.NewArgSet()
as.Append(args.STRING, "addr", "csv addr(s) of server(s)", "http://localhost:21412")
as.Append(args.INT, "r", "read concern", 1)
as.Append(args.INT, "w", "write concern", 1)
if err := as.Parse(); err != nil {
panic(err)
}
wConcern, err := strconv.Atoi(wConcernS)
if err != nil {
panic(err)
}
client, err := New(rConcern, wConcern, strings.Split(os.Getenv("ADDR"), ",")...)
rConcern := as.Get("r").GetInt()
wConcern := as.Get("w").GetInt()
addrs := as.Get("addr").GetString()
client, err := New(rConcern, wConcern, strings.Split(addrs, ",")...)
if err != nil {
panic(err)
}
@@ -48,6 +42,9 @@ func do(client *Client, line string) {
}
}()
switch strings.ToLower(strings.Split(line, " ")[0]) {
case "help":
log.Printf("get key1")
log.Printf("set key1 value value value...")
case "get":
get(client, line)
case "set":

View File

@@ -88,7 +88,13 @@ func New(rConcern, wConcern int, addrs ...string) (*Client, error) {
func (c *Client) scatterGather(key string, forEach func(addr string, each chan result), try, need int) ([]byte, error) {
final := make(chan result)
each := make(chan result)
members, err := c.hash.GetClosestN([]byte(key), try)
var members []consistent.Member
var err error
if try > 1 {
members, err = c.hash.GetClosestN([]byte(key), try)
} else {
members = append(members, c.hash.LocateKey([]byte(key)))
}
if err != nil {
return nil, err
}