예제 #1
0
파일: raftX.go 프로젝트: izouxv/raftX
func main() {
	go func() {
		//http://localhost:6060/debug/pprof/
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()

	log.SetFlags(0)
	flag.Parse()
	if verbose {
		log.Print("Verbose logging enabled.")
	}
	if trace {
		raft.SetLogLevel(raft.Trace)
		log.Print("Raft trace debugging enabled.")
	} else if debug {
		raft.SetLogLevel(raft.Debug)
		log.Print("Raft debugging enabled.")
	}

	rand.Seed(time.Now().UnixNano())

	// Setup commands.
	raft.RegisterCommand(&command.SetCommand{})
	raft.RegisterCommand(&command.RemoveTmpDataCommand{})

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}
	path := flag.Arg(0)
	if err := os.MkdirAll(path, 0744); err != nil {
		log.Fatalf("Unable to create path: %v", err)
	}

	//	log.Fatalf("join: %v", join)
	//	log.Fatalf(" path: %v", path)

	log.SetFlags(log.LstdFlags)
	s := server.New(path, host, port)

	if true {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}
	addr := fmt.Sprintf("%s:%d", host, tcpSerPort)

	//log.Fatal(s.ListenAndServe(join, addr))
	s.ListenAndServe(join, addr)
	select {}
}
예제 #2
0
파일: raftX_test.go 프로젝트: izouxv/raftX
func startSer() {

	// Setup commands.
	raft.RegisterCommand(&command.SetCommand{})
	raft.RegisterCommand(&command.RemoveTmpDataCommand{})

	path := kPath
	if err := os.MkdirAll(path, 0744); err != nil {
		log.Fatalf("Unable to create path: %v", err)
	}

	log.SetFlags(log.LstdFlags)
	s := server.New(path, host, port)

	addr := fmt.Sprintf("%s:%d", host, tcpSerPort)

	s.ListenAndServe(join, addr)
}