]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/wide/wide_column_serialization.h
update ceph source to reef 18.1.2
[ceph.git] / 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).
5
6 #pragma once
7
8 #include <cstdint>
9 #include <string>
10
11 #include "rocksdb/rocksdb_namespace.h"
12 #include "rocksdb/status.h"
13 #include "rocksdb/wide_columns.h"
14
15 namespace ROCKSDB_NAMESPACE {
16
17 class Slice;
18
19 // Wide-column serialization/deserialization primitives.
20 //
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.
26 //
27 // Legend: cn = column name, cv = column value, cns = column name size, cvs =
28 // column value size.
29 //
30 // +----------+--------------+----------+-------+----------+---...
31 // | version | # of columns | cns 1 | cn 1 | cvs 1 |
32 // +----------+--------------+------------------+--------- +---...
33 // | varint32 | varint32 | varint32 | bytes | varint32 |
34 // +----------+--------------+----------+-------+----------+---...
35 //
36 // ... continued ...
37 //
38 // ...---+----------+-------+----------+-------+---...---+-------+
39 // | cns N | cn N | cvs N | cv 1 | | cv N |
40 // ...---+----------+-------+----------+-------+---...---+-------+
41 // | varint32 | bytes | varint32 | bytes | | bytes |
42 // ...---+----------+-------+----------+-------+---...---+-------+
43
44 class WideColumnSerialization {
45 public:
46 static Status Serialize(const WideColumns& columns, std::string& output);
47 static Status Serialize(const Slice& value_of_default,
48 const WideColumns& other_columns,
49 std::string& output);
50
51 static Status Deserialize(Slice& input, WideColumns& columns);
52
53 static WideColumns::const_iterator Find(const WideColumns& columns,
54 const Slice& column_name);
55 static Status GetValueOfDefaultColumn(Slice& input, Slice& value);
56
57 static constexpr uint32_t kCurrentVersion = 1;
58
59 private:
60 static Status SerializeImpl(const Slice* value_of_default,
61 const WideColumns& columns, std::string& output);
62 };
63
64 inline Status WideColumnSerialization::Serialize(const WideColumns& columns,
65 std::string& output) {
66 constexpr Slice* value_of_default = nullptr;
67
68 return SerializeImpl(value_of_default, columns, output);
69 }
70
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);
75 }
76
77 } // namespace ROCKSDB_NAMESPACE