Esempio n. 1
0
func NewClusterService(comm *comm.Comm, config gostore.Config, sconfig gostore.ConfigService) *ClusterService {
	cs := new(ClusterService)

	cs.sconfig = sconfig
	cs.config = config
	cs.comm = comm
	cs.cluster = comm.Cluster
	cs.clusterMutex = new(sync.Mutex)
	cs.serviceId = sconfig.Id

	cs.state = state_booting

	if path, ok := sconfig.CustomConfig["DataDir"].(string); ok {
		cs.dataDir = path
	} else {
		log.Fatal("CS: Config 'DataDir' must be specified")
	}
	cs.clsDataPath = fmt.Sprintf("%s/cluster.db", cs.dataDir)

	if masteRing, ok := sconfig.CustomConfig["MasterRing"].(float64); ok {
		cs.masterRing = byte(masteRing)
	} else {
		log.Fatal("CS: Config 'MasterRing' must be specified")
	}

	// peristence
	cs.commitlog = commitlog.New(cs.dataDir)
	cs.commitlog.RegisterMutation(&clusterMutation{cs, []*cluster.Node{}, 0, false})

	return cs
}
Esempio n. 2
0
func Init() {
	if cl == nil {
		os.RemoveAll("_test/")
		cl = commitlog.New("_test/")

		cl.RegisterMutation(NewInt64Mutation(-1))
	}
}