From 78cd3327dd548ef81b7eff63067db84d4cc24d15 Mon Sep 17 00:00:00 2001 From: xuqinya Date: Thu, 24 Jan 2019 18:02:45 +0800 Subject: [PATCH] HBASE-21768 list_quota_table_sizes/list_quota_snapshots should print human readable values for size --- hbase-shell/src/main/ruby/hbase/quotas.rb | 16 ++++++++++++++++ .../ruby/shell/commands/list_quota_snapshots.rb | 4 ++-- .../ruby/shell/commands/list_quota_table_sizes.rb | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/quotas.rb b/hbase-shell/src/main/ruby/hbase/quotas.rb index 0534b7c..800bbb4 100644 --- a/hbase-shell/src/main/ruby/hbase/quotas.rb +++ b/hbase-shell/src/main/ruby/hbase/quotas.rb @@ -301,6 +301,22 @@ module Hbase end end # rubocop:enable Metrics/AbcSize, Metrics/MethodLength + + def size_to_str(value) + if (value >= (1 << 50)) + return (value / (1 << 50)).to_s << "P" + elsif(value >= (1 << 40)) + return (value / (1 << 40)).to_s << "T" + elsif (value >= (1 << 30)) + return (value / (1 << 30)).to_s << "G" + elsif (value >= (1 << 20)) + return (value / (1 << 20)).to_s << "M" + elsif (value >= (1 << 10)) + return (value / (1 << 10)).to_s << "K" + else + return value.to_s << "B" + end + end def _size_from_str(value, suffix) case suffix diff --git a/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb index 5cb01a9..b3d72a2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_quota_snapshots.rb @@ -55,8 +55,8 @@ EOF next unless accept? table_name, desired_table, desired_namespace status = snapshot.getQuotaStatus policy = get_policy(status) - formatter.row([table_name.to_s, snapshot.getUsage.to_s, snapshot.getLimit.to_s, - status.isInViolation.to_s, policy]) + formatter.row([table_name.to_s, quotas_admin.size_to_str(snapshot.getUsage()), + quotas_admin.size_to_str(snapshot.getLimit()), status.isInViolation.to_s, policy]) count += 1 end formatter.footer(count) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb b/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb index ef7505e..a8881e2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_quota_table_sizes.rb @@ -37,7 +37,7 @@ EOF formatter.header(%w[TABLE SIZE]) count = 0 quotas_admin.get_master_table_sizes.each do |tableName, size| - formatter.row([tableName.to_s, size.to_s]) + formatter.row([tableName.to_s, quotas_admin.size_to_str(size)]) count += 1 end formatter.footer(count) -- 1.7.1