YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/event_helpers.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/db/event_helpers.h"
22
23
namespace rocksdb {
24
25
namespace {
26
template<class T>
27
110k
inline T SafeDivide(T a, T b) {
28
110k
  return b == 0 ? 
02.27k
:
a / b107k
;
29
110k
}
30
}  // namespace
31
32
104k
void EventHelpers::AppendCurrentTime(JSONWriter* jwriter) {
33
104k
  *jwriter << "time_micros"
34
104k
           << std::chrono::duration_cast<std::chrono::microseconds>(
35
104k
                  std::chrono::system_clock::now().time_since_epoch()).count();
36
104k
}
37
38
void EventHelpers::LogAndNotifyTableFileCreation(
39
    EventLogger* event_logger,
40
    const std::vector<std::shared_ptr<EventListener>>& listeners,
41
55.0k
    const FileDescriptor& fd, const TableFileCreationInfo& info) {
42
55.0k
  assert(event_logger);
43
0
  JSONWriter jwriter;
44
55.0k
  AppendCurrentTime(&jwriter);
45
55.0k
  jwriter << "cf_name" << info.cf_name
46
55.0k
          << "job" << info.job_id
47
55.0k
          << "event" << "table_file_creation"
48
55.0k
          << "file_number" << fd.GetNumber()
49
55.0k
          << "file_size" << fd.GetTotalFileSize();
50
51
  // table_properties
52
55.0k
  {
53
55.0k
    jwriter << "table_properties";
54
55.0k
    jwriter.StartObject();
55
56
    // basic properties:
57
55.0k
    jwriter << "data_size" << info.table_properties.data_size
58
55.0k
            << "data_index_size" << info.table_properties.data_index_size
59
55.0k
            << "filter_size" << info.table_properties.filter_size
60
55.0k
            << "filter_index_size" << info.table_properties.filter_index_size
61
55.0k
            << "raw_key_size" << info.table_properties.raw_key_size
62
55.0k
            << "raw_average_key_size" << SafeDivide(
63
55.0k
                info.table_properties.raw_key_size,
64
55.0k
                info.table_properties.num_entries)
65
55.0k
            << "raw_value_size" << info.table_properties.raw_value_size
66
55.0k
            << "raw_average_value_size" << SafeDivide(
67
55.0k
               info.table_properties.raw_value_size,
68
55.0k
               info.table_properties.num_entries)
69
55.0k
            << "num_data_blocks" << info.table_properties.num_data_blocks
70
55.0k
            << "num_entries" << info.table_properties.num_entries
71
55.0k
            << "num_filter_blocks" << info.table_properties.num_filter_blocks
72
55.0k
            << "num_data_index_blocks" << info.table_properties.num_data_index_blocks
73
55.0k
            << "filter_policy_name" <<
74
55.0k
                info.table_properties.filter_policy_name;
75
76
    // user collected properties
77
55.0k
    for (const auto& prop : info.table_properties.readable_properties) {
78
52.7k
      jwriter << prop.first << prop.second;
79
52.7k
    }
80
55.0k
    jwriter.EndObject();
81
55.0k
  }
82
55.0k
  jwriter.EndObject();
83
84
55.0k
  event_logger->Log(jwriter);
85
86
55.0k
#ifndef ROCKSDB_LITE
87
55.0k
  if (listeners.size() == 0) {
88
50.2k
    return;
89
50.2k
  }
90
91
5.18k
  
for (auto listener : listeners)4.82k
{
92
5.18k
    listener->OnTableFileCreated(info);
93
5.18k
  }
94
4.82k
#endif  // !ROCKSDB_LITE
95
4.82k
}
96
97
void EventHelpers::LogAndNotifyTableFileDeletion(
98
    EventLogger* event_logger, int job_id,
99
    uint64_t file_number, const std::string& file_path,
100
    const Status& status, const std::string& dbname,
101
49.5k
    const std::vector<std::shared_ptr<EventListener>>& listeners) {
102
103
49.5k
  JSONWriter jwriter;
104
49.5k
  AppendCurrentTime(&jwriter);
105
106
49.5k
  jwriter << "job" << job_id
107
49.5k
          << "event" << "table_file_deletion"
108
49.5k
          << "file_number" << file_number;
109
49.5k
  if (!status.ok()) {
110
1.18k
    jwriter << "status" << status.ToString();
111
1.18k
  }
112
113
49.5k
  jwriter.EndObject();
114
115
49.5k
  event_logger->Log(jwriter);
116
117
49.5k
#ifndef ROCKSDB_LITE
118
49.5k
  TableFileDeletionInfo info;
119
49.5k
  info.db_name = dbname;
120
49.5k
  info.job_id = job_id;
121
49.5k
  info.file_path = file_path;
122
49.5k
  info.status = status;
123
49.5k
  for (auto listener : listeners) {
124
2.69k
    listener->OnTableFileDeleted(info);
125
2.69k
  }
126
49.5k
#endif  // !ROCKSDB_LITE
127
49.5k
}
128
129
}  // namespace rocksdb