Exemple #1
0
func (c *CreateShardsCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	createdShards, err := config.AddShards(c.Shards)
	if err != nil {
		return nil, err
	}
	createdShardData := make([]*cluster.NewShardData, 0)
	for _, s := range createdShards {
		createdShardData = append(createdShardData, s.ToNewShardData())
	}
	return createdShardData, nil
}
Exemple #2
0
func (c *InfluxJoinCommand) Apply(server raft.Server) (interface{}, error) {
	err := server.AddPeer(c.Name, c.ConnectionString)
	if err != nil {
		return nil, err
	}

	clusterConfig := server.Context().(*cluster.ClusterConfiguration)

	newServer := clusterConfig.GetServerByRaftName(c.Name)
	// it's a new server the cluster has never seen, make it a potential
	if newServer != nil {
		return nil, fmt.Errorf("Server %s already exist", c.Name)
	}

	log.Info("Adding new server to the cluster config %s", c.Name)
	clusterServer := cluster.NewClusterServer(c.Name,
		c.ConnectionString,
		c.ProtobufConnectionString,
		nil,
		clusterConfig.GetLocalConfiguration())
	clusterConfig.AddPotentialServer(clusterServer)
	return nil, nil
}
Exemple #3
0
func (c *InfluxForceLeaveCommand) Apply(server raft.Server) (interface{}, error) {
	clusterConfig := server.Context().(*cluster.ClusterConfiguration)
	s := clusterConfig.GetServerById(&c.Id)

	if s == nil {
		return nil, nil
	}

	if err := server.RemovePeer(s.RaftName); err != nil {
		log.Warn("Cannot remove peer: %s", err)
	}

	if err := clusterConfig.RemoveServer(s); err != nil {
		log.Warn("Cannot remove peer from cluster config: %s", err)
	}
	server.FlushCommitIndex()
	return nil, nil
}
Exemple #4
0
func (c *DeleteContinuousQueryCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.DeleteContinuousQuery(c.Database, c.Id)
	return nil, err
}
Exemple #5
0
func (c *SetContinuousQueryTimestampCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.SetContinuousQueryTimestamp(c.Timestamp)
	return nil, err
}
Exemple #6
0
func (c *DropShardSpaceCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.RemoveShardSpace(c.Database, c.Name)
	return nil, err
}
Exemple #7
0
func (c *CreateShardSpaceCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.AddShardSpace(c.ShardSpace)
	return nil, err
}
Exemple #8
0
func (c *DropSeriesCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.DropSeries(c.Database, c.Series)
	return nil, err
}
Exemple #9
0
func (c *CreateSeriesFieldIdsCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.MetaStore.GetOrSetFieldIds(c.Database, c.Series)
	return c.Series, err
}
Exemple #10
0
func (c *DropShardCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.DropShard(c.ShardId, c.ServerIds)
	return nil, err
}
Exemple #11
0
func (c *InfluxChangeConnectionStringCommand) Apply(server raft.Server) (interface{}, error) {
	if c.Name == server.Name() {
		return nil, nil
	}

	server.RemovePeer(c.Name)
	server.AddPeer(c.Name, c.ConnectionString)

	clusterConfig := server.Context().(*cluster.ClusterConfiguration)

	newServer := clusterConfig.GetServerByRaftName(c.Name)
	// it's a new server the cluster has never seen, make it a potential
	if newServer == nil {
		return nil, fmt.Errorf("Server %s doesn't exist", c.Name)
	}

	newServer.RaftConnectionString = c.ConnectionString
	newServer.ProtobufConnectionString = c.ProtobufConnectionString
	server.Context().(*cluster.ClusterConfiguration).ChangeProtobufConnectionString(newServer)
	server.FlushCommitIndex()
	return nil, nil
}
Exemple #12
0
func (c *SaveClusterAdminCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	config.SaveClusterAdmin(c.User)
	return nil, nil
}
Exemple #13
0
func (c *ChangeDbUserPermissions) Apply(server raft.Server) (interface{}, error) {
	log.Debug("(raft:%s) changing db user permissions for %s:%s", server.Name(), c.Database, c.Username)
	config := server.Context().(*cluster.ClusterConfiguration)
	return nil, config.ChangeDbUserPermissions(c.Database, c.Username, c.ReadPermissions, c.WritePermissions)
}
Exemple #14
0
func (c *ChangeDbUserPassword) Apply(server raft.Server) (interface{}, error) {
	log.Debug("(raft:%s) changing db user password for %s:%s", server.Name(), c.Database, c.Username)
	config := server.Context().(*cluster.ClusterConfiguration)
	return nil, config.ChangeDbUserPassword(c.Database, c.Username, c.Hash)
}
Exemple #15
0
func (c *SaveDbUserCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	config.SaveDbUser(c.User)
	log.Debug("(raft:%s) Created user %s:%s", server.Name(), c.User.Db, c.User.Name)
	return nil, nil
}
Exemple #16
0
func (c *CreateDatabaseCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.CreateDatabase(c.Name)
	return nil, err
}