YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/version_tracker.h
Line
Count
Source
1
//
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
16
#ifndef YB_UTIL_VERSION_TRACKER_H
17
#define YB_UTIL_VERSION_TRACKER_H
18
19
#include <stddef.h>
20
21
#include <atomic>
22
23
namespace yb {
24
25
template <class Value>
26
class VersionTrackerCheckOut;
27
28
// Utility class to track version of stored data.
29
// VersionTracker<T> provides read access to data.
30
// If data should be modified, then it should be checked out:
31
// auto checkout = versioned_data.CheckOut();
32
// And checkout would provide write access to data.
33
// After checkout is destroyed, version is incremented.
34
template <class Value>
35
class VersionTracker {
36
 public:
37
  VersionTracker(const VersionTracker&) = delete;
38
  void operator=(const VersionTracker&) = delete;
39
40
16.1k
  VersionTracker() = default;
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::VersionTracker()
Line
Count
Source
40
8.07k
  VersionTracker() = default;
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::VersionTracker()
Line
Count
Source
40
8.07k
  VersionTracker() = default;
41
42
  // Data is modified in place, so external synchronization is required to prevent
43
  // undesired access to partially modified data.
44
  VersionTrackerCheckOut<Value> CheckOut();
45
46
571k
  void Commit() {
47
571k
    version_.fetch_add(1, std::memory_order_acq_rel);
48
571k
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::Commit()
Line
Count
Source
46
64.2k
  void Commit() {
47
64.2k
    version_.fetch_add(1, std::memory_order_acq_rel);
48
64.2k
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::Commit()
Line
Count
Source
46
507k
  void Commit() {
47
507k
    version_.fetch_add(1, std::memory_order_acq_rel);
48
507k
  }
49
50
22.6M
  const Value& operator*() const {
51
22.6M
    return value_;
52
22.6M
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::operator*() const
Line
Count
Source
50
15.3M
  const Value& operator*() const {
51
15.3M
    return value_;
52
15.3M
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::operator*() const
Line
Count
Source
50
7.29M
  const Value& operator*() const {
51
7.29M
    return value_;
52
7.29M
  }
53
54
5.52M
  const Value* operator->() const {
55
5.52M
    return &value_;
56
5.52M
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::operator->() const
Line
Count
Source
54
5.50M
  const Value* operator->() const {
55
5.50M
    return &value_;
56
5.50M
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::operator->() const
Line
Count
Source
54
16.6k
  const Value* operator->() const {
55
16.6k
    return &value_;
56
16.6k
  }
57
58
12.0k
  size_t Version() const {
59
12.0k
    return version_.load(std::memory_order_acquire);
60
12.0k
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::Version() const
Line
Count
Source
58
6.01k
  size_t Version() const {
59
6.01k
    return version_.load(std::memory_order_acquire);
60
6.01k
  }
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::Version() const
Line
Count
Source
58
6.01k
  size_t Version() const {
59
6.01k
    return version_.load(std::memory_order_acquire);
60
6.01k
  }
61
62
 private:
63
  friend class VersionTrackerCheckOut<Value>;
64
65
  Value value_;
66
  std::atomic<size_t> version_{0};
67
};
68
69
template <class Value>
70
class VersionTrackerCheckOut {
71
 public:
72
  VersionTrackerCheckOut(const VersionTrackerCheckOut&) = delete;
73
  void operator=(const VersionTrackerCheckOut&) = delete;
74
75
  VersionTrackerCheckOut(VersionTrackerCheckOut&& rhs) : tracker_(rhs.tracker_) {
76
    rhs.tracker_ = nullptr;
77
  }
78
79
570k
  explicit VersionTrackerCheckOut(VersionTracker<Value>* tracker) : tracker_(tracker) {}
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::VersionTrackerCheckOut(yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >*)
Line
Count
Source
79
506k
  explicit VersionTrackerCheckOut(VersionTracker<Value>* tracker) : tracker_(tracker) {}
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::VersionTrackerCheckOut(yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >*)
Line
Count
Source
79
64.2k
  explicit VersionTrackerCheckOut(VersionTracker<Value>* tracker) : tracker_(tracker) {}
80
81
570k
  ~VersionTrackerCheckOut() {
82
570k
    if (tracker_) {
83
570k
      tracker_->Commit();
84
570k
    }
85
570k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::~VersionTrackerCheckOut()
Line
Count
Source
81
506k
  ~VersionTrackerCheckOut() {
82
506k
    if (tracker_) {
83
506k
      tracker_->Commit();
84
506k
    }
85
506k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::~VersionTrackerCheckOut()
Line
Count
Source
81
64.2k
  ~VersionTrackerCheckOut() {
82
64.2k
    if (tracker_) {
83
64.2k
      tracker_->Commit();
84
64.2k
    }
85
64.2k
  }
86
87
499k
  Value& operator*() {
88
499k
    return tracker_->value_;
89
499k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::operator*()
Line
Count
Source
87
2.25k
  Value& operator*() {
88
2.25k
    return tracker_->value_;
89
2.25k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::operator*()
Line
Count
Source
87
497k
  Value& operator*() {
88
497k
    return tracker_->value_;
89
497k
  }
90
91
24.9k
  Value* operator->() {
92
24.9k
    return get_ptr();
93
24.9k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::operator->()
Line
Count
Source
91
5.92k
  Value* operator->() {
92
5.92k
    return get_ptr();
93
5.92k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::operator->()
Line
Count
Source
91
19.0k
  Value* operator->() {
92
19.0k
    return get_ptr();
93
19.0k
  }
94
95
111k
  Value* get_ptr() {
96
111k
    return &tracker_->value_;
97
111k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::get_ptr()
Line
Count
Source
95
8.92k
  Value* get_ptr() {
96
8.92k
    return &tracker_->value_;
97
8.92k
  }
yb::VersionTrackerCheckOut<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::get_ptr()
Line
Count
Source
95
102k
  Value* get_ptr() {
96
102k
    return &tracker_->value_;
97
102k
  }
98
99
 private:
100
  VersionTracker<Value>* tracker_;
101
};
102
103
template <class Value>
104
570k
VersionTrackerCheckOut<Value> VersionTracker<Value>::CheckOut() {
105
570k
  return VersionTrackerCheckOut<Value>(this);
106
570k
}
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TableInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TableInfo> > > > >::CheckOut()
Line
Count
Source
104
506k
VersionTrackerCheckOut<Value> VersionTracker<Value>::CheckOut() {
105
506k
  return VersionTrackerCheckOut<Value>(this);
106
506k
}
yb::VersionTracker<std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, scoped_refptr<yb::master::TabletInfo>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, scoped_refptr<yb::master::TabletInfo> > > > >::CheckOut()
Line
Count
Source
104
64.2k
VersionTrackerCheckOut<Value> VersionTracker<Value>::CheckOut() {
105
64.2k
  return VersionTrackerCheckOut<Value>(this);
106
64.2k
}
107
108
} // namespace yb
109
110
#endif // YB_UTIL_VERSION_TRACKER_H