func (s *RaftServer) Set(cmd *entity.Command, resp *raftrpc.ClientResponse) error {
	countlog.Info("Set", "cmd", cmd)
	if cmd == nil {
		resp.Errcode = errno.MissingParam
		resp.Errmsg = "EmptyCommand"
		countlog.Error("EmptyCommand")
		return nil
	}
	if s.ServerConf.Info.Role != core.RoleLeader {
		resp.ServerAddr = s.ServerConf.Info.ServerAddr
		resp.Errcode = errno.NotLeader
		return nil
	}
	switch cmd.CommandType {
	case entity.CmdSet:
		val, err := s.ReplicateLog(cmd)
		if err != nil {
			countlog.Error("DBSet -> ReplicateLog failed", "key", cmd.Key, "error", err)
			resp.Errmsg = err.Error()
			resp.Errcode = errno.ReplicateLogFail
			return nil
		}
		resp.Errcode = errno.Success
		resp.Data = val
	default:
		resp.Errcode = errno.ValueNotAccepcted
		countlog.Error(fmt.Sprintf("UnkownCommandType(%d)", cmd.CommandType))
	}
	return nil
}
// Set handles client set command
Set handles client set command
// Set handles client set command
func (s *RaftServer) Set(cmd *entity.Command, resp *raftrpc.ClientResponse) error {
	countlog.Info("Set", "cmd", cmd)
	if cmd == nil {
		resp.Errcode = errno.MissingParam
		resp.Errmsg = "EmptyCommand"
		countlog.Error("EmptyCommand")
		return nil
	}
	if s.ServerConf.Info.Role != core.RoleLeader {
		resp.ServerAddr = s.ServerConf.Info.ServerAddr
		resp.Errcode = errno.NotLeader
		return nil
	}
	switch cmd.CommandType {
	case entity.CmdSet:
		val, err := s.ReplicateLog(cmd)
		if err != nil {
			countlog.Error("DBSet -> ReplicateLog failed", "key", cmd.Key, "error", err)
			resp.Errmsg = err.Error()
			resp.Errcode = errno.ReplicateLogFail
			return nil
		}
		resp.Errcode = errno.Success
		resp.Data = val
	default:
		resp.Errcode = errno.ValueNotAccepcted
		countlog.Error(fmt.Sprintf("UnkownCommandType(%d)", cmd.CommandType))
	}
	return nil
}
func ( s * RaftServer ) Set ( cmd * entity . Command , resp * raftrpc . ClientResponse ) error { countlog . Info ( " " , " " , cmd ) if cmd == nil { resp . Errcode = errno . MissingParam resp . Errmsg = " " countlog . Error ( " " ) return nil } if s . ServerConf . Info . Role != core . RoleLeader { resp . ServerAddr = s . ServerConf . Info . ServerAddr resp . Errcode = errno . NotLeader return nil } switch cmd . CommandType { case entity . CmdSet : val , err := s . ReplicateLog ( cmd ) if err != nil { countlog . Error ( " " , " " , cmd . Key , " " , err ) resp . Errmsg = err . Error ( ) resp . Errcode = errno . ReplicateLogFail return nil } resp . Errcode = errno . Success resp . Data = val default : resp . Errcode = errno . ValueNotAccepcted countlog . Error ( fmt . Sprintf ( " " , cmd . CommandType ) ) } return nil }
Set handles client set command
Set handles client set command