]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/wide/wide_column_serialization.h
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
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).
11 #include "rocksdb/rocksdb_namespace.h"
12 #include "rocksdb/status.h"
13 #include "rocksdb/wide_columns.h"
15 namespace ROCKSDB_NAMESPACE
{
19 // Wide-column serialization/deserialization primitives.
21 // The two main parts of the layout are 1) a sorted index containing the column
22 // names and column value sizes and 2) the column values themselves. Keeping the
23 // index and the values separate will enable selectively reading column values
24 // down the line. Note that currently the index has to be fully parsed in order
25 // to find out the offset of each column value.
27 // Legend: cn = column name, cv = column value, cns = column name size, cvs =
30 // +----------+--------------+----------+-------+----------+---...
31 // | version | # of columns | cns 1 | cn 1 | cvs 1 |
32 // +----------+--------------+------------------+--------- +---...
33 // | varint32 | varint32 | varint32 | bytes | varint32 |
34 // +----------+--------------+----------+-------+----------+---...
38 // ...---+----------+-------+----------+-------+---...---+-------+
39 // | cns N | cn N | cvs N | cv 1 | | cv N |
40 // ...---+----------+-------+----------+-------+---...---+-------+
41 // | varint32 | bytes | varint32 | bytes | | bytes |
42 // ...---+----------+-------+----------+-------+---...---+-------+
44 class WideColumnSerialization
{
46 static Status
Serialize(const WideColumns
& columns
, std::string
& output
);
47 static Status
Serialize(const Slice
& value_of_default
,
48 const WideColumns
& other_columns
,
51 static Status
Deserialize(Slice
& input
, WideColumns
& columns
);
53 static WideColumns::const_iterator
Find(const WideColumns
& columns
,
54 const Slice
& column_name
);
55 static Status
GetValueOfDefaultColumn(Slice
& input
, Slice
& value
);
57 static constexpr uint32_t kCurrentVersion
= 1;
60 static Status
SerializeImpl(const Slice
* value_of_default
,
61 const WideColumns
& columns
, std::string
& output
);
64 inline Status
WideColumnSerialization::Serialize(const WideColumns
& columns
,
65 std::string
& output
) {
66 constexpr Slice
* value_of_default
= nullptr;
68 return SerializeImpl(value_of_default
, columns
, output
);
71 inline Status
WideColumnSerialization::Serialize(
72 const Slice
& value_of_default
, const WideColumns
& other_columns
,
73 std::string
& output
) {
74 return SerializeImpl(&value_of_default
, other_columns
, output
);
77 } // namespace ROCKSDB_NAMESPACE