YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/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
142k
void AppendLineToStream(const std::string& s, ostream* out) {
33
142k
  *out << s << std::endl;
34
142k
}
35
36
template <class DumpStringFunc>
37
void ProcessDumpEntry(
38
    Slice key, Slice value, IncludeBinary include_binary, StorageDbType db_type,
39
186k
    DumpStringFunc func) {
40
186k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
186k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
186k
  const KeyType key_type = GetKeyType(key, db_type);
46
186k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
186k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
186k
  } else {
50
186k
    func(Format("$0 -> $1", *key_str, *value_str));
51
186k
  }
52
186k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
186k
}
Unexecuted instantiation: void yb::docdb::ProcessDumpEntry<std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >(yb::Slice, yb::Slice, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, yb::docdb::StorageDbType, std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >*>)
void yb::docdb::ProcessDumpEntry<std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*> >(yb::Slice, yb::Slice, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, yb::docdb::StorageDbType, std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*>)
Line
Count
Source
39
142k
    DumpStringFunc func) {
40
142k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
142k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
142k
  const KeyType key_type = GetKeyType(key, db_type);
46
142k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
142k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
142k
  } else {
50
142k
    func(Format("$0 -> $1", *key_str, *value_str));
51
142k
  }
52
142k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
142k
}
void yb::docdb::ProcessDumpEntry<std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&> >(yb::Slice, yb::Slice, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, yb::docdb::StorageDbType, std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&>)
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
}
void yb::docdb::ProcessDumpEntry<std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&> >(yb::Slice, yb::Slice, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, yb::docdb::StorageDbType, std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&>)
Line
Count
Source
39
3.79k
    DumpStringFunc func) {
40
3.79k
  const auto key_str = DocDBKeyToDebugStr(key, db_type);
41
3.79k
  if (!key_str.ok()) {
42
0
    func(key_str.status().ToString());
43
0
    return;
44
0
  }
45
3.79k
  const KeyType key_type = GetKeyType(key, db_type);
46
3.79k
  Result<std::string> value_str = DocDBValueToDebugStr(key_type, *key_str, value);
47
3.79k
  if (!value_str.ok()) {
48
0
    func(value_str.status().CloneAndAppend(strings::Substitute(". Key: $0", *key_str)).ToString());
49
3.79k
  } else {
50
3.79k
    func(Format("$0 -> $1", *key_str, *value_str));
51
3.79k
  }
52
3.79k
  if (include_binary) {
53
0
    func(Format("$0 -> $1\n", FormatSliceAsStr(key), FormatSliceAsStr(value)));
54
0
  }
55
3.79k
}
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
666
    DumpStringFunc dump_func) {
71
666
  rocksdb::ReadOptions read_opts;
72
666
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
666
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
666
  iter->SeekToFirst();
75
76
187k
  while (iter->Valid()) {
77
186k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
186k
    iter->Next();
79
186k
  }
80
666
}
void yb::docdb::DocDBDebugDump<std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*> >(rocksdb::DB*, yb::docdb::StorageDbType, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, std::__1::__bind<void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*), std::__1::placeholders::__ph<1> const&, std::__1::basic_ostream<char, std::__1::char_traits<char> >*>)
Line
Count
Source
70
627
    DumpStringFunc dump_func) {
71
627
  rocksdb::ReadOptions read_opts;
72
627
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
627
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
627
  iter->SeekToFirst();
75
76
143k
  while (iter->Valid()) {
77
142k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
142k
    iter->Next();
79
142k
  }
80
627
}
void yb::docdb::DocDBDebugDump<std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&> >(rocksdb::DB*, yb::docdb::StorageDbType, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&>)
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
}
void yb::docdb::DocDBDebugDump<std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&> >(rocksdb::DB*, yb::docdb::StorageDbType, yb::StronglyTypedBool<yb::docdb::IncludeBinary_Tag>, std::__1::__bind<void (*&)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*), std::__1::placeholders::__ph<1> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*&>)
Line
Count
Source
70
32
    DumpStringFunc dump_func) {
71
32
  rocksdb::ReadOptions read_opts;
72
32
  read_opts.query_id = rocksdb::kDefaultQueryId;
73
32
  auto iter = std::unique_ptr<rocksdb::Iterator>(rocksdb->NewIterator(read_opts));
74
32
  iter->SeekToFirst();
75
76
3.82k
  while (iter->Valid()) {
77
3.79k
    ProcessDumpEntry(iter->key(), iter->value(), include_binary, db_type, dump_func);
78
3.79k
    iter->Next();
79
3.79k
  }
80
32
}
81
82
void DocDBDebugDump(rocksdb::DB* rocksdb, ostream& out, StorageDbType db_type,
83
627
                    IncludeBinary include_binary) {
84
627
  DocDBDebugDump(rocksdb, db_type, include_binary, std::bind(&AppendLineToStream, _1, &out));
85
627
}
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
620
    IncludeBinary include_binary) {
99
620
  std::stringstream ss;
100
620
  DocDBDebugDump(rocksdb, ss, db_type, include_binary);
101
620
  return ss.str();
102
620
}
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
3.79k
void AppendToContainer(const std::string& s, std::vector<std::string>* out) {
109
3.79k
  out->push_back(s);
110
3.79k
}
111
112
template <class T>
113
39
void DocDBDebugDumpToContainer(rocksdb::DB* rocksdb, T* out, StorageDbType db_type) {
114
39
  void (*f)(const std::string&, T*) = AppendToContainer;
115
39
  DocDBDebugDump(rocksdb, db_type, IncludeBinary::kFalse, std::bind(f, _1, out));
116
39
}
void yb::docdb::DocDBDebugDumpToContainer<std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >(rocksdb::DB*, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*, yb::docdb::StorageDbType)
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
}
void yb::docdb::DocDBDebugDumpToContainer<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >(rocksdb::DB*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >*, yb::docdb::StorageDbType)
Line
Count
Source
113
32
void DocDBDebugDumpToContainer(rocksdb::DB* rocksdb, T* out, StorageDbType db_type) {
114
32
  void (*f)(const std::string&, T*) = AppendToContainer;
115
32
  DocDBDebugDump(rocksdb, db_type, IncludeBinary::kFalse, std::bind(f, _1, out));
116
32
}
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
32
void DumpRocksDBToLog(rocksdb::DB* rocksdb, StorageDbType db_type, const std::string& log_prefix) {
126
32
  std::vector<std::string> lines;
127
32
  DocDBDebugDumpToContainer(rocksdb, &lines, db_type);
128
32
  LOG(INFO) << log_prefix << AsString(db_type) << " DB dump:";
129
3.79k
  for (const auto& line : lines) {
130
3.79k
    LOG(INFO) << log_prefix << "  " << line;
131
3.79k
  }
132
32
}
133
134
}  // namespace docdb
135
}  // namespace yb