Commit 8700e53e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b55e94bf
......@@ -75,23 +75,29 @@ var _ zodb.IStorageDriver = (*Client)(nil)
//
// It will connect to master @masterAddr and identify with specified cluster name.
func NewClient(clusterName, masterAddr string, net xnet.Networker) *Client {
cli := &Client{
cli := newClient(clusterName, masterAddr, net)
go cli.run(context.Background()) // XXX bg hardcoded
return cli
}
func newClient(clusterName, masterAddr string, net xnet.Networker) *Client {
return &Client{
node: NewNodeApp(net, proto.CLIENT, clusterName, masterAddr, ""),
mlinkReady: make(chan struct{}),
operational: false,
opReady: make(chan struct{}),
}
}
// spawn background process which performs master talk
ctx, cancel := context.WithCancel(context.Background()) // XXX bg hardcoded
// XXX make run public?
func (cli *Client) run(ctx context.Context) error {
// run process which performs master talk
ctx, cancel := context.WithCancel(ctx)
cli.talkMasterCancel = cancel
cli.node.OnShutdown = cancel // XXX ok?
go cli.talkMaster(ctx)
return cli
return cli.talkMaster(ctx)
}
func (c *Client) Close() error {
c.talkMasterCancel()
// XXX wait talkMaster finishes
......
......@@ -468,16 +468,20 @@ func TestMasterStorage(t *testing.T) {
rt.BranchNode("m", cM)
rt.BranchNode("s", cS)
//rt.BranchNode("c", cC) XXX - no
rt.BranchLink("s-m", cSM, cMS)
rt.BranchLink("c-m", cCM, cMC)
// cluster nodes
M := NewMaster("abc1", ":1", Mhost)
zstor := xfs1stor("../zodb/storage/fs1/testdata/1.fs")
S := NewStorage("abc1", "m:1", ":1", Shost, zstor)
C := newClient("abc1", "m:1", Chost)
// let tracer know how to map state addresses to node names
tracer.RegisterNode(M.node, "m") // XXX better Mhost.Name() ?
tracer.RegisterNode(S.node, "s")
tracer.RegisterNode(C.node, "c")
......@@ -617,12 +621,15 @@ func TestMasterStorage(t *testing.T) {
// ----------------------------------------
// XXX try creating client from the beginning
return // XXX temp
// XXX try starting client from the beginning
// create client
C := NewClient("abc1", "m:1", Chost)
tracer.RegisterNode(C.node, "c")
// start client
Cctx, Ccancel := context.WithCancel(bg)
gox(gwg, func() {
err := C.run(Cctx)
fmt.Println("C err: ", err)
exc.Raiseif(err)
})
// trace
......@@ -692,6 +699,7 @@ func TestMasterStorage(t *testing.T) {
_ = Mcancel
_ = Scancel
_ = Ccancel
return
}
......
// Copyright (C) 2016-2017 Nexedi SA and Contributors.
// Copyright (C) 2016-2018 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment