From 83ab3a6b4c5215fdece50797da7182acbebfc7f2 Mon Sep 17 00:00:00 2001 From: Chun-Hao Tang Date: Sun, 6 Aug 2017 16:56:45 +0800 Subject: [PATCH] HBASE-18142 Deletion of a cell deletes the previous versions too --- hbase-shell/src/main/ruby/hbase/table.rb | 30 +++++++++++++--------- hbase-shell/src/main/ruby/shell/commands/delete.rb | 6 ++--- .../src/main/ruby/shell/commands/deleteall.rb | 2 +- hbase-shell/src/test/ruby/hbase/table_test.rb | 30 +++++++++++----------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index b297f58..7eaf1b3 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -24,7 +24,6 @@ include Java module Hbase class Table include HBaseConstants - @@thread_pool = nil # Add the command 'name' to table s.t. the shell command also called via 'name' @@ -102,7 +101,7 @@ flush and drop just by typing: Note that after dropping a table, your reference to it becomes useless and further usage is undefined (and not recommended). EOF - end + end #--------------------------------------------------------------------------------------------- @@ -162,7 +161,8 @@ EOF #---------------------------------------------------------------------------------------------- # Create a Delete mutation def _createdelete_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) temptimestamp = timestamp if temptimestamp.is_a?(Hash) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP @@ -179,9 +179,12 @@ EOF visibility = args[VISIBILITY] set_cell_visibility(d, visibility) if visibility end - if column + if column && all_version family, qualifier = parse_column_name(column) d.addColumns(family, qualifier, timestamp) + elsif column && !all_version + family, qualifier = parse_column_name(column) + d.addColumn(family, qualifier, timestamp) end d end @@ -189,7 +192,8 @@ EOF #---------------------------------------------------------------------------------------------- # Delete rows using prefix def _deleterows_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) cache = row['CACHE'] ? row['CACHE'] : 100 prefix = row['ROWPREFIXFILTER'] @@ -205,7 +209,7 @@ EOF while iter.hasNext row = iter.next key = org.apache.hadoop.hbase.util.Bytes.toStringBinary(row.getRow) - d = _createdelete_internal(key, column, timestamp, args) + d = _createdelete_internal(key, column, timestamp, args, all_version) list.add(d) if list.size >= cache @table.delete(list) @@ -218,23 +222,25 @@ EOF #---------------------------------------------------------------------------------------------- # Delete a cell def _delete_internal(row, column, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) - _deleteall_internal(row, column, timestamp, args) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, + args = {}, all_version = false) + _deleteall_internal(row, column, timestamp, args, all_version) end #---------------------------------------------------------------------------------------------- # Delete a row def _deleteall_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) # delete operation doesn't need read permission. Retaining the read check for # meta table as a part of HBASE-5837. if is_meta_table? raise ArgumentError, 'Row Not Found' if _get_internal(row).nil? end if row.is_a?(Hash) - _deleterows_internal(row, column, timestamp, args) + _deleterows_internal(row, column, timestamp, args, all_version) else - d = _createdelete_internal(row, column, timestamp, args) + d = _createdelete_internal(row, column, timestamp, args, all_version) @table.delete(d) end end @@ -510,7 +516,7 @@ EOF org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes) else org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) - end + end # This will overwrite any startrow/stoprow settings scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter diff --git a/hbase-shell/src/main/ruby/shell/commands/delete.rb b/hbase-shell/src/main/ruby/shell/commands/delete.rb index 3e4447c..6995959 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb @@ -40,15 +40,15 @@ t to table 't1', the corresponding command would be: EOF end - def command(table, row, column, + def command(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) delete(table(table), row, column, timestamp, args) end - def delete(table, row, column, + def delete(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) @start_time = Time.now - table._delete_internal(row, column, timestamp, args) + table._delete_internal(row, column, timestamp, args, false) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb index f5444ae..f18fa05 100644 --- a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb +++ b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb @@ -58,7 +58,7 @@ EOF def deleteall(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) @start_time = Time.now - table._deleteall_internal(row, column, timestamp, args) + table._deleteall_internal(row, column, timestamp, args, true) end end end diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index a01514c..7751ab7 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -154,21 +154,21 @@ module Hbase #------------------------------------------------------------------------------- define_test "delete should work without timestamp" do - @test_table.delete("101", "x:a") + @test_table.delete('101', 'x:a') res = @test_table._get_internal('101', 'x:a') - assert_nil(res) + assert_not_nil(res) end define_test "delete should work with timestamp" do - @test_table.delete("102", "x:a", 1214) + @test_table.delete('102', 'x:a', 1213) res = @test_table._get_internal('102', 'x:a') - assert_nil(res) + assert_not_nil(res) end define_test "delete should work with integer keys" do - @test_table.delete(103, "x:a") + @test_table.delete(103, 'x:a') res = @test_table._get_internal('103', 'x:a') - assert_nil(res) + assert_not_nil(res) end #------------------------------------------------------------------------------- @@ -266,7 +266,7 @@ module Hbase count = @test_table.count COLUMNS => [ 'x:c'] assert(count == 1) ensure - @test_table.delete(4, "x:c") + @test_table.deleteall(4, 'x:c') end end @@ -413,8 +413,8 @@ module Hbase assert_not_nil(/value=98/.match(res['x:d'])) ensure # clean up newly added columns for this test only. - @test_table.delete(1, "x:c") - @test_table.delete(1, "x:d") + @test_table.deleteall(1, 'x:c') + @test_table.deleteall(1, 'x:d') end end @@ -430,7 +430,7 @@ module Hbase assert_nil(res) ensure # clean up newly added columns for this test only. - @test_table.delete(1, "x:v") + @test_table.deleteall(1, 'x:v') end end @@ -613,8 +613,8 @@ module Hbase assert_not_nil(/value=98/.match(res['1']['x:d'])) ensure # clean up newly added columns for this test only. - @test_table.delete(1, "x:c") - @test_table.delete(1, "x:d") + @test_table.deleteall(1, 'x:c') + @test_table.deleteall(1, 'x:d') end end @@ -632,7 +632,7 @@ module Hbase assert_equal(res, {}, "Result is not empty") ensure # clean up newly added columns for this test only. - @test_table.delete(1, "x:v") + @test_table.deleteall(1, 'x:v') end end @@ -648,7 +648,7 @@ module Hbase assert_nil(res['2']) ensure # clean up newly added columns for this test only. - @test_table.delete(4, "x:a") + @test_table.deleteall(4, 'x:a') end end @@ -666,7 +666,7 @@ module Hbase res = @test_table._get_internal('ttlTest', 'x:a') assert_nil(res) ensure - @test_table.delete('ttlTest', 'x:a') + @test_table.deleteall('ttlTest', 'x:a') end end -- 1.9.2.msysgit.0