Remove timestamp before inserting to WBWI's index (#10742)

Summary:
Currently, this original behavior should not lead to incorrect result, but will violate the contract of CompareWithTimestamp() that when a_has_ts or b_has_ts is false, the slice does not include timestamp.

Resolves https://github.com/facebook/rocksdb/issues/10709

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10742

Test Plan: make check

Reviewed By: ltamasi

Differential Revision: D39834096

Pulled By: riversand963

fbshipit-source-id: c597600f5a7820734f07d0926cdc224cea5eabe1
main
Yanqin Jin 2 years ago committed by Facebook GitHub Bot
parent df492791b6
commit 7045b74b47
  1. 7
      utilities/write_batch_with_index/write_batch_with_index.cc
  2. 20
      utilities/write_batch_with_index/write_batch_with_index_test.cc

@ -153,6 +153,13 @@ void WriteBatchWithIndex::Rep::AddNewEntry(uint32_t column_family_id) {
#endif
assert(success);
const Comparator* const ucmp = comparator.GetComparator(column_family_id);
size_t ts_sz = ucmp ? ucmp->timestamp_size() : 0;
if (ts_sz > 0) {
key.remove_suffix(ts_sz);
}
auto* mem = arena.Allocate(sizeof(WriteBatchIndexEntry));
auto* index_entry =
new (mem) WriteBatchIndexEntry(last_entry_offset, column_family_id,

@ -2387,6 +2387,26 @@ TEST_P(WriteBatchWithIndexTest, ColumnFamilyWithTimestamp) {
}
}
TEST_P(WriteBatchWithIndexTest, IndexNoTs) {
const Comparator* const ucmp = test::BytewiseComparatorWithU64TsWrapper();
ColumnFamilyHandleImplDummy cf(1, ucmp);
WriteBatchWithIndex wbwi;
ASSERT_OK(wbwi.Put(&cf, "a", "a0"));
ASSERT_OK(wbwi.Put(&cf, "a", "a1"));
{
std::string ts;
PutFixed64(&ts, 10000);
ASSERT_OK(wbwi.GetWriteBatch()->UpdateTimestamps(
ts, [](uint32_t cf_id) { return cf_id == 1 ? 8 : 0; }));
}
{
std::string value;
Status s = wbwi.GetFromBatch(&cf, options_, "a", &value);
ASSERT_OK(s);
ASSERT_EQ("a1", value);
}
}
INSTANTIATE_TEST_CASE_P(WBWI, WriteBatchWithIndexTest, testing::Bool());
} // namespace ROCKSDB_NAMESPACE

Loading…
Cancel
Save