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 }
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 }
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 }
func (c *DeleteContinuousQueryCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.DeleteContinuousQuery(c.Database, c.Id) return nil, err }
func (c *SetContinuousQueryTimestampCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.SetContinuousQueryTimestamp(c.Timestamp) return nil, err }
func (c *UpdateShardSpaceCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.UpdateShardSpace(c.ShardSpace) return nil, err }
func (c *DropShardSpaceCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.RemoveShardSpace(c.Database, c.Name) return nil, err }
func (c *DropSeriesCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.DropSeries(c.Database, c.Series) return nil, err }
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 }
func (c *DropShardCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.DropShard(c.ShardId, c.ServerIds) return nil, err }
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 }
func (c *SaveClusterAdminCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) config.SaveClusterAdmin(c.User) return nil, nil }
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) }
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) }
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 }
func (c *CreateDatabaseCommand) Apply(server raft.Server) (interface{}, error) { config := server.Context().(*cluster.ClusterConfiguration) err := config.CreateDatabase(c.Name) return nil, err }