2017-06-16 21:12:52 +00:00
|
|
|
// Copyright (c) 2017-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-07-21 21:42:32 +00:00
|
|
|
#include "utilities/cassandra/serialize.h"
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2024-03-04 18:08:32 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE::cassandra {
|
2017-06-16 21:12:52 +00:00
|
|
|
namespace {
|
2022-10-24 23:38:09 +00:00
|
|
|
const int32_t kDefaultLocalDeletionTime = std::numeric_limits<int32_t>::max();
|
|
|
|
const int64_t kDefaultMarkedForDeleteAt = std::numeric_limits<int64_t>::min();
|
|
|
|
} // namespace
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
ColumnBase::ColumnBase(int8_t mask, int8_t index)
|
2022-10-24 23:38:09 +00:00
|
|
|
: mask_(mask), index_(index) {}
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
std::size_t ColumnBase::Size() const { return sizeof(mask_) + sizeof(index_); }
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
int8_t ColumnBase::Mask() const { return mask_; }
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
int8_t ColumnBase::Index() const { return index_; }
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
void ColumnBase::Serialize(std::string* dest) const {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int8_t>(mask_, dest);
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int8_t>(index_, dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 21:42:32 +00:00
|
|
|
std::shared_ptr<ColumnBase> ColumnBase::Deserialize(const char* src,
|
2017-06-16 21:12:52 +00:00
|
|
|
std::size_t offset) {
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t mask = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
if ((mask & ColumnTypeMask::DELETION_MASK) != 0) {
|
|
|
|
return Tombstone::Deserialize(src, offset);
|
|
|
|
} else if ((mask & ColumnTypeMask::EXPIRATION_MASK) != 0) {
|
|
|
|
return ExpiringColumn::Deserialize(src, offset);
|
|
|
|
} else {
|
|
|
|
return Column::Deserialize(src, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
Column::Column(int8_t mask, int8_t index, int64_t timestamp, int32_t value_size,
|
|
|
|
const char* value)
|
|
|
|
: ColumnBase(mask, index),
|
|
|
|
timestamp_(timestamp),
|
|
|
|
value_size_(value_size),
|
|
|
|
value_(value) {}
|
|
|
|
|
|
|
|
int64_t Column::Timestamp() const { return timestamp_; }
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
std::size_t Column::Size() const {
|
2022-10-24 23:38:09 +00:00
|
|
|
return ColumnBase::Size() + sizeof(timestamp_) + sizeof(value_size_) +
|
|
|
|
value_size_;
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Column::Serialize(std::string* dest) const {
|
|
|
|
ColumnBase::Serialize(dest);
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int64_t>(timestamp_, dest);
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int32_t>(value_size_, dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
dest->append(value_, value_size_);
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
std::shared_ptr<Column> Column::Deserialize(const char* src,
|
2017-06-16 21:12:52 +00:00
|
|
|
std::size_t offset) {
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t mask = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(mask);
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t index = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(index);
|
2020-02-20 20:07:53 +00:00
|
|
|
int64_t timestamp =
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int64_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(timestamp);
|
2020-02-20 20:07:53 +00:00
|
|
|
int32_t value_size =
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int32_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(value_size);
|
2022-10-24 23:38:09 +00:00
|
|
|
return std::make_shared<Column>(mask, index, timestamp, value_size,
|
|
|
|
src + offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
ExpiringColumn::ExpiringColumn(int8_t mask, int8_t index, int64_t timestamp,
|
|
|
|
int32_t value_size, const char* value,
|
|
|
|
int32_t ttl)
|
|
|
|
: Column(mask, index, timestamp, value_size, value), ttl_(ttl) {}
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
std::size_t ExpiringColumn::Size() const {
|
|
|
|
return Column::Size() + sizeof(ttl_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExpiringColumn::Serialize(std::string* dest) const {
|
|
|
|
Column::Serialize(dest);
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int32_t>(ttl_, dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> ExpiringColumn::TimePoint()
|
|
|
|
const {
|
|
|
|
return std::chrono::time_point<std::chrono::system_clock>(
|
|
|
|
std::chrono::microseconds(Timestamp()));
|
2017-07-21 21:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::seconds ExpiringColumn::Ttl() const {
|
|
|
|
return std::chrono::seconds(ttl_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExpiringColumn::Expired() const {
|
|
|
|
return TimePoint() + Ttl() < std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Tombstone> ExpiringColumn::ToTombstone() const {
|
|
|
|
auto expired_at = (TimePoint() + Ttl()).time_since_epoch();
|
|
|
|
int32_t local_deletion_time = static_cast<int32_t>(
|
2022-10-24 23:38:09 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::seconds>(expired_at).count());
|
2017-07-21 21:42:32 +00:00
|
|
|
int64_t marked_for_delete_at =
|
2022-10-24 23:38:09 +00:00
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(expired_at).count();
|
2017-07-21 21:42:32 +00:00
|
|
|
return std::make_shared<Tombstone>(
|
2022-10-24 23:38:09 +00:00
|
|
|
static_cast<int8_t>(ColumnTypeMask::DELETION_MASK), Index(),
|
|
|
|
local_deletion_time, marked_for_delete_at);
|
2017-07-21 21:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ExpiringColumn> ExpiringColumn::Deserialize(
|
2022-10-24 23:38:09 +00:00
|
|
|
const char* src, std::size_t offset) {
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t mask = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(mask);
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t index = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(index);
|
2020-02-20 20:07:53 +00:00
|
|
|
int64_t timestamp =
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int64_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(timestamp);
|
2020-02-20 20:07:53 +00:00
|
|
|
int32_t value_size =
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int32_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(value_size);
|
|
|
|
const char* value = src + offset;
|
|
|
|
offset += value_size;
|
2020-02-20 20:07:53 +00:00
|
|
|
int32_t ttl = ROCKSDB_NAMESPACE::cassandra::Deserialize<int32_t>(src, offset);
|
2022-10-24 23:38:09 +00:00
|
|
|
return std::make_shared<ExpiringColumn>(mask, index, timestamp, value_size,
|
|
|
|
value, ttl);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
Tombstone::Tombstone(int8_t mask, int8_t index, int32_t local_deletion_time,
|
|
|
|
int64_t marked_for_delete_at)
|
|
|
|
: ColumnBase(mask, index),
|
|
|
|
local_deletion_time_(local_deletion_time),
|
|
|
|
marked_for_delete_at_(marked_for_delete_at) {}
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
int64_t Tombstone::Timestamp() const { return marked_for_delete_at_; }
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
std::size_t Tombstone::Size() const {
|
2022-10-24 23:38:09 +00:00
|
|
|
return ColumnBase::Size() + sizeof(local_deletion_time_) +
|
|
|
|
sizeof(marked_for_delete_at_);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Tombstone::Serialize(std::string* dest) const {
|
|
|
|
ColumnBase::Serialize(dest);
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int32_t>(local_deletion_time_, dest);
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int64_t>(marked_for_delete_at_, dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 17:10:47 +00:00
|
|
|
bool Tombstone::Collectable(int32_t gc_grace_period_in_seconds) const {
|
|
|
|
auto local_deleted_at = std::chrono::time_point<std::chrono::system_clock>(
|
|
|
|
std::chrono::seconds(local_deletion_time_));
|
|
|
|
auto gc_grace_period = std::chrono::seconds(gc_grace_period_in_seconds);
|
|
|
|
return local_deleted_at + gc_grace_period < std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
std::shared_ptr<Tombstone> Tombstone::Deserialize(const char* src,
|
2017-06-16 21:12:52 +00:00
|
|
|
std::size_t offset) {
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t mask = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(mask);
|
2020-02-20 20:07:53 +00:00
|
|
|
int8_t index = ROCKSDB_NAMESPACE::cassandra::Deserialize<int8_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(index);
|
|
|
|
int32_t local_deletion_time =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int32_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(int32_t);
|
|
|
|
int64_t marked_for_delete_at =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int64_t>(src, offset);
|
2022-10-24 23:38:09 +00:00
|
|
|
return std::make_shared<Tombstone>(mask, index, local_deletion_time,
|
|
|
|
marked_for_delete_at);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RowValue::RowValue(int32_t local_deletion_time, int64_t marked_for_delete_at)
|
2022-10-24 23:38:09 +00:00
|
|
|
: local_deletion_time_(local_deletion_time),
|
|
|
|
marked_for_delete_at_(marked_for_delete_at),
|
|
|
|
columns_(),
|
|
|
|
last_modified_time_(0) {}
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
RowValue::RowValue(Columns columns, int64_t last_modified_time)
|
|
|
|
: local_deletion_time_(kDefaultLocalDeletionTime),
|
|
|
|
marked_for_delete_at_(kDefaultMarkedForDeleteAt),
|
|
|
|
columns_(std::move(columns)),
|
|
|
|
last_modified_time_(last_modified_time) {}
|
2017-06-16 21:12:52 +00:00
|
|
|
|
|
|
|
std::size_t RowValue::Size() const {
|
2022-10-24 23:38:09 +00:00
|
|
|
std::size_t size =
|
|
|
|
sizeof(local_deletion_time_) + sizeof(marked_for_delete_at_);
|
2017-06-16 21:12:52 +00:00
|
|
|
for (const auto& column : columns_) {
|
2022-10-24 23:38:09 +00:00
|
|
|
size += column->Size();
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t RowValue::LastModifiedTime() const {
|
|
|
|
if (IsTombstone()) {
|
|
|
|
return marked_for_delete_at_;
|
|
|
|
} else {
|
|
|
|
return last_modified_time_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RowValue::IsTombstone() const {
|
|
|
|
return marked_for_delete_at_ > kDefaultMarkedForDeleteAt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RowValue::Serialize(std::string* dest) const {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int32_t>(local_deletion_time_, dest);
|
|
|
|
ROCKSDB_NAMESPACE::cassandra::Serialize<int64_t>(marked_for_delete_at_, dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
for (const auto& column : columns_) {
|
2022-10-24 23:38:09 +00:00
|
|
|
column->Serialize(dest);
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:10:47 +00:00
|
|
|
RowValue RowValue::RemoveExpiredColumns(bool* changed) const {
|
2017-07-21 21:42:32 +00:00
|
|
|
*changed = false;
|
|
|
|
Columns new_columns;
|
|
|
|
for (auto& column : columns_) {
|
2022-10-24 23:38:09 +00:00
|
|
|
if (column->Mask() == ColumnTypeMask::EXPIRATION_MASK) {
|
2017-07-21 21:42:32 +00:00
|
|
|
std::shared_ptr<ExpiringColumn> expiring_column =
|
2022-10-24 23:38:09 +00:00
|
|
|
std::static_pointer_cast<ExpiringColumn>(column);
|
2017-07-21 21:42:32 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
if (expiring_column->Expired()) {
|
2017-07-21 21:42:32 +00:00
|
|
|
*changed = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_columns.push_back(column);
|
|
|
|
}
|
|
|
|
return RowValue(std::move(new_columns), last_modified_time_);
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:10:47 +00:00
|
|
|
RowValue RowValue::ConvertExpiredColumnsToTombstones(bool* changed) const {
|
2017-07-21 21:42:32 +00:00
|
|
|
*changed = false;
|
|
|
|
Columns new_columns;
|
|
|
|
for (auto& column : columns_) {
|
2022-10-24 23:38:09 +00:00
|
|
|
if (column->Mask() == ColumnTypeMask::EXPIRATION_MASK) {
|
2017-07-21 21:42:32 +00:00
|
|
|
std::shared_ptr<ExpiringColumn> expiring_column =
|
2022-10-24 23:38:09 +00:00
|
|
|
std::static_pointer_cast<ExpiringColumn>(column);
|
2017-07-21 21:42:32 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
if (expiring_column->Expired()) {
|
2018-11-09 19:17:34 +00:00
|
|
|
std::shared_ptr<Tombstone> tombstone = expiring_column->ToTombstone();
|
2017-07-21 21:42:32 +00:00
|
|
|
new_columns.push_back(tombstone);
|
|
|
|
*changed = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new_columns.push_back(column);
|
2017-08-31 17:10:47 +00:00
|
|
|
}
|
|
|
|
return RowValue(std::move(new_columns), last_modified_time_);
|
|
|
|
}
|
|
|
|
|
|
|
|
RowValue RowValue::RemoveTombstones(int32_t gc_grace_period) const {
|
|
|
|
Columns new_columns;
|
|
|
|
for (auto& column : columns_) {
|
|
|
|
if (column->Mask() == ColumnTypeMask::DELETION_MASK) {
|
|
|
|
std::shared_ptr<Tombstone> tombstone =
|
|
|
|
std::static_pointer_cast<Tombstone>(column);
|
|
|
|
|
|
|
|
if (tombstone->Collectable(gc_grace_period)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_columns.push_back(column);
|
2017-07-21 21:42:32 +00:00
|
|
|
}
|
|
|
|
return RowValue(std::move(new_columns), last_modified_time_);
|
|
|
|
}
|
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
bool RowValue::Empty() const { return columns_.empty(); }
|
2017-07-21 21:42:32 +00:00
|
|
|
|
2022-10-24 23:38:09 +00:00
|
|
|
RowValue RowValue::Deserialize(const char* src, std::size_t size) {
|
2017-06-16 21:12:52 +00:00
|
|
|
std::size_t offset = 0;
|
|
|
|
assert(size >= sizeof(local_deletion_time_) + sizeof(marked_for_delete_at_));
|
|
|
|
int32_t local_deletion_time =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int32_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(int32_t);
|
|
|
|
int64_t marked_for_delete_at =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::cassandra::Deserialize<int64_t>(src, offset);
|
2017-06-16 21:12:52 +00:00
|
|
|
offset += sizeof(int64_t);
|
|
|
|
if (offset == size) {
|
|
|
|
return RowValue(local_deletion_time, marked_for_delete_at);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(local_deletion_time == kDefaultLocalDeletionTime);
|
|
|
|
assert(marked_for_delete_at == kDefaultMarkedForDeleteAt);
|
2017-07-21 21:42:32 +00:00
|
|
|
Columns columns;
|
2017-06-16 21:12:52 +00:00
|
|
|
int64_t last_modified_time = 0;
|
|
|
|
while (offset < size) {
|
|
|
|
auto c = ColumnBase::Deserialize(src, offset);
|
2022-10-24 23:38:09 +00:00
|
|
|
offset += c->Size();
|
2017-06-16 21:12:52 +00:00
|
|
|
assert(offset <= size);
|
2022-10-24 23:38:09 +00:00
|
|
|
last_modified_time = std::max(last_modified_time, c->Timestamp());
|
2017-06-16 21:12:52 +00:00
|
|
|
columns.push_back(std::move(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
return RowValue(std::move(columns), last_modified_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge multiple row values into one.
|
|
|
|
// For each column in rows with same index, we pick the one with latest
|
|
|
|
// timestamp. And we also take row tombstone into consideration, by iterating
|
|
|
|
// each row from reverse timestamp order, and stop once we hit the first
|
|
|
|
// row tombstone.
|
|
|
|
RowValue RowValue::Merge(std::vector<RowValue>&& values) {
|
|
|
|
assert(values.size() > 0);
|
|
|
|
if (values.size() == 1) {
|
|
|
|
return std::move(values[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge columns by their last modified time, and skip once we hit
|
|
|
|
// a row tombstone.
|
|
|
|
std::sort(values.begin(), values.end(),
|
2022-10-24 23:38:09 +00:00
|
|
|
[](const RowValue& r1, const RowValue& r2) {
|
|
|
|
return r1.LastModifiedTime() > r2.LastModifiedTime();
|
|
|
|
});
|
2017-06-16 21:12:52 +00:00
|
|
|
|
2017-07-21 21:42:32 +00:00
|
|
|
std::map<int8_t, std::shared_ptr<ColumnBase>> merged_columns;
|
2017-06-16 21:12:52 +00:00
|
|
|
int64_t tombstone_timestamp = 0;
|
|
|
|
|
|
|
|
for (auto& value : values) {
|
|
|
|
if (value.IsTombstone()) {
|
|
|
|
if (merged_columns.size() == 0) {
|
|
|
|
return std::move(value);
|
|
|
|
}
|
|
|
|
tombstone_timestamp = value.LastModifiedTime();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (auto& column : value.columns_) {
|
|
|
|
int8_t index = column->Index();
|
|
|
|
if (merged_columns.find(index) == merged_columns.end()) {
|
2017-07-21 21:42:32 +00:00
|
|
|
merged_columns[index] = column;
|
2017-06-16 21:12:52 +00:00
|
|
|
} else {
|
|
|
|
if (column->Timestamp() > merged_columns[index]->Timestamp()) {
|
2017-07-21 21:42:32 +00:00
|
|
|
merged_columns[index] = column;
|
2017-06-16 21:12:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t last_modified_time = 0;
|
2017-07-21 21:42:32 +00:00
|
|
|
Columns columns;
|
2022-10-24 23:38:09 +00:00
|
|
|
for (auto& pair : merged_columns) {
|
2017-06-16 21:12:52 +00:00
|
|
|
// For some row, its last_modified_time > row tombstone_timestamp, but
|
|
|
|
// it might have rows whose timestamp is ealier than tombstone, so we
|
|
|
|
// ned to filter these rows.
|
|
|
|
if (pair.second->Timestamp() <= tombstone_timestamp) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
last_modified_time = std::max(last_modified_time, pair.second->Timestamp());
|
|
|
|
columns.push_back(std::move(pair.second));
|
|
|
|
}
|
|
|
|
return RowValue(std::move(columns), last_modified_time);
|
|
|
|
}
|
|
|
|
|
2024-03-04 18:08:32 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE::cassandra
|