Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 5
0
func (c *SetContinuousQueryTimestampCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.SetContinuousQueryTimestamp(c.Timestamp)
	return nil, err
}
Exemplo n.º 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
}
Exemplo n.º 7
0
func (c *CreateShardSpaceCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.AddShardSpace(c.ShardSpace)
	return nil, err
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 12
0
func (c *SaveClusterAdminCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	config.SaveClusterAdmin(c.User)
	return nil, nil
}
Exemplo n.º 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)
}
Exemplo n.º 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)
}
Exemplo n.º 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
}
Exemplo n.º 16
0
func (c *CreateDatabaseCommand) Apply(server raft.Server) (interface{}, error) {
	config := server.Context().(*cluster.ClusterConfiguration)
	err := config.CreateDatabase(c.Name)
	return nil, err
}