Commit 08a54443 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 89309b93
......@@ -45,22 +45,28 @@ Run NEO master node.
}
func masterMain(argv []string) {
var bind string
var cluster string
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.Usage = func() { masterUsage(os.Stderr); flags.PrintDefaults() } // XXX prettify
flags.StringVar(&bind, "bind", bind, "address to serve on")
flags.StringVar(&cluster, "cluster", cluster, "cluster name")
cluster := flags.String("cluster", "", "cluster name")
// XXX masters here too?
bind := flags.String("bind", "", "address to serve on")
flags.Parse(argv[1:])
if *cluster == "" {
// XXX vvv -> die or log.Fatalf ?
log.Fatal(os.Stderr, "cluster name must be provided")
os.Exit(2)
}
argv = flags.Args()
if len(argv) < 1 {
flags.Usage()
os.Exit(2)
}
masterSrv := server.NewMaster(cluster)
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
masterSrv := server.NewMaster(*cluster, *bind, net)
ctx := context.Background()
/*
......@@ -71,8 +77,7 @@ func masterMain(argv []string) {
}()
*/
net := neo.NetPlain("tcp") // TODO + TLS; not only "tcp" ?
err := server.ListenAndServe(ctx, net, bind, masterSrv)
err := masterSrv.Run(ctx)
if err != nil {
log.Fatal(err)
}
......
......@@ -34,9 +34,6 @@ import (
const storageSummary = "run storage node"
// TODO options:
// cluster, masterv ...
func storageUsage(w io.Writer) {
fmt.Fprintf(w,
`Usage: neo storage [options] zstor XXX
......@@ -56,7 +53,7 @@ func storageMain(argv []string) {
if *cluster == "" {
// XXX vvv -> die or log.Fatalf ?
fmt.Fprintf(os.Stderr, "cluster name must be provided")
log.Fatal(os.Stderr, "cluster name must be provided")
os.Exit(2)
}
......
......@@ -73,12 +73,14 @@ type nodeLeave struct {
}
// NewMaster TODO ...
func NewMaster(clusterName string) *Master {
func NewMaster(clusterName, serveAddr string, net neo.Network) *Master {
// XXX serveAddr + net
m := &Master{clusterName: clusterName}
m.nodeUUID = m.allocUUID(neo.MASTER)
// TODO update nodeTab with self
m.clusterState = neo.ClusterRecovering // XXX no elections - we are the only master
go m.run(context.TODO()) // XXX ctx
// go m.run(context.TODO()) // XXX ctx
return m
}
......@@ -122,17 +124,18 @@ func (m *Master) setClusterState(state neo.ClusterState) {
}
// run is the process which implements main master cluster management logic: node tracking, cluster
// Run is the process which implements main master cluster management logic: node tracking, cluster
// state updates, scheduling data movement between storage nodes etc
func (m *Master) run(ctx context.Context) {
func (m *Master) Run(ctx context.Context) (err error) {
//defer xerr.Context(&err, "master: run")
// NOTE run's goroutine is the only mutator of nodeTab, partTab and other cluster state
// NOTE Run's goroutine is the only mutator of nodeTab, partTab and other cluster state
for ctx.Err() == nil {
err := m.recovery(ctx)
if err != nil {
fmt.Println(err)
return // recovery cancelled
return err // recovery cancelled
}
// successful recovery -> verify
......@@ -154,7 +157,7 @@ func (m *Master) run(ctx context.Context) {
// XXX shutdown ?
}
fmt.Printf("master: run: %v\n", ctx.Err())
return fmt.Errorf("master: run: %v\n", ctx.Err())
}
......
......@@ -78,6 +78,7 @@ func Serve(ctx context.Context, l net.Listener, srv Server) error {
}
}
/*
// ListenAndServe listens on network address and then calls Serve to handle incoming connections
// XXX unused -> goes away ?
func ListenAndServe(ctx context.Context, net neo.Network, laddr string, srv Server) error {
......@@ -88,6 +89,7 @@ func ListenAndServe(ctx context.Context, net neo.Network, laddr string, srv Serv
// TODO set keepalive on l
return Serve(ctx, l, srv)
}
*/
// ----------------------------------------
......
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