Skip to content

HBASE-28754 verify the first argument passed to compaction_switch #6119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hbase-shell/src/main/ruby/hbase/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def compact(table_or_region_name, family = nil, type = 'NORMAL')
#----------------------------------------------------------------------------------------------
# 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?
Expand Down
8 changes: 8 additions & 0 deletions hbase-shell/src/test/ruby/hbase/admin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ def teardown
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
Expand Down
6 changes: 6 additions & 0 deletions hbase-shell/src/test/ruby/shell/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def setup
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

##
Expand Down