HBASE-18142 Deletion of a cell deletes the previous versions too

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Chun-Hao Tang 2017-09-15 02:13:12 +08:00 committed by Chia-Ping Tsai
parent 83e9188d0c
commit 03eefa8aa5
4 changed files with 40 additions and 45 deletions

View File

@ -24,7 +24,6 @@ include Java
module Hbase module Hbase
class Table class Table
include HBaseConstants include HBaseConstants
@@thread_pool = nil @@thread_pool = nil
# Add the command 'name' to table s.t. the shell command also called via 'name' # 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 Note that after dropping a table, your reference to it becomes useless and further usage
is undefined (and not recommended). is undefined (and not recommended).
EOF EOF
end end
#--------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------
@ -162,7 +161,8 @@ EOF
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Create a Delete mutation # Create a Delete mutation
def _createdelete_internal(row, column = nil, 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 temptimestamp = timestamp
if temptimestamp.is_a?(Hash) if temptimestamp.is_a?(Hash)
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP
@ -179,9 +179,12 @@ EOF
visibility = args[VISIBILITY] visibility = args[VISIBILITY]
set_cell_visibility(d, visibility) if visibility set_cell_visibility(d, visibility) if visibility
end end
if column if column && all_version
family, qualifier = parse_column_name(column) family, qualifier = parse_column_name(column)
d.addColumns(family, qualifier, timestamp) d.addColumns(family, qualifier, timestamp)
elsif column && !all_version
family, qualifier = parse_column_name(column)
d.addColumn(family, qualifier, timestamp)
end end
d d
end end
@ -189,7 +192,8 @@ EOF
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Delete rows using prefix # Delete rows using prefix
def _deleterows_internal(row, column = nil, 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 cache = row['CACHE'] ? row['CACHE'] : 100
prefix = row['ROWPREFIXFILTER'] prefix = row['ROWPREFIXFILTER']
@ -205,7 +209,7 @@ EOF
while iter.hasNext while iter.hasNext
row = iter.next row = iter.next
key = org.apache.hadoop.hbase.util.Bytes.toStringBinary(row.getRow) 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) list.add(d)
if list.size >= cache if list.size >= cache
@table.delete(list) @table.delete(list)
@ -218,23 +222,25 @@ EOF
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Delete a cell # Delete a cell
def _delete_internal(row, column, def _delete_internal(row, column,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
_deleteall_internal(row, column, timestamp, args) args = {}, all_version = false)
_deleteall_internal(row, column, timestamp, args, all_version)
end end
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Delete a row # Delete a row
def _deleteall_internal(row, column = nil, 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 # delete operation doesn't need read permission. Retaining the read check for
# meta table as a part of HBASE-5837. # meta table as a part of HBASE-5837.
if is_meta_table? if is_meta_table?
raise ArgumentError, 'Row Not Found' if _get_internal(row).nil? raise ArgumentError, 'Row Not Found' if _get_internal(row).nil?
end end
if row.is_a?(Hash) if row.is_a?(Hash)
_deleterows_internal(row, column, timestamp, args) _deleterows_internal(row, column, timestamp, args, all_version)
else else
d = _createdelete_internal(row, column, timestamp, args) d = _createdelete_internal(row, column, timestamp, args, all_version)
@table.delete(d) @table.delete(d)
end end
end end
@ -510,7 +516,7 @@ EOF
org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes) org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes)
else else
org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes)
end end
# This will overwrite any startrow/stoprow settings # This will overwrite any startrow/stoprow settings
scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter

View File

