]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/cassandra/cassandra_compaction_filter.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / utilities / cassandra / cassandra_compaction_filter.cc
CommitLineData
11fdf7f2
TL
1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
5
6#include "utilities/cassandra/cassandra_compaction_filter.h"
7#include <string>
8#include "rocksdb/slice.h"
9#include "utilities/cassandra/format.h"
10
f67539c2 11namespace ROCKSDB_NAMESPACE {
11fdf7f2
TL
12namespace cassandra {
13
14const char* CassandraCompactionFilter::Name() const {
15 return "CassandraCompactionFilter";
16}
17
18CompactionFilter::Decision CassandraCompactionFilter::FilterV2(
19 int /*level*/, const Slice& /*key*/, ValueType value_type,
20 const Slice& existing_value, std::string* new_value,
21 std::string* /*skip_until*/) const {
22 bool value_changed = false;
23 RowValue row_value = RowValue::Deserialize(
24 existing_value.data(), existing_value.size());
25 RowValue compacted =
26 purge_ttl_on_expiration_
27 ? row_value.RemoveExpiredColumns(&value_changed)
28 : row_value.ConvertExpiredColumnsToTombstones(&value_changed);
29
30 if (value_type == ValueType::kValue) {
31 compacted = compacted.RemoveTombstones(gc_grace_period_in_seconds_);
32 }
33
34 if(compacted.Empty()) {
35 return Decision::kRemove;
36 }
37
38 if (value_changed) {
39 compacted.Serialize(new_value);
40 return Decision::kChangeValue;
41 }
42
43 return Decision::kKeep;
44}
45
46} // namespace cassandra
f67539c2 47} // namespace ROCKSDB_NAMESPACE