From d49eb4286f278b4940ad8d27356f89e0c661d935 Mon Sep 17 00:00:00 2001 From: chunhao Date: Sat, 5 Aug 2017 14:36:44 +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 | 2 +- .../src/main/ruby/shell/commands/deleteall.rb | 2 +- hbase-shell/src/test/ruby/hbase/table_test.rb | 24 ++++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index b297f58..c9796c9 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -24,7 +24,7 @@ include Java module Hbase class Table include HBaseConstants - + HConstants = org.apache.hadoop.hbase.HConstants @@thread_pool = nil # Add the command 'name' to table s.t. the shell command also called via 'name' @@ -162,7 +162,8 @@ EOF #---------------------------------------------------------------------------------------------- # Create a Delete mutation def _createdelete_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) temptimestamp = timestamp if temptimestamp.is_a?(Hash) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP @@ -181,7 +182,11 @@ EOF end if column family, qualifier = parse_column_name(column) - d.addColumns(family, qualifier, timestamp) + if all_version + d.addColumns(family, qualifier, timestamp) + else + d.addColumn(family, qualifier, timestamp) + end end d end @@ -189,7 +194,8 @@ EOF #---------------------------------------------------------------------------------------------- # Delete rows using prefix def _deleterows_internal(row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + timestamp = HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) cache = row['CACHE'] ? row['CACHE'] : 100 prefix = row['ROWPREFIXFILTER'] @@ -205,7 +211,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 +224,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 = HConstants::LATEST_TIMESTAMP, + args = {}, all_version = true) + _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 = 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 +518,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..923d349 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb @@ -48,7 +48,7 @@ EOF def delete(table, row, column, 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..e3a976d 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -154,19 +154,19 @@ module Hbase #------------------------------------------------------------------------------- define_test "delete should work without timestamp" do - @test_table.delete("101", "x:a") + @test_table.deleteall('101', 'x:a') res = @test_table._get_internal('101', 'x:a') assert_nil(res) end define_test "delete should work with timestamp" do - @test_table.delete("102", "x:a", 1214) + @test_table.deleteall('102', 'x:a', 1214) res = @test_table._get_internal('102', 'x:a') assert_nil(res) end define_test "delete should work with integer keys" do - @test_table.delete(103, "x:a") + @test_table.deleteall(103, 'x:a') res = @test_table._get_internal('103', 'x:a') assert_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