Commit 96580b58 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b211c7b2
......@@ -81,7 +81,7 @@ func WhenDone(ctx context.Context, f func()) func() {
// WithCloseOnErrCancel closes c on ctx cancel while f is run, or if f returns with an error.
//
// It is usually handy to propagate cancellation to interrupt IO.
// It is usually handy to propagate cancellation to interrupt IO. XXX when f creates/leaves link alive.
// XXX naming?
// XXX don't close on f return?
func WithCloseOnErrCancel(ctx context.Context, c io.Closer, f func() error) (err error) {
......@@ -92,7 +92,7 @@ func WithCloseOnErrCancel(ctx context.Context, c io.Closer, f func() error) (err
if err != nil {
if !closed {
c.Close()
c.Close() // XXX log err?
}
}
}()
......@@ -107,7 +107,7 @@ func WithCloseOnErrCancel(ctx context.Context, c io.Closer, f func() error) (err
select {
case <-ctx.Done():
c.Close() // interrupt IO
c.Close() // interrupt IO XXX log err?
closed = true
return ctx.Err()
......
......@@ -28,6 +28,7 @@ import (
"os"
"lab.nexedi.com/kirr/go123/prog"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo"
)
......@@ -49,7 +50,7 @@ func masterMain(argv []string) {
flags.Usage = func() { masterUsage(os.Stderr); flags.PrintDefaults() }
netSetup := netFlags(flags)
cluster := flags.String("cluster", "", "cluster name")
// XXX masters here too?
// TODO masters here too (multiple masters) ?
bind := flags.String("bind", "", "address to serve on")
flags.Parse(argv[1:])
......@@ -64,17 +65,21 @@ func masterMain(argv []string) {
}
ctx := context.Background()
err := func() (err error) {
net, err := netSetup(ctx)
if err != nil {
return err
}
defer func() {
__ := net.Close()
err = xerr.First(err, __)
}()
net, err := netSetup(ctx)
if err != nil {
prog.Fatal(err)
}
defer net.Close() // XXX err
err = listenAndServe(ctx, net, *bind, func(ctx context.Context, l xnet.Listener) error {
master := neo.NewMaster(*cluster, net)
return master.Run(ctx, l)
})
return listenAndServe(ctx, net, *bind, func(ctx context.Context, l xnet.Listener) error {
master := neo.NewMaster(*cluster, net)
return master.Run(ctx, l)
})
}()
if err != nil {
prog.Fatal(err)
......
......@@ -30,6 +30,7 @@ import (
"strings"
"lab.nexedi.com/kirr/go123/prog"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo"
"lab.nexedi.com/kirr/neo/go/neo/storage"
......@@ -79,7 +80,7 @@ func storageMain(argv []string) {
prog.Fatal("master list must be provided")
}
if len(masterv) > 1 {
prog.Fatal("BUG neo/go POC currently supports only 1 master")
prog.Fatal("TODO neo/go POC currently supports only 1 master")
}
master := masterv[0]
......@@ -102,24 +103,27 @@ func storageMain(argv []string) {
runtime.GOMAXPROCS(maxprocs*8) // XXX *8 is enough?
ctx := context.Background()
back, err := storage.OpenBackend(ctx, argv[0])
if err != nil {
prog.Fatal(err)
}
net, err := netSetup(ctx)
if err != nil {
prog.Fatal(err)
}
defer net.Close() // XXX err
err = listenAndServe(ctx, net, *bind, func(ctx context.Context, l xnet.Listener) error {
stor := neo.NewStorage(*cluster, master, net, back)
return stor.Run(ctx, l)
})
// XXX back.Close here or in Storage?
err := func() (err error) {
back, err := storage.OpenBackend(ctx, argv[0])
if err != nil {
return err
}
// XXX back.Close here or in Storage?
net, err := netSetup(ctx)
if err != nil {
return err
}
defer func() {
__ := net.Close()
err = xerr.First(err, __)
}()
return listenAndServe(ctx, net, *bind, func(ctx context.Context, l xnet.Listener) error {
stor := neo.NewStorage(*cluster, master, net, back)
return stor.Run(ctx, l)
})
}()
if err != nil {
prog.Fatal(err)
......
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