etcdserver: wip
parent
edac2e909b
commit
008337e150
|
@ -1,6 +1,8 @@
|
||||||
package etcdserver
|
package etcdserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
"code.google.com/p/go.net/context"
|
"code.google.com/p/go.net/context"
|
||||||
"github.com/coreos/etcd/raft"
|
"github.com/coreos/etcd/raft"
|
||||||
"github.com/coreos/etcd/wait"
|
"github.com/coreos/etcd/wait"
|
||||||
|
@ -13,22 +15,24 @@ type Response struct {
|
||||||
type Server struct {
|
type Server struct {
|
||||||
n raft.Node
|
n raft.Node
|
||||||
w wait.List
|
w wait.List
|
||||||
|
|
||||||
|
msgsc chan raft.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Run(ctx context.Context) {
|
func (s *Server) Run(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
st, ents, cents, msgs, err := s.n.ReadState(ctx)
|
st, ents, cents, msgs, err := s.n.ReadState(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
do something here
|
log.Println("etcdserver: error while reading state -", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
save state to wal
|
s.save(st, ents)
|
||||||
go send messages
|
s.send(msgs)
|
||||||
go func() {
|
go func() {
|
||||||
for e in cents {
|
for _, e := range cents {
|
||||||
req = decode e.Data
|
var r Request
|
||||||
apply req to state machine
|
r.Unmarshal(e.Data)
|
||||||
build Response from result of apply
|
s.w.Trigger(r.Id, s.apply(r))
|
||||||
trigger wait with (r.Id, resp)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -53,3 +57,25 @@ func (s *Server) Do(ctx context.Context, r Request) (Response, error) {
|
||||||
return Response{}, ctx.Err()
|
return Response{}, ctx.Err()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send sends dispatches msgs to the sending goroutine. If the goroutine is
|
||||||
|
// busy, it will drop msgs and clients should timeout and reissue.
|
||||||
|
// TODO: we could use s.w to trigger and error to cancel the clients faster???? Is this a good idea??
|
||||||
|
func (s *Server) send(msgs []raft.Message) {
|
||||||
|
for _, m := range msgs {
|
||||||
|
select {
|
||||||
|
case s.msgsc <- m:
|
||||||
|
default:
|
||||||
|
log.Println("TODO: log dropped message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) save(st raft.State, ents []raft.Entry) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// apply interprets r as a call to store.X and returns an Response interpreted from store.Event
|
||||||
|
func (s *Server) apply(r Request) Response {
|
||||||
|
panic("not implmented")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue