YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/table_properties.cc
Line
Count
Source (jump to first uncovered line)
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
21
#include "yb/rocksdb/table_properties.h"
22
#include "yb/rocksdb/iterator.h"
23
#include "yb/rocksdb/port/port.h"
24
#include "yb/rocksdb/table/internal_iterator.h"
25
#include "yb/util/string_util.h"
26
27
namespace rocksdb {
28
29
const uint32_t TablePropertiesCollectorFactory::Context::kUnknownColumnFamily =
30
    port::kMaxInt32;
31
32
namespace {
33
  void AppendProperty(
34
      std::string* props,
35
      const std::string& key,
36
      const std::string& value,
37
      const std::string& prop_delim,
38
11.2k
      const std::string& kv_delim) {
39
11.2k
    props->append(key);
40
11.2k
    props->append(kv_delim);
41
11.2k
    props->append(value);
42
11.2k
    props->append(prop_delim);
43
11.2k
  }
44
45
  template <class TValue>
46
  void AppendProperty(
47
      std::string* props,
48
      const std::string& key,
49
      const TValue& value,
50
      const std::string& prop_delim,
51
10.4k
      const std::string& kv_delim) {
52
10.4k
    AppendProperty(
53
10.4k
        props, key, ToString(value), prop_delim, kv_delim
54
10.4k
    );
55
10.4k
  }
table_properties.cc:void rocksdb::(anonymous namespace)::AppendProperty<unsigned long long>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
51
8.87k
      const std::string& kv_delim) {
52
8.87k
    AppendProperty(
53
8.87k
        props, key, ToString(value), prop_delim, kv_delim
54
8.87k
    );
55
8.87k
  }
table_properties.cc:void rocksdb::(anonymous namespace)::AppendProperty<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
51
1.61k
      const std::string& kv_delim) {
52
1.61k
    AppendProperty(
53
1.61k
        props, key, ToString(value), prop_delim, kv_delim
54
1.61k
    );
55
1.61k
  }
56
} // namespace
57
58
std::string TableProperties::ToString(
59
    const std::string& prop_delim,
60
807
    const std::string& kv_delim) const {
61
807
  std::string result;
62
807
  result.reserve(1024);
63
64
  // Basic Info
65
807
  AppendProperty(&result, "# data blocks", num_data_blocks, prop_delim,
66
807
                 kv_delim);
67
807
  AppendProperty(&result, "# data index blocks", num_data_index_blocks, prop_delim,
68
807
      kv_delim);
69
807
  AppendProperty(&result, "# filter blocks", num_filter_blocks, prop_delim,
70
807
      kv_delim);
71
807
  AppendProperty(&result, "# entries", num_entries, prop_delim, kv_delim);
72
73
807
  AppendProperty(&result, "raw key size", raw_key_size, prop_delim, kv_delim);
74
807
  AppendProperty(&result, "raw average key size",
75
807
                 num_entries != 0 ? 
1.0 * raw_key_size / num_entries207
:
0.0600
,
76
807
                 prop_delim, kv_delim);
77
807
  AppendProperty(&result, "raw value size", raw_value_size, prop_delim,
78
807
                 kv_delim);
79
807
  AppendProperty(&result, "raw average value size",
80
807
                 num_entries != 0 ? 
1.0 * raw_value_size / num_entries207
:
0.0600
,
81
807
                 prop_delim, kv_delim);
82
83
807
  AppendProperty(&result, "data blocks total size", data_size, prop_delim, kv_delim);
84
807
  AppendProperty(&result, "data index size", data_index_size, prop_delim, kv_delim);
85
807
  AppendProperty(&result, "filter blocks total size", filter_size, prop_delim, kv_delim);
86
807
  AppendProperty(&result, "filter index block size", filter_index_size, prop_delim, kv_delim);
87
807
  AppendProperty(
88
807
      &result, "(estimated) table size", data_size + data_index_size + filter_size, prop_delim,
89
807
      kv_delim);
90
91
807
  AppendProperty(
92
807
      &result, "filter policy name",
93
807
      filter_policy_name.empty() ? 
std::string("N/A")804
:
filter_policy_name3
,
94
807
      prop_delim, kv_delim);
95
96
807
  return result;
97
807
}
98
99
5.76k
void TableProperties::Add(const TableProperties& tp) {
100
5.76k
  data_size += tp.data_size;
101
5.76k
  data_index_size += tp.data_index_size;
102
5.76k
  filter_size += tp.filter_size;
103
5.76k
  filter_index_size += tp.filter_index_size;
104
5.76k
  raw_key_size += tp.raw_key_size;
105
5.76k
  raw_value_size += tp.raw_value_size;
106
5.76k
  num_data_blocks += tp.num_data_blocks;
107
5.76k
  num_filter_blocks += tp.num_filter_blocks;
108
5.76k
  num_data_index_blocks += tp.num_data_index_blocks;
109
5.76k
  num_entries += tp.num_entries;
110
5.76k
}
111
112
const std::string TablePropertiesNames::kDataSize  =
113
    "rocksdb.data.size";
114
const std::string TablePropertiesNames::kDataIndexSize =
115
    "rocksdb.data.index.size";
116
const std::string TablePropertiesNames::kFilterSize =
117
    "rocksdb.filter.size";
118
const std::string TablePropertiesNames::kFilterIndexSize =
119
    "rocksdb.filter.index.size";
120
const std::string TablePropertiesNames::kRawKeySize =
121
    "rocksdb.raw.key.size";
122
const std::string TablePropertiesNames::kRawValueSize =
123
    "rocksdb.raw.value.size";
124
const std::string TablePropertiesNames::kNumDataBlocks =
125
    "rocksdb.num.data.blocks";
126
const std::string TablePropertiesNames::kNumEntries =
127
    "rocksdb.num.entries";
128
const std::string TablePropertiesNames::kNumFilterBlocks =
129
    "rocksdb.num.filter.blocks";
130
const std::string TablePropertiesNames::kNumDataIndexBlocks =
131
    "rocksdb.num.data.index.blocks";
132
const std::string TablePropertiesNames::kFilterPolicy =
133
    "rocksdb.filter.policy";
134
const std::string TablePropertiesNames::kFormatVersion =
135
    "rocksdb.format.version";
136
const std::string TablePropertiesNames::kFixedKeyLen =
137
    "rocksdb.fixed.key.length";
138
139
extern const std::string kPropertiesBlock = "rocksdb.properties";
140
// Old property block name for backward compatibility
141
extern const std::string kPropertiesBlockOldName = "rocksdb.stats";
142
143
// Seek to the properties block.
144
// Return true if it successfully seeks to the properties block.
145
112k
Status SeekToPropertiesBlock(InternalIterator* meta_iter, bool* is_found) {
146
112k
  *is_found = true;
147
112k
  meta_iter->Seek(kPropertiesBlock);
148
112k
  if (meta_iter->status().ok() &&
149
112k
      
(112k
!meta_iter->Valid()112k
||
meta_iter->key() != kPropertiesBlock112k
)) {
150
0
    meta_iter->Seek(kPropertiesBlockOldName);
151
0
    if (meta_iter->status().ok() &&
152
0
        (!meta_iter->Valid() || meta_iter->key() != kPropertiesBlockOldName)) {
153
0
      *is_found = false;
154
0
    }
155
0
  }
156
112k
  return meta_iter->status();
157
112k
}
158
159
}  // namespace rocksdb