@ -40,15 +40,15 @@ t to table 't1', the corresponding command would be:
EOF EOF
end end
def command(table, row, column, def command(table, row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
delete(table(table), row, column, timestamp, args) delete(table(table), row, column, timestamp, args)
end end
def delete(table, row, column, def delete(table, row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
@start_time = Time.now @start_time = Time.now
table._delete_internal(row, column, timestamp, args) table._delete_internal(row, column, timestamp, args, false)
end end
end end
end end

View File

@ -58,7 +58,7 @@ EOF
def deleteall(table, row, column = nil, def deleteall(table, row, column = nil,
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
@start_time = Time.now @start_time = Time.now
table._deleteall_internal(row, column, timestamp, args) table._deleteall_internal(row, column, timestamp, args, true)
end end
end end
end end

View File

@ -106,18 +106,12 @@ module Hbase
@test_table = table(@test_name) @test_table = table(@test_name)
# Insert data to perform delete operations # Insert data to perform delete operations
@test_table.put("101", "x:a", "1") @test_table.put("102", "x:a", "2", 1212)
@test_table.put("101", "x:a", "2", Time.now.to_i) @test_table.put(103, "x:a", "3", 1214)
@test_table.put("102", "x:a", "1", 1212)
@test_table.put("102", "x:a", "2", 1213)
@test_table.put(103, "x:a", "3")
@test_table.put(103, "x:a", "4")
@test_table.put("104", "x:a", 5) @test_table.put("104", "x:a", 5)
@test_table.put("104", "x:b", 6) @test_table.put("104", "x:b", 6)
@test_table.put(105, "x:a", "3") @test_table.put(105, "x:a", "3")
@test_table.put(105, "x:a", "4") @test_table.put(105, "x:a", "4")
@ -152,21 +146,16 @@ module Hbase
end end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "delete should work with string keys" do
define_test "delete should work without timestamp" do @test_table.delete('102', 'x:a', 1212)
@test_table.delete("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)
res = @test_table._get_internal('102', 'x:a') res = @test_table._get_internal('102', 'x:a')
assert_nil(res) assert_nil(res)
end end
define_test "delete should work with integer keys" do define_test "delete should work with integer keys" do
@test_table.delete(103, "x:a") res = @test_table._get_internal('103', 'x:a')
assert_not_nil(res)
@test_table.delete(103, 'x:a', 1214)
res = @test_table._get_internal('103', 'x:a') res = @test_table._get_internal('103', 'x:a')
assert_nil(res) assert_nil(res)
end end
@ -266,7 +255,7 @@ module Hbase
count = @test_table.count COLUMNS => [ 'x:c'] count = @test_table.count COLUMNS => [ 'x:c']
assert(count == 1) assert(count == 1)
ensure ensure
@test_table.delete(4, "x:c") @test_table.deleteall(4, 'x:c')
end end
end end
@ -413,8 +402,8 @@ module Hbase
assert_not_nil(/value=98/.match(res['x:d'])) assert_not_nil(/value=98/.match(res['x:d']))
ensure ensure
# clean up newly added columns for this test only. # clean up newly added columns for this test only.
@test_table.delete(1, "x:c") @test_table.deleteall(1, 'x:c')
@test_table.delete(1, "x:d") @test_table.deleteall(1, 'x:d')
end end
end end
@ -430,7 +419,7 @@ module Hbase
assert_nil(res) assert_nil(res)
ensure ensure
# clean up newly added columns for this test only. # clean up newly added columns for this test only.
@test_table.delete(1, "x:v") @test_table.deleteall(1, 'x:v')
end end
end end
@ -613,8 +602,8 @@ module Hbase
assert_not_nil(/value=98/.match(res['1']['x:d'])) assert_not_nil(/value=98/.match(res['1']['x:d']))
ensure ensure
# clean up newly added columns for this test only. # clean up newly added columns for this test only.
@test_table.delete(1, "x:c") @test_table.deleteall(1, 'x:c')
@test_table.delete(1, "x:d") @test_table.deleteall(1, 'x:d')
end end
end end
@ -632,7 +621,7 @@ module Hbase
assert_equal(res, {}, "Result is not empty") assert_equal(res, {}, "Result is not empty")
ensure ensure
# clean up newly added columns for this test only. # clean up newly added columns for this test only.
@test_table.delete(1, "x:v") @test_table.deleteall(1, 'x:v')
end end
end end
@ -648,7 +637,7 @@ module Hbase
assert_nil(res['2']) assert_nil(res['2'])
ensure ensure
# clean up newly added columns for this test only. # clean up newly added columns for this test only.
@test_table.delete(4, "x:a") @test_table.deleteall(4, 'x:a')
end end
end end
@ -666,7 +655,7 @@ module Hbase
res = @test_table._get_internal('ttlTest', 'x:a') res = @test_table._get_internal('ttlTest', 'x:a')
assert_nil(res) assert_nil(res)
ensure ensure
@test_table.delete('ttlTest', 'x:a') @test_table.deleteall('ttlTest', 'x:a')
end end
end end