YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/docdb/docdb_debug.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
14
#include "yb/docdb/docdb_debug.h"
15
16
#include "yb/docdb/docdb_fwd.h"
17
#include "yb/docdb/shared_lock_manager_fwd.h"
18
#include "yb/docdb/docdb-internal.h"
19
#include "yb/docdb/key_bounds.h"
20
#include "yb/docdb/kv_debug.h"
21
22
#include "yb/rocksdb/db.h"
23
24
#include "yb/util/bytes_formatter.h"
25
#include "yb/util/result.h"
26
27
using namespace std::placeholders;
28
29
namespace yb {
30
namespace docdb {
31
32
140k
void AppendLineToStream(const std::string& s, ostream* out) {
33
140k
  *out << s << std::endl;
34
140k
}
35
36
template <class DumpStringFunc>
37
void ProcessDumpEntry(
38
    Slice key, Slice value, IncludeBinary include_binary, StorageDbType db_type,
39
180k
    DumpStringFunc func) {
40
180k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
180k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
180k
  const KeyType key_type = GetKeyType(key, db_type);
46
180k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
180k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
180k
  } else {
50
180k
    func(Format("$0 -> $1", *key_str, *value_str));
51
180k
  }
52
180k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
180k
}
Unexecuted instantiation: _ZN2yb5docdb16ProcessDumpEntryINSt3__16__bindIPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_13basic_ostreamIcS6_EEEJRKNS2_12placeholders4__phILi1EEEPNS2_19basic_ostringstreamIcS6_S8_EEEEEEEvNS_5SliceESQ_NS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEENS0_13StorageDbTypeET_
_ZN2yb5docdb16ProcessDumpEntryINSt3__16__bindIPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_13basic_ostreamIcS6_EEEJRKNS2_12placeholders4__phILi1EEESE_EEEEEvNS_5SliceESN_NS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEENS0_13StorageDbTypeET_
Line
Count
Source
39
140k
    DumpStringFunc func) {
40
140k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
140k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
140k
  const KeyType key_type = GetKeyType(key, db_type);
46
140k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
140k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
140k
  } else {
50
140k
    func(Format("$0 -> $1", *key_str, *value_str));
51
140k
  }
52
140k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
140k
}
_ZN2yb5docdb16ProcessDumpEntryINSt3__16__bindIRPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_13unordered_setIS9_NS2_4hashIS9_EENS2_8equal_toIS9_EENS7_IS9_EEEEEJRKNS2_12placeholders4__phILi1EEERSJ_EEEEEvNS_5SliceESU_NS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEENS0_13StorageDbTypeET_
Line
Count
Source
39
40.0k
    DumpStringFunc func) {
40
40.0k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
40.0k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
40.0k
  const KeyType key_type = GetKeyType(key, db_type);
46
40.0k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
40.0k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
40.0k
  } else {
50
40.0k
    func(Format("$0 -> $1", *key_str, *value_str));
51
40.0k
  }
