Пример #1
0
func StartServer(servers []string, me int) *ShardMaster {
	gob.Register(Op{})
	sm := new(ShardMaster)

	path_parts := strings.Split(servers[me], "/")
	sm.db_path = db_path + path_parts[len(path_parts)-1]
	os.Remove(sm.db_path)
	sm.db = dbaccess.GetDatabase(sm.db_path)

	// Put my index
	sm.db.PutInt(METADATA, "me", me)
	sm.me = me

	// Enter peers
	sm.db.PutStringList(METADATA, "servers", servers)

	first_conf := new(Config)
	first_conf.Groups = map[int64][]string{}
	sm.DBPutConfig(0, first_conf)
	sm.db.PutInt(METADATA, "num_configs", 1)

	rpcs := rpc.NewServer()
	rpcs.Register(sm)

	sm.px = paxos.Make(servers, me, rpcs)
	FinishStartServer(sm, servers, me, rpcs)
	return sm
}
Пример #2
0
func StartServerFromDB(me string) *ShardMaster {
	gob.Register(Op{})
	sm := new(ShardMaster)
	path_parts := strings.Split(me, "/")
	sm.db_path = db_path + path_parts[len(path_parts)-1]
	sm.db = dbaccess.GetDatabase(sm.db_path)

	me_index, me_exists := sm.db.GetInt(METADATA, "me")
	if !me_exists {
		log.Fatal("couldn't find me, start from DB")
	}

	stored_servers, servers_exists := sm.db.GetStringList(METADATA, "servers")
	if !servers_exists {
		log.Fatal("couldn't find servers start from DB")
	}

	_, val_exists := sm.db.GetInt(METADATA, "num_configs")
	if !val_exists {
		log.Fatal("DB not consistent")
	}

	rpcs := rpc.NewServer()
	rpcs.Register(sm)

	sm.px = paxos.MakeFromDB(stored_servers[me_index], rpcs)

	FinishStartServer(sm, stored_servers, me_index, rpcs)
	return sm
}
Пример #3
0
func Make(peers []string, me int, rpcs *rpc.Server) *Paxos {
	px := &Paxos{}
	path_parts := strings.Split(peers[me], "/")
	px.db_path = db_path + path_parts[len(path_parts)-1]
	os.Remove(px.db_path)
	px.db = dbaccess.GetDatabase(px.db_path)
	px.FreshStart(peers, me)
	FinishMake(px, rpcs)
	return px
}
Пример #4
0
func MakeFromDB(me string, rpcs *rpc.Server) *Paxos {

	px := &Paxos{}
	path_parts := strings.Split(me, "/")
	px.db_path = db_path + path_parts[len(path_parts)-1]
	px.db = dbaccess.GetDatabase(px.db_path)

	did_restore := px.TryRestoreFromDisk()
	if !did_restore {
		log.Fatal("RESTORE FROM DB FAILED")
	}

	FinishMake(px, rpcs)
	return px
}