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-18 16:06:00 +08:00 committed by Chia-Ping Tsai
parent 815673f7e4
commit bd0f6551f5
4 changed files with 32 additions and 37 deletions

View File

@ -102,7 +102,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,14 +162,16 @@ 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?
@ -191,9 +193,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.deleteColumns(family, qualifier, timestamp) d.deleteColumns(family, qualifier, timestamp)
elsif column && !all_version
family, qualifier = parse_column_name(column)
d.deleteColumn(family, qualifier, timestamp)
end end
@table.delete(d) @table.delete(d)
end end

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 = {})
format_simple_command do format_simple_command do
table._delete_internal(row, column, timestamp, args) table._delete_internal(row, column, timestamp, args, false)
end end
end end
end end

View File

@ -49,7 +49,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 = {})
format_simple_command do format_simple_command do
table._deleteall_internal(row, column, timestamp, args) table._deleteall_internal(row, column, timestamp, args, true)
end end
end end
end end

View File

@ -104,20 +104,14 @@ module Hbase
@test_name = "hbase_shell_tests_table" @test_name = "hbase_shell_tests_table"
create_test_table(@test_name) create_test_table(@test_name)
@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")
end end
@ -149,20 +143,16 @@ module Hbase
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test "delete should work without timestamp" do define_test "delete should work with string keys" do
@test_table.delete("101", "x:a") @test_table.delete('102', 'x:a', 1212)
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
@ -376,8 +366,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
@ -393,7 +383,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
@ -576,8 +566,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
@ -595,7 +585,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
@ -611,7 +601,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
@ -624,7 +614,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