8
8
#include < stack>
9
9
#include < unordered_set>
10
10
11
+ #include < Common/CurrentMetrics.h>
11
12
#include < Common/ProfileEvents.h>
12
13
#include < IO/WriteHelpers.h>
13
14
#include < Storages/Page/mvcc/VersionSet.h>
@@ -22,6 +23,11 @@ extern const Event PSMVCCApplyOnCurrentDelta;
22
23
extern const Event PSMVCCApplyOnNewDelta;
23
24
} // namespace ProfileEvents
24
25
26
+ namespace CurrentMetrics
27
+ {
28
+ extern const Metric PSMVCCNumSnapshots;
29
+ } // namespace CurrentMetrics
30
+
25
31
namespace DB
26
32
{
27
33
namespace MVCC
@@ -61,13 +67,18 @@ class VersionSetWithDelta
61
67
snapshots(std::move(std::make_shared<Snapshot>(this , nullptr ))), //
62
68
config(config_)
63
69
{
70
+ // The placeholder snapshot should not be counted.
71
+ CurrentMetrics::sub (CurrentMetrics::PSMVCCNumSnapshots);
64
72
}
65
73
66
74
virtual ~VersionSetWithDelta ()
67
75
{
68
76
current.reset ();
69
77
// snapshot list is empty
70
78
assert (snapshots->prev == snapshots.get ());
79
+
80
+ // Ignore the destructor of placeholder snapshot
81
+ CurrentMetrics::add (CurrentMetrics::PSMVCCNumSnapshots);
71
82
}
72
83
73
84
void apply (TVersionEdit & edit)
@@ -114,7 +125,10 @@ class VersionSetWithDelta
114
125
Snapshot * next;
115
126
116
127
public:
117
- Snapshot (VersionSetWithDelta * vset_, VersionPtr tail_) : vset(vset_), view(std::move(tail_)), prev(this ), next(this ) {}
128
+ Snapshot (VersionSetWithDelta * vset_, VersionPtr tail_) : vset(vset_), view(std::move(tail_)), prev(this ), next(this )
129
+ {
130
+ CurrentMetrics::add (CurrentMetrics::PSMVCCNumSnapshots);
131
+ }
118
132
119
133
~Snapshot ()
120
134
{
@@ -123,6 +137,8 @@ class VersionSetWithDelta
123
137
std::unique_lock lock = vset->acquireForLock ();
124
138
prev->next = next;
125
139
next->prev = prev;
140
+
141
+ CurrentMetrics::sub (CurrentMetrics::PSMVCCNumSnapshots);
126
142
}
127
143
128
144
const TVersionView * version () const { return &view; }
@@ -327,6 +343,8 @@ class VersionSetWithDelta
327
343
VersionPtr current;
328
344
SnapshotPtr snapshots;
329
345
::DB::MVCC::VersionSetConfig config;
346
+
347
+ friend class VersionSetWithDeltaCompactTest ;
330
348
};
331
349
332
350
} // namespace MVCC
0 commit comments