コード例 #1
0
ファイル: commands.go プロジェクト: lilwulin/raftkv
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
}
コード例 #2
0
ファイル: commands.go プロジェクト: lilwulin/raftkv
// 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
}
コード例 #3
0
ファイル: command.go プロジェクト: hanshenu/influxdb
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
}
コード例 #4
0
ファイル: command.go プロジェクト: hanshenu/influxdb
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)
}
コード例 #5
0
ファイル: command.go プロジェクト: hanshenu/influxdb
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)
}
コード例 #6
0
ファイル: command.go プロジェクト: hanshenu/influxdb
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
}