Esempio n. 1
0
func NewServer(config *configuration.Configuration) (*Server, error) {
	log.Info("Opening database at %s", config.DataDir)
	metaStore := metastore.NewStore()
	shardDb, err := datastore.NewShardDatastore(config, metaStore)
	if err != nil {
		return nil, err
	}

	newClient := func(connectString string) cluster.ServerConnection {
		return coordinator.NewProtobufClient(connectString, config.ProtobufTimeout.Duration)
	}
	writeLog, err := wal.NewWAL(config)
	if err != nil {
		return nil, err
	}

	clusterConfig := cluster.NewClusterConfiguration(config, writeLog, shardDb, newClient, metaStore)
	raftServer := coordinator.NewRaftServer(config, clusterConfig)
	metaStore.SetClusterConsensus(raftServer)
	clusterConfig.LocalRaftName = raftServer.GetRaftName()
	clusterConfig.SetShardCreator(raftServer)

	coord := coordinator.NewCoordinator(config, raftServer, clusterConfig)
	requestHandler := coordinator.NewProtobufRequestHandler(coord, clusterConfig)
	protobufServer := coordinator.NewProtobufServer(config.ProtobufListenString(), requestHandler)

	raftServer.AssignCoordinator(coord)
	httpApi := http.NewHttpServer(config, coord, coord, clusterConfig, raftServer)
	httpApi.EnableSsl(config.ApiHttpSslPortString(), config.ApiHttpCertPath)
	graphiteApi := graphite.NewServer(config, coord, clusterConfig)
	collectdApi := collectd.NewServer(config, coord, clusterConfig)
	adminServer := admin.NewHttpServer(config.AdminHttpPortString())

	return &Server{
		RaftServer:     raftServer,
		ProtobufServer: protobufServer,
		ClusterConfig:  clusterConfig,
		HttpApi:        httpApi,
		GraphiteApi:    graphiteApi,
		CollectdApi:    collectdApi,
		Coordinator:    coord,
		AdminServer:    adminServer,
		Config:         config,
		RequestHandler: requestHandler,
		writeLog:       writeLog,
		shardStore:     shardDb}, nil
}
Esempio n. 2
0
func (self *ShardDatastoreSuite) TestGetOrCreateShardDeletesFilesOnError(c *C) {
	// Register our mockDB so that ShardData will create & use it instead
	// of a real one (i.e., leveldb, rocksdb, etc.).
	err := storage.RegisterEngine("mockdb", storage.Initializer{NewMockDBConfig, NewMockDB})
	c.Assert(err, IsNil)

	config := &configuration.Configuration{
		DataDir:              TEST_DATASTORE_SHARD_DIR,
		StorageMaxOpenShards: 100,
		StorageDefaultEngine: "mockdb",
	}

	sd, err := NewShardDatastore(config, metastore.NewStore())
	c.Assert(err, IsNil)

	s, err := sd.GetOrCreateShard(999)
	c.Assert(err, NotNil)
	c.Assert(s, IsNil)
	_, err = os.Stat(path.Join(TEST_DATASTORE_SHARD_DIR, "shard_db_v2/00999"))
	c.Assert(os.IsNotExist(err), Equals, true)
}
// wrote this test while tracking down https://github.com/Wikia/influxdb/issues/886
func (self *ClusterConfigurationSuite) TestSerializesShardSpaces(c *C) {
	config := &configuration.Configuration{}
	store := metastore.NewStore()
	clusterConfig := NewClusterConfiguration(config, nil, nil, nil, store)
	clusterConfig.CreateDatabase("db1")
	space1 := NewShardSpace("db1", "space1")
	space1.Regex = "/space1/"
	space1.ReplicationFactor = 2
	space1.Split = 2
	err := clusterConfig.AddShardSpace(space1)
	c.Assert(err, IsNil)
	space2 := NewShardSpace("db1", "space2")
	space2.Regex = "/space2/"
	err = clusterConfig.AddShardSpace(space2)
	c.Assert(err, IsNil)

	verify := func(conf *ClusterConfiguration) {
		spaces := conf.databaseShardSpaces["db1"]
		c.Assert(spaces, HasLen, 2)
		space2 := spaces[0]
		space1 := spaces[1]
		c.Assert(space1.Name, Equals, "space1")
		c.Assert(space1.Regex, Equals, "/space1/")
		c.Assert(space1.ReplicationFactor, Equals, uint32(2))
		c.Assert(space1.Split, Equals, uint32(2))
		c.Assert(space2.Name, Equals, "space2")
		c.Assert(space2.Regex, Equals, "/space2/")
	}

	verify(clusterConfig)

	bytes, err := clusterConfig.Save()
	c.Assert(err, IsNil)
	newConfig := NewClusterConfiguration(config, nil, nil, nil, store)
	err = newConfig.Recovery(bytes)
	c.Assert(err, IsNil)
	verify(newConfig)
	verify(clusterConfig)
}