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

.

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