52
40.0k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
40.0k
}
Unexecuted instantiation: _ZN2yb5docdb16ProcessDumpEntryINSt3__16__bindIRPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_6vectorIS9_NS7_IS9_EEEEEJRKNS2_12placeholders4__phILi1EEERSF_EEEEEvNS_5SliceESQ_NS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEENS0_13StorageDbTypeET_
56
57
0
std::string EntryToString(const Slice& key, const Slice& value, StorageDbType db_type) {
58
0
  std::ostringstream out;
59
0
  ProcessDumpEntry(
60
0
      key, value, IncludeBinary::kFalse, db_type, std::bind(&AppendLineToStream, _1, &out));
61
0
  return out.str();
62
0
}
63
64
0
std::string EntryToString(const rocksdb::Iterator& iterator, StorageDbType db_type) {
65
0
  return EntryToString(iterator.key(), iterator.value(), db_type);
66
0
}
67
68
template <class DumpStringFunc>
69
void DocDBDebugDump(rocksdb::DB* rocksdb, StorageDbType db_type, IncludeBinary include_binary,
70
14
    DumpStringFunc dump_func) {
71
14
  rocksdb::ReadOptions read_opts;
72
14
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
14
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
14
  iter->SeekToFirst();
75
76
180k
  while (iter->Valid()) {
77
180k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
180k
    iter->Next();
79
180k
  }
80
14
}
_ZN2yb5docdb14DocDBDebugDumpINSt3__16__bindIPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_13basic_ostreamIcS6_EEEJRKNS2_12placeholders4__phILi1EEESE_EEEEEvPN7rocksdb2DBENS0_13StorageDbTypeENS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEET_
Line
Count
Source
70
7
    DumpStringFunc dump_func) {
71
7
  rocksdb::ReadOptions read_opts;
72
7
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
7
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
7
  iter->SeekToFirst();
75
76
140k
  while (iter->Valid()) {
77
140k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
140k
    iter->Next();
79
140k
  }
80
7
}
_ZN2yb5docdb14DocDBDebugDumpINSt3__16__bindIRPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_13unordered_setIS9_NS2_4hashIS9_EENS2_8equal_toIS9_EENS7_IS9_EEEEEJRKNS2_12placeholders4__phILi1EEERSJ_EEEEEvPN7rocksdb2DBENS0_13StorageDbTypeENS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEET_
Line
Count
Source
70
7
    DumpStringFunc dump_func) {
71
7
  rocksdb::ReadOptions read_opts;
72
7
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
7
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
7
  iter->SeekToFirst();
75
76
40.0k
  while (iter->Valid()) {
77
40.0k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
40.0k
    iter->Next();
79
40.0k
  }
80
7
}
Unexecuted instantiation: _ZN2yb5docdb14DocDBDebugDumpINSt3__16__bindIRPFvRKNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEPNS2_6vectorIS9_NS7_IS9_EEEEEJRKNS2_12placeholders4__phILi1EEERSF_EEEEEvPN7rocksdb2DBENS0_13StorageDbTypeENS_17StronglyTypedBoolINS0_17IncludeBinary_TagEEET_
81
82
void DocDBDebugDump(rocksdb::DB* rocksdb, ostream& out, StorageDbType db_type,
83
7
                    IncludeBinary include_binary) {
84
7
  DocDBDebugDump(rocksdb, db_type, include_binary, std::bind(&AppendLineToStream, _1, &out));
85
7
}
86
87
7
std::string DocDBDebugDumpToStr(DocDB docdb, IncludeBinary include_binary) {
88
7
  std::stringstream ss;
89
7
  DocDBDebugDump(docdb.regular, ss, StorageDbType::kRegular, include_binary);
90
7
  if (docdb.intents) {
91
0
    DocDBDebugDump(docdb.intents, ss, StorageDbType::kIntents, include_binary);
92
0
  }
93
7
  return ss.str();
94
7
}
95
96
std::string DocDBDebugDumpToStr(
97
    rocksdb::DB* rocksdb, StorageDbType db_type,
98
0
    IncludeBinary include_binary) {
99
0
  std::stringstream ss;
100
0
  DocDBDebugDump(rocksdb, ss, db_type, include_binary);
101
0
  return ss.str();
102
0
}
103
104
40.0k
void AppendToContainer(const std::string& s, std::unordered_set<std::string>* out) {
105
40.0k
  out->insert(s);
106
40.0k
}
107
108
0
void AppendToContainer(const std::string& s, std::vector<std::string>* out) {
109
0
  out->push_back(s);
110
0
}
111
112
template <class T>
113
7
void DocDBDebugDumpToContainer(rocksdb::DB* rocksdb, T* out, StorageDbType db_type) {
114
7
  void (*f)(const std::string&, T*) = AppendToContainer;
115
7
  DocDBDebugDump(rocksdb, db_type, IncludeBinary::kFalse, std::bind(f, _1, out));
116
7
}
_ZN2yb5docdb25DocDBDebugDumpToContainerINSt3__113unordered_setINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS2_4hashIS9_EENS2_8equal_toIS9_EENS7_IS9_EEEEEEvPN7rocksdb2DBEPT_NS0_13StorageDbTypeE
Line
Count
Source
113
7
void DocDBDebugDumpToContainer(rocksdb::DB* rocksdb, T* out, StorageDbType db_type) {
114
7
  void (*f)(const std::string&, T*) = AppendToContainer;
115
7
  DocDBDebugDump(rocksdb, db_type, IncludeBinary::kFalse, std::bind(f, _1, out));
116
7
}
Unexecuted instantiation: _ZN2yb5docdb25DocDBDebugDumpToContainerINSt3__16vectorINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS7_IS9_EEEEEEvPN7rocksdb2DBEPT_NS0_13StorageDbTypeE
117
118
7
void DocDBDebugDumpToContainer(DocDB docdb, std::unordered_set<std::string>* out) {
119
7
  DocDBDebugDumpToContainer(docdb.regular, out, StorageDbType::kRegular);
120
7
  if (docdb.intents) {
121
0
    DocDBDebugDumpToContainer(docdb.intents, out, StorageDbType::kIntents);
122
0
  }
123
7
}
124
125
0
void DumpRocksDBToLog(rocksdb::DB* rocksdb, StorageDbType db_type, const std::string& log_prefix) {
126
0
  std::vector<std::string> lines;
127
0
  DocDBDebugDumpToContainer(rocksdb, &lines, db_type);
128
0
  LOG(INFO) << log_prefix << AsString(db_type) << " DB dump:";
129
0
  for (const auto& line : lines) {
130
0
    LOG(INFO) << log_prefix << "  " << line;
131
0
  }
132
0
}
133
134
}  // namespace docdb
135
}  // namespace yb