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).
8 #include "rocksdb/compaction_filter.h"
9 #include "rocksdb/slice.h"
11 namespace ROCKSDB_NAMESPACE
{
15 * Compaction filter for removing expired Cassandra data with ttl.
16 * If option `purge_ttl_on_expiration` is set to true, expired data
17 * will be directly purged. Otherwise expired data will be converted
18 * tombstones first, then be eventally removed after gc grace period.
19 * `purge_ttl_on_expiration` should only be on in the case all the
20 * writes have same ttl setting, otherwise it could bring old data back.
22 * Compaction filter is also in charge of removing tombstone that has been
23 * promoted to kValue type after serials of merging in compaction.
25 class CassandraCompactionFilter
: public CompactionFilter
{
27 explicit CassandraCompactionFilter(bool purge_ttl_on_expiration
,
28 int32_t gc_grace_period_in_seconds
)
29 : purge_ttl_on_expiration_(purge_ttl_on_expiration
),
30 gc_grace_period_in_seconds_(gc_grace_period_in_seconds
) {}
32 const char* Name() const override
;
33 virtual Decision
FilterV2(int level
, const Slice
& key
, ValueType value_type
,
34 const Slice
& existing_value
, std::string
* new_value
,
35 std::string
* skip_until
) const override
;
38 bool purge_ttl_on_expiration_
;
39 int32_t gc_grace_period_in_seconds_
;
41 } // namespace cassandra
42 } // namespace ROCKSDB_NAMESPACE