]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/utilities/cassandra/format.h
1 // Copyright (c) 2017-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).
7 * The encoding of Cassandra Row Value.
9 * A Cassandra Row Value could either be a row tombstone,
10 * or contains multiple columns, it has following fields:
13 * int32_t local_deletion_time; // Time in second when the row is deleted,
14 * // only used for Cassandra tombstone gc.
15 * int64_t marked_for_delete_at; // Ms that marked this row is deleted.
16 * struct column_base columns[]; // For non tombstone row, all columns
20 * If the local_deletion_time and marked_for_delete_at is set, then this is
21 * a tombstone, otherwise it contains multiple columns.
23 * There are three type of Columns: Normal Column, Expiring Column and Column
24 * Tombstone, which have following fields:
26 * // Identify the type of the column.
28 * DELETION_MASK = 0x01,
29 * EXPIRATION_MASK = 0x02,
36 * int32_t value_length;
37 * char value[value_length];
40 * struct expiring_column {
41 * int8_t mask = mask.EXPIRATION_MASK;
44 * int32_t value_length;
45 * char value[value_length];
49 * struct tombstone_column {
50 * int8_t mask = mask.DELETION_MASK;
52 * int32_t local_deletion_time; // Similar to row_value's field.
53 * int64_t marked_for_delete_at;
61 #include "rocksdb/merge_operator.h"
62 #include "rocksdb/slice.h"
64 namespace ROCKSDB_NAMESPACE
{
67 // Identify the type of the column.
70 EXPIRATION_MASK
= 0x02,
76 ColumnBase(int8_t mask
, int8_t index
);
77 virtual ~ColumnBase() = default;
79 virtual int64_t Timestamp() const = 0;
80 virtual int8_t Mask() const;
81 virtual int8_t Index() const;
82 virtual std::size_t Size() const;
83 virtual void Serialize(std::string
* dest
) const;
84 static std::shared_ptr
<ColumnBase
> Deserialize(const char* src
,
92 class Column
: public ColumnBase
{
94 Column(int8_t mask
, int8_t index
, int64_t timestamp
,
95 int32_t value_size
, const char* value
);
97 virtual int64_t Timestamp() const override
;
98 virtual std::size_t Size() const override
;
99 virtual void Serialize(std::string
* dest
) const override
;
100 static std::shared_ptr
<Column
> Deserialize(const char* src
,
109 class Tombstone
: public ColumnBase
{
111 Tombstone(int8_t mask
, int8_t index
,
112 int32_t local_deletion_time
, int64_t marked_for_delete_at
);
114 virtual int64_t Timestamp() const override
;
115 virtual std::size_t Size() const override
;
116 virtual void Serialize(std::string
* dest
) const override
;
117 bool Collectable(int32_t gc_grace_period
) const;
118 static std::shared_ptr
<Tombstone
> Deserialize(const char* src
,
122 int32_t local_deletion_time_
;
123 int64_t marked_for_delete_at_
;
126 class ExpiringColumn
: public Column
{
128 ExpiringColumn(int8_t mask
, int8_t index
, int64_t timestamp
,
129 int32_t value_size
, const char* value
, int32_t ttl
);
131 virtual std::size_t Size() const override
;
132 virtual void Serialize(std::string
* dest
) const override
;
133 bool Expired() const;
134 std::shared_ptr
<Tombstone
> ToTombstone() const;
136 static std::shared_ptr
<ExpiringColumn
> Deserialize(const char* src
,
141 std::chrono::time_point
<std::chrono::system_clock
> TimePoint() const;
142 std::chrono::seconds
Ttl() const;
145 typedef std::vector
<std::shared_ptr
<ColumnBase
>> Columns
;
149 // Create a Row Tombstone.
150 RowValue(int32_t local_deletion_time
, int64_t marked_for_delete_at
);
151 // Create a Row containing columns.
152 RowValue(Columns columns
,
153 int64_t last_modified_time
);
154 RowValue(const RowValue
& /*that*/) = delete;
155 RowValue(RowValue
&& /*that*/) noexcept
= default;
156 RowValue
& operator=(const RowValue
& /*that*/) = delete;
157 RowValue
& operator=(RowValue
&& /*that*/) = default;
159 std::size_t Size() const;
160 bool IsTombstone() const;
161 // For Tombstone this returns the marked_for_delete_at_,
162 // otherwise it returns the max timestamp of containing columns.
163 int64_t LastModifiedTime() const;
164 void Serialize(std::string
* dest
) const;
165 RowValue
RemoveExpiredColumns(bool* changed
) const;
166 RowValue
ConvertExpiredColumnsToTombstones(bool* changed
) const;
167 RowValue
RemoveTombstones(int32_t gc_grace_period
) const;
170 static RowValue
Deserialize(const char* src
, std::size_t size
);
171 // Merge multiple rows according to their timestamp.
172 static RowValue
Merge(std::vector
<RowValue
>&& values
);
174 const Columns
& get_columns() { return columns_
; }
177 int32_t local_deletion_time_
;
178 int64_t marked_for_delete_at_
;
180 int64_t last_modified_time_
;
183 } // namepsace cassandrda
184 } // namespace ROCKSDB_NAMESPACE