func initAction(cmd *cobra.Command, args []string) { var err error md := torus.GlobalMetadata{} md.BlockSize = blockSize md.DefaultBlockSpec, err = blockset.ParseBlockLayerSpec(blockSpec) if err != nil { die("error parsing block-spec: %v", err) } cfg := flagconfig.BuildConfigFromFlags() ringType := ring.Ketama if noMakeRing { ringType = ring.Empty } err = torus.InitMDS("etcd", cfg, md, ringType) if err != nil { die("error writing metadata: %v", err) } }
func initAction(cmd *cobra.Command, args []string) { var err error md := torus.GlobalMetadata{} md.BlockSize = blockSize md.DefaultBlockSpec, err = blockset.ParseBlockLayerSpec(blockSpec) md.INodeReplication = inodeReplication if err != nil { die("error parsing block-spec: %v", err) } cfg := torus.Config{ MetadataAddress: etcdAddress, } ringType := ring.Ketama if noMakeRing { ringType = ring.Empty } err = torus.InitMDS("etcd", cfg, md, ringType) if err != nil { die("error writing metadata: %v", err) } }
func runServer(cmd *cobra.Command, args []string) { if completion { cmd.Root().GenBashCompletion(os.Stdout) os.Exit(0) } var ( srv *torus.Server err error ) switch { case cfg.MetadataAddress == "": srv, err = torus.NewServer(cfg, "temp", "mfile") case debugInit: err = torus.InitMDS("etcd", cfg, torus.GlobalMetadata{ BlockSize: 512 * 1024, DefaultBlockSpec: blockset.MustParseBlockLayerSpec("crc,base"), }, ring.Ketama) if err != nil { if err == torus.ErrExists { fmt.Println("debug-init: Already exists") } else { fmt.Printf("Couldn't debug-init: %s\n", err) os.Exit(1) } } fallthrough default: srv, err = torus.NewServer(cfg, "etcd", "mfile") } if err != nil { fmt.Printf("Couldn't start: %s\n", err) os.Exit(1) } if autojoin { err = doAutojoin(srv) if err != nil { fmt.Printf("Couldn't auto-join: %s\n", err) os.Exit(1) } } mainClose := make(chan bool) signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, os.Interrupt) if peerAddress != "" { var u *url.URL u, err = url.Parse(peerAddress) if err != nil { fmt.Printf("Couldn't parse peer address %s: %s\n", peerAddress, err) os.Exit(1) } if u.Scheme == "" { fmt.Printf("Peer address %s does not have URL scheme (http:// or tdp://)\n", peerAddress) os.Exit(1) } err = distributor.ListenReplication(srv, u) } else { err = distributor.OpenReplication(srv) } defer srv.Close() go func() { for _ = range signalChan { fmt.Println("\nReceived an interrupt, stopping services...") close(mainClose) os.Exit(0) } }() if err != nil { fmt.Println("couldn't use server:", err) os.Exit(1) } if httpAddress != "" { http.ServeHTTP(httpAddress, srv) } // Wait <-mainClose }