Skip to content

Commit

Permalink
Merge pull request #19 from volkangurel/json-case
Browse files Browse the repository at this point in the history
made config json keys lower camel case, fixed return format of config ge...
  • Loading branch information
jbooth committed Mar 6, 2015
2 parents 3ee9026 + 59dc381 commit 21e2cc4
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 24 deletions.
16 changes: 8 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
)

type ClusterConfig struct {
NumSlots uint32
Me Host // should match a host in one of our shards exactly to identify which peergroup we join
Shards []Shard
NumSlots uint32 `json:"numSlots"`
Me Host `json:"me"` // should match a host in one of our shards exactly to identify which peergroup we join
Shards []Shard `json:"shards"`
}

type Shard struct {
Slots []uint32
Hosts []Host
Slots []uint32 `json:"slots"`
Hosts []Host `json:"hosts"`
}

type Host struct {
RedisAddr string // "192.168.0.4:8369"
FlotillaAddr string // "192.168.0.4:1103"
Group string
RedisAddr string `json:"redisAddr"` // "192.168.0.4:8369"
FlotillaAddr string `json:"flotillaAddr"` // "192.168.0.4:1103"
Group string `json:"group"`
}

func WriteConfig(c *ClusterConfig, w io.Writer) error {
Expand Down
30 changes: 30 additions & 0 deletions raftis/local1.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"me": {
"flotillaAddr": "localhost:1103",
"group": "local1",
"redisAddr": "localhost:8369"
},
"shards": [
{
"hosts": [
{
"flotillaAddr": "localhost:1103",
"group": "local1",
"redisAddr": "localhost:8369"
},
{
"flotillaAddr": "localhost:1104",
"group": "local2",
"redisAddr": "localhost:8370"
},
{
"flotillaAddr": "localhost:1105",
"group": "local3",
"redisAddr": "localhost:8371"
}
],
"slots": [ 0 ]
}
],
"numSlots": 1
}
30 changes: 30 additions & 0 deletions raftis/local2.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"me": {
"flotillaAddr": "localhost:1104",
"group": "local2",
"redisAddr": "localhost:8370"
},
"shards": [
{
"hosts": [
{
"flotillaAddr": "localhost:1103",
"group": "local1",
"redisAddr": "localhost:8369"
},
{
"flotillaAddr": "localhost:1104",
"group": "local2",
"redisAddr": "localhost:8370"
},
{
"flotillaAddr": "localhost:1105",
"group": "local3",
"redisAddr": "localhost:8371"
}
],
"slots": [ 0 ]
}
],
"numSlots": 1
}
30 changes: 30 additions & 0 deletions raftis/local3.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"me": {
"flotillaAddr": "localhost:1105",
"group": "local3",
"redisAddr": "localhost:8371"
},
"shards": [
{
"hosts": [
{
"flotillaAddr": "localhost:1103",
"group": "local1",
"redisAddr": "localhost:8369"
},
{
"flotillaAddr": "localhost:1104",
"group": "local2",
"redisAddr": "localhost:8370"
},
{
"flotillaAddr": "localhost:1105",
"group": "local3",
"redisAddr": "localhost:8371"
}
],
"slots": [ 0 ]
}
],
"numSlots": 1
}
8 changes: 3 additions & 5 deletions raftis/runcluster2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ function startraftis() {
rm -rf $dir
mkdir -p $dir

port=`expr $1 \\* 10 + 16369`
iport=`expr $1 + 11102`
echo starting raftis on port $port, iport $iport
raftis -r 127.0.0.1:$port -i 127.0.0.1:$iport -d $dir -p 127.0.0.1:11103,127.0.0.1:11104,127.0.0.1:11105 >$dir/out.log 2>&1 &
echo starting raftis $1
raftis -config local$1.cfg -d $dir >$dir/out.log 2>&1 &
pid=$!
echo $pid > $dir/pid
echo "launched server$1, pid $pid"
Expand Down Expand Up @@ -45,4 +43,4 @@ stop)
*)
echo "$0 {start|stop}"
;;
esac
esac
33 changes: 22 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package raftis

import (
"fmt"
"bytes"
"bytes"
"strings"
"github.com/jbooth/flotilla"
mdb "github.com/jbooth/gomdb"
ops "github.com/jbooth/raftis/ops"
redis "github.com/jbooth/raftis/redis"
log "github.com/jbooth/raftis/rlog"
config "github.com/jbooth/raftis/config"
config "github.com/jbooth/raftis/config"
"io"
"net"
"os"
Expand Down Expand Up @@ -151,7 +152,7 @@ func (s *Server) Serve() (err error) {
s.redis.Close()
s.flotilla.Close()
s.lg.Printf("server on %s going down: %s", s.redis.Addr().String(), err)
return
return
}(s)
for {
c, err := s.redis.AcceptTCP()
Expand All @@ -167,14 +168,24 @@ func (s *Server) Serve() (err error) {
var get []byte = []byte("GET")
func (s *Server) doRequest(c Conn, r *redis.Request) io.WriterTo {

if r.Name == "CONFIG" &&
bytes.Equal(r.Args[0], []byte("GET")) &&
bytes.Equal(r.Args[1], []byte("cluster")) {

var buf bytes.Buffer
config.WriteConfig(s.cluster.c, &buf)
return &redis.BulkReply{buf.Bytes()}
}
if r.Name == "CONFIG" &&
len(r.Args) > 0 &&
strings.ToUpper(string(r.Args[0])) == "GET" {
var resp redis.ReplyWriter
if len(r.Args) == 1 {
resp = redis.NewError("ERR Wrong number of arguments for CONFIG GET")
} else {
ret := make([][]byte, 0)
if bytes.Equal(r.Args[1], []byte("cluster")) {
var buf bytes.Buffer
config.WriteConfig(s.cluster.c, &buf)
ret = append(ret, []byte("cluster"))
ret = append(ret, buf.Bytes())
}
resp = &redis.ArrayReply{ret}
}
return resp
}

if len(r.Args) > 0 {
//hasKey, err := s.cluster.HasKey(r.Args[0])
Expand Down

0 comments on commit 21e2cc4

Please sign in to comment.