]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/blob/blob_file_addition.cc
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).
6 #include "db/blob/blob_file_addition.h"
11 #include "logging/event_logger.h"
12 #include "rocksdb/slice.h"
13 #include "rocksdb/status.h"
14 #include "test_util/sync_point.h"
15 #include "util/coding.h"
17 namespace ROCKSDB_NAMESPACE
{
19 // Tags for custom fields. Note that these get persisted in the manifest,
20 // so existing tags should not be modified.
21 enum BlobFileAddition::CustomFieldTags
: uint32_t {
24 // Add forward compatible fields here
26 /////////////////////////////////////////////////////////////////////
28 kForwardIncompatibleMask
= 1 << 6,
30 // Add forward incompatible fields here
33 void BlobFileAddition::EncodeTo(std::string
* output
) const {
34 PutVarint64(output
, blob_file_number_
);
35 PutVarint64(output
, total_blob_count_
);
36 PutVarint64(output
, total_blob_bytes_
);
37 PutLengthPrefixedSlice(output
, checksum_method_
);
38 PutLengthPrefixedSlice(output
, checksum_value_
);
40 // Encode any custom fields here. The format to use is a Varint32 tag (see
41 // CustomFieldTags above) followed by a length prefixed slice. Unknown custom
42 // fields will be ignored during decoding unless they're in the forward
43 // incompatible range.
45 TEST_SYNC_POINT_CALLBACK("BlobFileAddition::EncodeTo::CustomFields", output
);
47 PutVarint32(output
, kEndMarker
);
50 Status
BlobFileAddition::DecodeFrom(Slice
* input
) {
51 constexpr char class_name
[] = "BlobFileAddition";
53 if (!GetVarint64(input
, &blob_file_number_
)) {
54 return Status::Corruption(class_name
, "Error decoding blob file number");
57 if (!GetVarint64(input
, &total_blob_count_
)) {
58 return Status::Corruption(class_name
, "Error decoding total blob count");
61 if (!GetVarint64(input
, &total_blob_bytes_
)) {
62 return Status::Corruption(class_name
, "Error decoding total blob bytes");
65 Slice checksum_method
;
66 if (!GetLengthPrefixedSlice(input
, &checksum_method
)) {
67 return Status::Corruption(class_name
, "Error decoding checksum method");
69 checksum_method_
= checksum_method
.ToString();
72 if (!GetLengthPrefixedSlice(input
, &checksum_value
)) {
73 return Status::Corruption(class_name
, "Error decoding checksum value");
75 checksum_value_
= checksum_value
.ToString();
78 uint32_t custom_field_tag
= 0;
79 if (!GetVarint32(input
, &custom_field_tag
)) {
80 return Status::Corruption(class_name
, "Error decoding custom field tag");
83 if (custom_field_tag
== kEndMarker
) {
87 if (custom_field_tag
& kForwardIncompatibleMask
) {
88 return Status::Corruption(
89 class_name
, "Forward incompatible custom field encountered");
92 Slice custom_field_value
;
93 if (!GetLengthPrefixedSlice(input
, &custom_field_value
)) {
94 return Status::Corruption(class_name
,
95 "Error decoding custom field value");
102 std::string
BlobFileAddition::DebugString() const {
103 std::ostringstream oss
;
110 std::string
BlobFileAddition::DebugJSON() const {
120 bool operator==(const BlobFileAddition
& lhs
, const BlobFileAddition
& rhs
) {
121 return lhs
.GetBlobFileNumber() == rhs
.GetBlobFileNumber() &&
122 lhs
.GetTotalBlobCount() == rhs
.GetTotalBlobCount() &&
123 lhs
.GetTotalBlobBytes() == rhs
.GetTotalBlobBytes() &&
124 lhs
.GetChecksumMethod() == rhs
.GetChecksumMethod() &&
125 lhs
.GetChecksumValue() == rhs
.GetChecksumValue();
128 bool operator!=(const BlobFileAddition
& lhs
, const BlobFileAddition
& rhs
) {
129 return !(lhs
== rhs
);
132 std::ostream
& operator<<(std::ostream
& os
,
133 const BlobFileAddition
& blob_file_addition
) {
134 os
<< "blob_file_number: " << blob_file_addition
.GetBlobFileNumber()
135 << " total_blob_count: " << blob_file_addition
.GetTotalBlobCount()
136 << " total_blob_bytes: " << blob_file_addition
.GetTotalBlobBytes()
137 << " checksum_method: " << blob_file_addition
.GetChecksumMethod()
138 << " checksum_value: "
139 << Slice(blob_file_addition
.GetChecksumValue()).ToString(/* hex */ true);
144 JSONWriter
& operator<<(JSONWriter
& jw
,
145 const BlobFileAddition
& blob_file_addition
) {
146 jw
<< "BlobFileNumber" << blob_file_addition
.GetBlobFileNumber()
147 << "TotalBlobCount" << blob_file_addition
.GetTotalBlobCount()
148 << "TotalBlobBytes" << blob_file_addition
.GetTotalBlobBytes()
149 << "ChecksumMethod" << blob_file_addition
.GetChecksumMethod()
151 << Slice(blob_file_addition
.GetChecksumValue()).ToString(/* hex */ true);
156 } // namespace ROCKSDB_NAMESPACE