This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.5 by this push:
new b1d20d535c7 HBASE-28754 verify the first argument passed to
compaction_switch (#6119)
b1d20d535c7 is described below
commit b1d20d535c75738f208a9d9a90f67e4c741a37c4
Author: ether1984 <[email protected]>
AuthorDate: Wed Mar 26 22:36:28 2025 +0800
HBASE-28754 verify the first argument passed to compaction_switch (#6119)
Co-authored-by: wangjue <[email protected]>
Signed-off-by: Duo Zhang <[email protected]>
Reviewed-by: guluo <[email protected]>
Reviewed-by: Chandra Sekhar K <[email protected]>
(cherry picked from commit b625bda1b2a7035e7626189392bcaaf02bd8832d)
---
hbase-shell/src/main/ruby/hbase/admin.rb | 3 +++
hbase-shell/src/test/ruby/hbase/admin_test.rb | 8 ++++++++
hbase-shell/src/test/ruby/shell/commands_test.rb | 6 ++++++
3 files changed, 17 insertions(+)
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb
b/hbase-shell/src/main/ruby/hbase/admin.rb
index 405e900b7ba..9a2721edc71 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -101,6 +101,9 @@ module Hbase
#----------------------------------------------------------------------------------------------
# Switch compaction on/off at runtime on a region server
def compaction_switch(on_or_off, regionserver_names)
+ unless /true|false/i.match(on_or_off.to_s)
+ raise ArgumentError, 'compaction_switch first argument only accepts
"true" or "false"'
+ end
region_servers = regionserver_names.flatten.compact
servers = java.util.ArrayList.new
if region_servers.any?
diff --git a/hbase-shell/src/test/ruby/hbase/admin_test.rb
b/hbase-shell/src/test/ruby/hbase/admin_test.rb
index e84ffd6385a..4188f3e70f6 100644
--- a/hbase-shell/src/test/ruby/hbase/admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/admin_test.rb
@@ -140,6 +140,14 @@ module Hbase
command(:compaction_state, 'hbase:meta')
end
+
#-------------------------------------------------------------------------------
+ define_test "compaction_switch should work" do
+ output = capture_stdout { command(:compaction_switch, false) }
+ assert(output.include?('PREV_STATE'))
+ output = capture_stdout { command(:compaction_switch, 'true') }
+ assert(output.include?('PREV_STATE'))
+ end
+
#-------------------------------------------------------------------------------
define_test "major_compact should work" do
diff --git a/hbase-shell/src/test/ruby/shell/commands_test.rb
b/hbase-shell/src/test/ruby/shell/commands_test.rb
index c97931ff20f..3acd885115e 100644
--- a/hbase-shell/src/test/ruby/shell/commands_test.rb
+++ b/hbase-shell/src/test/ruby/shell/commands_test.rb
@@ -69,6 +69,12 @@ class ShellCommandsErrorTest < Test::Unit::TestCase
output = capture_stdout { @shell.command(name) }
assert_match(/For usage try 'help "#{name}"'/, output)
end
+
+ define_test 'Erroneous first argument for compaction_switch should indicate
correct usage' do
+ name = :compaction_switch
+ output = capture_stdout { @shell.command(name, 'test') }
+ assert_match(/compaction_switch first argument only accepts "true" or
"false"/, output)
+ end
end
##