func (dcmd *delCommand) Apply(server raft.Server) (interface{}, error) { if server.Name() == server.Leader() { return nil, nil } kvs := server.Context().(KVstore) err := kvs.Delete(dcmd.Key) return nil, err }
// Apply implements goraft Command interface's Apply function // It puts a key-value pair in KVstore func (pcmd *putCommand) Apply(server raft.Server) (interface{}, error) { if server.Name() == server.Leader() { return nil, nil } kvs := server.Context().(KVstore) err := kvs.Put(pcmd.Key, pcmd.Val) 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 *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 }