HBASE-21634: Print error message when user uses unacceptable values for LIMIT while setting quotas.
Signed-off-by: Guanghao Zhang <zghao@apache.org>
This commit is contained in:
parent
dc50b570c6
commit
1e91ae8f9e
|
@ -45,6 +45,7 @@ module HBaseQuotasConstants
|
||||||
end
|
end
|
||||||
|
|
||||||
module Hbase
|
module Hbase
|
||||||
|
# rubocop:disable Metrics/ClassLength
|
||||||
class QuotasAdmin
|
class QuotasAdmin
|
||||||
def initialize(admin)
|
def initialize(admin)
|
||||||
@admin = admin
|
@admin = admin
|
||||||
|
@ -117,6 +118,8 @@ module Hbase
|
||||||
@admin.setQuota(settings)
|
@admin.setQuota(settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
||||||
|
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
|
||||||
def limit_space(args)
|
def limit_space(args)
|
||||||
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
|
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
|
||||||
# Let the user provide a raw number
|
# Let the user provide a raw number
|
||||||
|
@ -126,6 +129,10 @@ module Hbase
|
||||||
# Parse a string a 1K, 2G, etc.
|
# Parse a string a 1K, 2G, etc.
|
||||||
_parse_size(args[LIMIT])
|
_parse_size(args[LIMIT])
|
||||||
end
|
end
|
||||||
|
if limit <= 0
|
||||||
|
raise(ArgumentError, 'Invalid space limit, must be greater than 0')
|
||||||
|
end
|
||||||
|
|
||||||
# Extract the policy, failing if something bogus was provided
|
# Extract the policy, failing if something bogus was provided
|
||||||
policy = SpaceViolationPolicy.valueOf(args[POLICY])
|
policy = SpaceViolationPolicy.valueOf(args[POLICY])
|
||||||
# Create a table or namespace quota
|
# Create a table or namespace quota
|
||||||
|
@ -145,6 +152,8 @@ module Hbase
|
||||||
# Apply the quota
|
# Apply the quota
|
||||||
@admin.setQuota(settings)
|
@admin.setQuota(settings)
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
||||||
|
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
|
||||||
|
|
||||||
def remove_space_limit(args)
|
def remove_space_limit(args)
|
||||||
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
|
raise(ArgumentError, 'Argument should be a Hash') unless !args.nil? && args.is_a?(Hash)
|
||||||
|
@ -253,7 +262,7 @@ module Hbase
|
||||||
|
|
||||||
def _parse_size(str_limit)
|
def _parse_size(str_limit)
|
||||||
str_limit = str_limit.downcase
|
str_limit = str_limit.downcase
|
||||||
match = /(\d+)([bkmgtp%]*)/.match(str_limit)
|
match = /^(\d+)([bkmgtp%]?)$/.match(str_limit)
|
||||||
if match
|
if match
|
||||||
if match[2] == '%'
|
if match[2] == '%'
|
||||||
return match[1].to_i
|
return match[1].to_i
|
||||||
|
@ -265,23 +274,23 @@ module Hbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
||||||
def _parse_limit(str_limit, type_cls, type)
|
def _parse_limit(str_limit, type_cls, type)
|
||||||
str_limit = str_limit.downcase
|
str_limit = str_limit.downcase
|
||||||
match = /(\d+)(req|cu|[bkmgtp])\/(sec|min|hour|day)/.match(str_limit)
|
match = /^(\d+)(req|cu|[bkmgtp])\/(sec|min|hour|day)$/.match(str_limit)
|
||||||
if match
|
if match
|
||||||
if match[2] == 'req'
|
|
||||||
limit = match[1].to_i
|
limit = match[1].to_i
|
||||||
|
if match[2] == 'req'
|
||||||
type = type_cls.valueOf(type + '_NUMBER')
|
type = type_cls.valueOf(type + '_NUMBER')
|
||||||
elsif match[2] == 'cu'
|
elsif match[2] == 'cu'
|
||||||
limit = match[1].to_i
|
|
||||||
type = type_cls.valueOf(type + '_CAPACITY_UNIT')
|
type = type_cls.valueOf(type + '_CAPACITY_UNIT')
|
||||||
else
|
else
|
||||||
limit = _size_from_str(match[1].to_i, match[2])
|
limit = _size_from_str(limit, match[2])
|
||||||
type = type_cls.valueOf(type + '_SIZE')
|
type = type_cls.valueOf(type + '_SIZE')
|
||||||
end
|
end
|
||||||
|
|
||||||
if limit <= 0
|
if limit <= 0
|
||||||
raise(ArgumentError, 'Invalid throttle limit, must be greater then 0')
|
raise(ArgumentError, 'Invalid throttle limit, must be greater than 0')
|
||||||
end
|
end
|
||||||
|
|
||||||
case match[3]
|
case match[3]
|
||||||
|
@ -296,6 +305,7 @@ module Hbase
|
||||||
raise(ArgumentError, 'Invalid throttle limit syntax')
|
raise(ArgumentError, 'Invalid throttle limit syntax')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
||||||
|
|
||||||
def _size_from_str(value, suffix)
|
def _size_from_str(value, suffix)
|
||||||
case suffix
|
case suffix
|
||||||
|
@ -308,4 +318,5 @@ module Hbase
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/ClassLength
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,7 @@ require 'hbase/table'
|
||||||
include HBaseConstants
|
include HBaseConstants
|
||||||
|
|
||||||
module Hbase
|
module Hbase
|
||||||
|
# rubocop:disable Metrics/ClassLength
|
||||||
class SpaceQuotasTest < Test::Unit::TestCase
|
class SpaceQuotasTest < Test::Unit::TestCase
|
||||||
include TestHelpers
|
include TestHelpers
|
||||||
|
|
||||||
|
@ -60,11 +61,91 @@ module Hbase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
define_test 'set quota with a non-numeric limit fails' do
|
# rubocop:disable Metrics/BlockLength
|
||||||
|
define_test 'set quota with an invalid limit fails' do
|
||||||
|
# Space Quota
|
||||||
assert_raise(ArgumentError) do
|
assert_raise(ArgumentError) do
|
||||||
command(:set_quota, TYPE => SPACE, LIMIT => 'asdf', POLICY => NO_INSERTS, TABLE => @test_name)
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => 'asdf',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => '1.3G',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => 'G1G',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => '1GG',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => '1H',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => SPACE,
|
||||||
|
LIMIT => '0G',
|
||||||
|
POLICY => NO_INSERTS,
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Throttle Quota
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => 'asdf',
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => '1.3G/hour',
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => 'G1G/hour',
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => '1GG/hour',
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => '1H/hour',
|
||||||
|
TABLE => @test_name)
|
||||||
|
end
|
||||||
|
assert_raise(ArgumentError) do
|
||||||
|
command(:set_quota,
|
||||||
|
TYPE => THROTTLE,
|
||||||
|
LIMIT => '0G/hour',
|
||||||
|
TABLE => @test_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/BlockLength
|
||||||
|
|
||||||
define_test 'set quota without a limit fails' do
|
define_test 'set quota without a limit fails' do
|
||||||
assert_raise(ArgumentError) do
|
assert_raise(ArgumentError) do
|
||||||
|
@ -171,4 +252,5 @@ module Hbase
|
||||||
assert(output.include?('Previous rpc throttle state : false'))
|
assert(output.include?('Previous rpc throttle state : false'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/ClassLength
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue