YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksutil/write_batch_formatter.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
#include "yb/rocksutil/write_batch_formatter.h"
14
15
#include "yb/rocksdb/metadata.h"
16
#include "yb/util/bytes_formatter.h"
17
18
using std::endl;
19
using rocksdb::Status;
20
using rocksdb::SequenceNumber;
21
22
using yb::FormatBytesAsStr;
23
using yb::QuotesType;
24
using yb::BinaryOutputFormat;
25
26
namespace yb {
27
28
rocksdb::Status WriteBatchFormatter::PutCF(
29
    uint32_t column_family_id,
30
    const SliceParts& key,
31
32
    const SliceParts& value) {
32
32
  StartOutputLine(__FUNCTION__);
33
32
  OutputKey(key.TheOnlyPart());
34
32
  AddSeparator();
35
32
  OutputValue(key.TheOnlyPart(), value.TheOnlyPart());
36
32
  FinishOutputLine();
37
32
  return Status::OK();
38
32
}
39
40
rocksdb::Status WriteBatchFormatter::DeleteCF(
41
    uint32_t column_family_id,
42
0
    const Slice& key) {
43
0
  StartOutputLine(__FUNCTION__);
44
0
  OutputKey(key);
45
0
  FinishOutputLine();
46
0
  return Status::OK();
47
0
}
48
49
rocksdb::Status WriteBatchFormatter::SingleDeleteCF(
50
    uint32_t column_family_id,
51
0
    const Slice& key) {
52
0
  StartOutputLine(__FUNCTION__);
53
0
  OutputKey(key);
54
0
  FinishOutputLine();
55
0
  return Status::OK();
56
0
}
57
58
rocksdb::Status WriteBatchFormatter::MergeCF(
59
    uint32_t column_family_id,
60
    const Slice& key,
61
0
    const Slice& value) {
62
0
  StartOutputLine(__FUNCTION__);
63
0
  OutputKey(key);
64
0
  AddSeparator();
65
0
  OutputValue(key, value);
66
0
  FinishOutputLine();
67
0
  return Status::OK();
68
0
}
69
70
0
Status WriteBatchFormatter::Frontiers(const rocksdb::UserFrontiers& range) {
71
0
  StartOutputLine(__FUNCTION__, /* is_kv= */ false);
72
0
  out_ << range.ToString() << endl;
73
0
  return Status::OK();
74
0
}
75
76
32
std::string WriteBatchFormatter::FormatKey(const Slice& key) {
77
32
  return FormatSliceAsStr(key, binary_output_format_, QuotesType::kSingleQuotes);
78
32
}
79
80
32
std::string WriteBatchFormatter::FormatValue(const Slice& key, const Slice& value) {
81
  // We are ignoring the key here, but in subclasses we can use it to decide how to decode value.
82
32
  return FormatSliceAsStr(value, binary_output_format_, QuotesType::kSingleQuotes);
83
32
}
84
85
32
void WriteBatchFormatter::StartOutputLine(const char* function_name, bool is_kv) {
86
32
  out_ << line_prefix_;
87
32
  if (is_kv) {
88
32
    ++kv_index_;
89
32
    out_ << kv_index_ << ". ";
90
32
  }
91
32
  out_ << function_name;
92
32
  switch (output_format_) {
93
32
    case WriteBatchOutputFormat::kParentheses: out_ << "("; break;
94
0
    case WriteBatchOutputFormat::kArrow: out_ << ": "; break;
95
32
  }
96
32
}
97
98
32
void WriteBatchFormatter::AddSeparator() {
99
32
  switch (output_format_) {
100
32
    case WriteBatchOutputFormat::kParentheses: out_ << ", "; break;
101
0
    case WriteBatchOutputFormat::kArrow: out_ << " => "; break;
102
32
  }
103
32
}
104
105
32
void WriteBatchFormatter::OutputKey(const Slice& key) {
106
32
  out_ << FormatKey(key);
107
32
}
108
109
32
void WriteBatchFormatter::OutputValue(const Slice& key, const Slice& value) {
110
32
  out_ << FormatValue(key, value);
111
32
}
112
113
32
void WriteBatchFormatter::FinishOutputLine() {
114
32
  if (output_format_ == WriteBatchOutputFormat::kParentheses) {
115
32
    out_ << ")";
116
32
  }
117
32
  out_ << endl;
118
32
}
119
120
}  // namespace yb