/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 | 0 | const SliceParts& value) { |
32 | 0 | StartOutputLine(__FUNCTION__); |
33 | 0 | OutputKey(key.TheOnlyPart()); |
34 | 0 | AddSeparator(); |
35 | 0 | OutputValue(key.TheOnlyPart(), value.TheOnlyPart()); |
36 | 0 | FinishOutputLine(); |
37 | 0 | return Status::OK(); |
38 | 0 | } |
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 | 0 | std::string WriteBatchFormatter::FormatKey(const Slice& key) { |
77 | 0 | return FormatSliceAsStr(key, binary_output_format_, QuotesType::kSingleQuotes); |
78 | 0 | } |
79 | | |
80 | 0 | 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 | 0 | return FormatSliceAsStr(value, binary_output_format_, QuotesType::kSingleQuotes); |
83 | 0 | } |
84 | | |
85 | 0 | void WriteBatchFormatter::StartOutputLine(const char* function_name, bool is_kv) { |
86 | 0 | out_ << line_prefix_; |
87 | 0 | if (is_kv) { |
88 | 0 | ++kv_index_; |
89 | 0 | out_ << kv_index_ << ". "; |
90 | 0 | } |
91 | 0 | out_ << function_name; |
92 | 0 | switch (output_format_) { |
93 | 0 | case WriteBatchOutputFormat::kParentheses: out_ << "("; break; |
94 | 0 | case WriteBatchOutputFormat::kArrow: out_ << ": "; break; |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | 0 | void WriteBatchFormatter::AddSeparator() { |
99 | 0 | switch (output_format_) { |
100 | 0 | case WriteBatchOutputFormat::kParentheses: out_ << ", "; break; |
101 | 0 | case WriteBatchOutputFormat::kArrow: out_ << " => "; break; |
102 | 0 | } |
103 | 0 | } |
104 | | |
105 | 0 | void WriteBatchFormatter::OutputKey(const Slice& key) { |
106 | 0 | out_ << FormatKey(key); |
107 | 0 | } |
108 | | |
109 | 0 | void WriteBatchFormatter::OutputValue(const Slice& key, const Slice& value) { |
110 | 0 | out_ << FormatValue(key, value); |
111 | 0 | } |
112 | | |
113 | 0 | void WriteBatchFormatter::FinishOutputLine() { |
114 | 0 | if (output_format_ == WriteBatchOutputFormat::kParentheses) { |
115 | 0 | out_ << ")"; |
116 | 0 | } |
117 | 0 | out_ << endl; |
118 | 0 | } |
119 | | |
120 | | } // namespace yb |