From db8b8a076a480d966c4939e719c287baf01ad477 Mon Sep 17 00:00:00 2001 From: xuqinya Date: Thu, 21 Feb 2019 14:10:18 +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.swp | Bin 0 -> 16384 bytes hbase-shell/src/main/ruby/hbase/quotas.rb | 22 ++++++++++++++++++++ hbase-shell/src/main/ruby/hbase_constants.rb | 1 + .../ruby/shell/commands/list_quota_snapshots.rb | 14 ++++++++++- .../ruby/shell/commands/list_quota_table_sizes.rb | 12 ++++++++++- 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 hbase-shell/src/main/ruby/hbase/.quotas.rb.swp diff --git a/hbase-shell/src/main/ruby/hbase/.quotas.rb.swp b/hbase-shell/src/main/ruby/hbase/.quotas.rb.swp new file mode 100644 index 0000000000000000000000000000000000000000..1e15a3f8c87d76387499fee92aded532b2fd1dba GIT binary patch literal 16384 zcmeHOTWlj&89s$_S;|r_5~>i0pQOk(o7hQqmrJ%w>Lkv_-Na5k~20S^^W5EVQCLgJz7@|`mmkDX*U zDOy!RGtw8&ob&(Z{O3FWx&1TQo?0)j(x>t>4A*-ZE6rJ(-`x2yyRpDnM{D*(@|~{v zM>duwm*$QmE}7=7UV^%1G`F=ZfSAY~wBAY~wBAY~wBAY~wB;QyHcuXiu|A{zLXu#xNG z?>!^Gx58^JOusae|9Y5zB~1VBNd8;H=Ti9lKv+RkPnewkqzt4Cqzt4Cqzt4Cqzt4C zqzt4Cqzt4Cqzt4C+yw@-CS&5ve^VU9@%}$L|G$1eW3K@>fG2=u;6C7`_b~P?U<ln5Gk^k|1pfAJ#$E;f3j7}UA@F6O4txao^L>mx517CV@XvQK_7C9Kzze|B zzz(ni6o3x`w@xtj3h)cyd%#mb6_^3?z$8Gxf8NR1pMaadkAd$4&jZf@Ujv>5z69(5 z9|B%|2V*Y+KClU#13n7;S%)CkU);0A~Tg@r!pY;6dRvPHJ_rI!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Bn#?Eh`R0JeZl;FG{9;O~e7 z{1Nya@LS*p@GS6EzycKD)4+qkYlsKD0*F|_bHL+38<+#K00aJwSirAFgAfk`xGd`vlGm3$*tMoE{eF z?h}|97TDP*fd8fnY|wGmL>#@dA)pLfswEo1GT4PEX|qF(AU#jk9J(v)Xai>Cr4N&N?%i)r+&v4rd8Z6W!MkT^zYt z=w1UK8QdKfUM*YbSOW)%FuE9=mdWi~o^~x01q6oz;tuzG$2#OSP2k{yi)7uwSZ!+k z3}UfjJjbtf(7x#CK0CWu+=$*YQ8>O4X>`Kzcd!o5-0{n)NC}a_+gG$&uGA5&W5P~x z1@^gIzrC7L636+0njHQ()9Ibdr?(Dn`SEz4psw$FBCv{sxrS&A*uvp{D((mwl$J4K z!d!@d>Xhc=Pm*nL90YvDPeV7|_-&3%KSh~_QvO^iQ7DDojxe-zs(AJa-@*lLoY{)} z0re&4kt0;NP()a?tZp>wm9mU^n|C=z3Ks62!~ z1_cJ(oew3Zx5R{JFj0}DRw^?26o|k-3!l$!Hc#cUC}&Ui_bzYmblYBUE4Nw5!ejQ} zY_u$^S2Mc*wL>6N*h~-C=#R(`ezRx!iX%Jo{tCXup@-;v#7raFhT^Za3g$|aH L(O~xN*Aez#4JdKW literal 0 HcmV?d00001 diff --git a/hbase-shell/src/main/ruby/hbase/quotas.rb b/hbase-shell/src/main/ruby/hbase/quotas.rb index 4023aed..30dd306 100644 --- a/hbase-shell/src/main/ruby/hbase/quotas.rb +++ b/hbase-shell/src/main/ruby/hbase/quotas.rb @@ -309,6 +309,28 @@ module Hbase raise(ArgumentError, 'Invalid throttle limit syntax') end end + + def size_to_str(value) + p = (1 << 50).freeze + t = (1 << 40).freeze + g = (1 << 30).freeze + m = (1 << 20).freeze + k = (1 << 10).freeze + if value >= p + size = (value / p).to_s << 'P' + elsif value >= t + size = (value / t).to_s << 'T' + elsif value >= g + size = (value / g).to_s << 'G' + elsif value >= m + size = (value / m).to_s << 'M' + elsif value >= k + size = (value / k).to_s << 'K' + else + size = value.to_s << 'B' + end + size + end # rubocop:enable Metrics/AbcSize, Metrics/MethodLength def _size_from_str(value, suffix) diff --git a/hbase-shell/src/main/ruby/hbase_constants.rb b/hbase-shell/src/main/ruby/hbase_constants.rb index 5c8ab87..5676275 100644 --- a/hbase-shell/src/main/ruby/hbase_constants.rb +++ b/hbase-shell/src/main/ruby/hbase_constants.rb @@ -98,6 +98,7 @@ module HBaseConstants FORMATTER_CLASS = 'FORMATTER_CLASS'.freeze POLICY = 'POLICY'.freeze REGIONSERVER = 'REGIONSERVER'.freeze + HUMANREADABLE = 'HUMANREADABLE'.freeze # Load constants from hbase java API def self.promote_constants(constants) 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..12a2287 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 @@ -36,6 +36,7 @@ be retreived from that RegionServer instead of the quota table. For example: hbase> list_quota_snapshots + hbase> list_quota_snapshots({HUMANREADABLE=>'true'}) hbase> list_quota_snapshots({TABLE => 'table1'}) hbase> list_quota_snapshots({NAMESPACE => 'org1'}) hbase> list_quota_snapshots({REGIONSERVER => 'server1.domain,16020,1483482894742'}) @@ -43,11 +44,13 @@ For example: EOF end + # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength def command(args = {}) # All arguments may be nil desired_table = args[TABLE] desired_namespace = args[NAMESPACE] desired_regionserver = args[REGIONSERVER] + desired_humanreadable = args[HUMANREADABLE] formatter.header(%w[TABLE USAGE LIMIT IN_VIOLATION POLICY]) count = 0 quotas_admin.get_quota_snapshots(desired_regionserver).each do |table_name, snapshot| @@ -55,12 +58,19 @@ 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]) + if desired_humanreadable == 'true' + 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]) + else + formatter.row([table_name.to_s, snapshot.getUsage.to_s, + snapshot.getLimit.to_s, status.isInViolation.to_s, policy]) + end count += 1 end formatter.footer(count) end + # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength def get_policy(status) # Unwrap the violation policy if it exists 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..0c0c935 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 @@ -30,18 +30,28 @@ provides a higher-level of insight than this command. For example: hbase> list_quota_table_sizes + hbase> list_quota_table_sizes({HUMANREADABLE=>'true'}) EOF end + # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/MethodLength def command(_args = {}) + desired_humanreadable = args[HUMANREADABLE] 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]) + if desired_humanreadable == 'true' + formatter.row([tableName.to_s, quotas_admin.size_to_str(size)]) + else + formatter.row([tableName.to_s, size.to_s]) + end count += 1 end formatter.footer(count) end + # rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/MethodLength end end end -- 1.7.1