YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

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