]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/utilities/blob_db/blob_log_format.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / utilities / blob_db / blob_log_format.h
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// Log format information shared by reader and writer.
7
8#pragma once
9
10#ifndef ROCKSDB_LITE
11
12#include <limits>
13#include <utility>
14#include "rocksdb/options.h"
15#include "rocksdb/slice.h"
16#include "rocksdb/status.h"
17#include "rocksdb/types.h"
18
19namespace rocksdb {
20namespace blob_db {
21
22constexpr uint32_t kMagicNumber = 2395959; // 0x00248f37
23constexpr uint32_t kVersion1 = 1;
24constexpr uint64_t kNoExpiration = std::numeric_limits<uint64_t>::max();
25
26using ExpirationRange = std::pair<uint64_t, uint64_t>;
27
28// Format of blob log file header (30 bytes):
29//
30// +--------------+---------+---------+-------+-------------+-------------------+
31// | magic number | version | cf id | flags | compression | expiration range |
32// +--------------+---------+---------+-------+-------------+-------------------+
33// | Fixed32 | Fixed32 | Fixed32 | char | char | Fixed64 Fixed64 |
34// +--------------+---------+---------+-------+-------------+-------------------+
35//
36// List of flags:
37// has_ttl: Whether the file contain TTL data.
38//
39// Expiration range in the header is a rough range based on
40// blob_db_options.ttl_range_secs.
41struct BlobLogHeader {
42 static constexpr size_t kSize = 30;
43
44 uint32_t version = kVersion1;
45 uint32_t column_family_id = 0;
46 CompressionType compression = kNoCompression;
47 bool has_ttl = false;
48 ExpirationRange expiration_range = std::make_pair(0, 0);
49
50 void EncodeTo(std::string* dst);
51
52 Status DecodeFrom(Slice slice);
53};
54
55// Format of blob log file footer (32 bytes):
56//
57// +--------------+------------+-------------------+------------+
58// | magic number | blob count | expiration range | footer CRC |
59// +--------------+------------+-------------------+------------+
60// | Fixed32 | Fixed64 | Fixed64 + Fixed64 | Fixed32 |
61// +--------------+------------+-------------------+------------+
62//
63// The footer will be presented only when the blob file is properly closed.
64//
65// Unlike the same field in file header, expiration range in the footer is the
66// range of smallest and largest expiration of the data in this file.
67struct BlobLogFooter {
68 static constexpr size_t kSize = 32;
69
70 uint64_t blob_count = 0;
71 ExpirationRange expiration_range = std::make_pair(0, 0);
72 uint32_t crc = 0;
73
74 void EncodeTo(std::string* dst);
75
76 Status DecodeFrom(Slice slice);
77};
78
79// Blob record format (32 bytes header + key + value):
80//
81// +------------+--------------+------------+------------+----------+---------+-----------+
82// | key length | value length | expiration | header CRC | blob CRC | key | value |
83// +------------+--------------+------------+------------+----------+---------+-----------+
84// | Fixed64 | Fixed64 | Fixed64 | Fixed32 | Fixed32 | key len | value len |
85// +------------+--------------+------------+------------+----------+---------+-----------+
86//
87// If file has has_ttl = false, expiration field is always 0, and the blob
88// doesn't has expiration.
89//
90// Also note that if compression is used, value is compressed value and value
91// length is compressed value length.
92//
93// Header CRC is the checksum of (key_len + val_len + expiration), while
94// blob CRC is the checksum of (key + value).
95//
96// We could use variable length encoding (Varint64) to save more space, but it
97// make reader more complicated.
98struct BlobLogRecord {
99 // header include fields up to blob CRC
100 static constexpr size_t kHeaderSize = 32;
101
102 uint64_t key_size = 0;
103 uint64_t value_size = 0;
104 uint64_t expiration = 0;
105 uint32_t header_crc = 0;
106 uint32_t blob_crc = 0;
107 Slice key;
108 Slice value;
109 std::string key_buf;
110 std::string value_buf;
111
112 uint64_t record_size() const { return kHeaderSize + key_size + value_size; }
113
114 void EncodeHeaderTo(std::string* dst);
115
116 Status DecodeHeaderFrom(Slice src);
117
118 Status CheckBlobCRC() const;
119};
120
121} // namespace blob_db
122} // namespace rocksdb
123#endif // ROCKSDB_LITE