Skip to content

Commit 5688514

Browse files
authored
Separate TGenStep class from BlobDepot and move it to common utils (#5193)
1 parent 8395ad6 commit 5688514

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

ydb/core/blob_depot/data.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,3 @@ template<>
732732
void Out<NKikimr::NBlobDepot::TGivenIdRange>(IOutputStream& s, const NKikimr::NBlobDepot::TGivenIdRange& x) {
733733
x.Output(s);
734734
}
735-
736-
template<>
737-
void Out<NKikimr::NBlobDepot::TGenStep>(IOutputStream& s, const NKikimr::NBlobDepot::TGenStep& x) {
738-
x.Output(s);
739-
}

ydb/core/blob_depot/defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <ydb/core/protos/blob_depot.pb.h>
1717
#include <ydb/core/protos/counters_blob_depot.pb.h>
1818
#include <ydb/core/util/format.h>
19+
#include <ydb/core/util/gen_step.h>
1920
#include <ydb/core/util/stlog.h>
2021

2122
#include <library/cpp/monlib/service/pages/templates.h>

ydb/core/blob_depot/types.h

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ namespace NKikimr::NBlobDepot {
117117
type == EBlobType::VG_FOOTER_BLOB || type == EBlobType::VG_GC_BLOB);
118118
return cookie >> typeBits;
119119
}
120+
121+
explicit operator TGenStep() const {
122+
return {Generation, Step};
123+
}
120124
};
121125

122126
class TGivenIdRange {
@@ -195,65 +199,6 @@ namespace NKikimr::NBlobDepot {
195199
return true;
196200
}
197201

198-
class TGenStep {
199-
ui64 Value = 0;
200-
201-
public:
202-
TGenStep() = default;
203-
TGenStep(const TGenStep&) = default;
204-
TGenStep &operator=(const TGenStep& other) = default;
205-
206-
explicit TGenStep(ui64 value)
207-
: Value(value)
208-
{}
209-
210-
TGenStep(ui32 gen, ui32 step)
211-
: Value(ui64(gen) << 32 | step)
212-
{}
213-
214-
explicit TGenStep(const TLogoBlobID& id)
215-
: TGenStep(id.Generation(), id.Step())
216-
{}
217-
218-
explicit TGenStep(const TBlobSeqId& id)
219-
: TGenStep(id.Generation, id.Step)
220-
{}
221-
222-
explicit operator ui64() const {
223-
return Value;
224-
}
225-
226-
ui32 Generation() const {
227-
return Value >> 32;
228-
}
229-
230-
ui32 Step() const {
231-
return Value;
232-
}
233-
234-
void Output(IOutputStream& s) const {
235-
s << Generation() << ":" << Step();
236-
}
237-
238-
TString ToString() const {
239-
TStringStream s;
240-
Output(s);
241-
return s.Str();
242-
}
243-
244-
TGenStep Previous() const {
245-
Y_ABORT_UNLESS(Value);
246-
return TGenStep(Value - 1);
247-
}
248-
249-
friend bool operator ==(const TGenStep& x, const TGenStep& y) { return x.Value == y.Value; }
250-
friend bool operator !=(const TGenStep& x, const TGenStep& y) { return x.Value != y.Value; }
251-
friend bool operator < (const TGenStep& x, const TGenStep& y) { return x.Value < y.Value; }
252-
friend bool operator <=(const TGenStep& x, const TGenStep& y) { return x.Value <= y.Value; }
253-
friend bool operator > (const TGenStep& x, const TGenStep& y) { return x.Value > y.Value; }
254-
friend bool operator >=(const TGenStep& x, const TGenStep& y) { return x.Value >= y.Value; }
255-
};
256-
257202
#define BDEV(MARKER, TEXT, ...) \
258203
do { \
259204
auto& ctx = *TlsActivationContext; \

ydb/core/util/gen_step.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "gen_step.h"
2+
3+
template<>
4+
void Out<NKikimr::TGenStep>(IOutputStream& s, const NKikimr::TGenStep& x) {
5+
x.Output(s);
6+
}

ydb/core/util/gen_step.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#pragma once
2+
3+
#include <ydb/core/base/logoblob.h>
4+
5+
#include <util/generic/string.h>
6+
#include <util/stream/output.h>
7+
#include <util/stream/str.h>
8+
9+
namespace NKikimr {
10+
11+
class TGenStep {
12+
ui64 Value = 0;
13+
14+
public:
15+
TGenStep() = default;
16+
TGenStep(const TGenStep&) = default;
17+
TGenStep &operator=(const TGenStep&) = default;
18+
19+
explicit TGenStep(ui64 value)
20+
: Value(value)
21+
{}
22+
23+
TGenStep(ui32 gen, ui32 step)
24+
: Value(ui64(gen) << 32 | step)
25+
{}
26+
27+
explicit TGenStep(const TLogoBlobID& id)
28+
: TGenStep(id.Generation(), id.Step())
29+
{}
30+
31+
explicit operator ui64() const {
32+
return Value;
33+
}
34+
35+
ui32 Generation() const {
36+
return Value >> 32;
37+
}
38+
39+
ui32 Step() const {
40+
return Value;
41+
}
42+
43+
void Output(IOutputStream& s) const {
44+
s << Generation() << ":" << Step();
45+
}
46+
47+
TString ToString() const {
48+
TStringStream s;
49+
Output(s);
50+
return s.Str();
51+
}
52+
53+
TGenStep Previous() const {
54+
Y_ABORT_UNLESS(Value);
55+
return TGenStep(Value - 1);
56+
}
57+
58+
friend auto operator <=>(const TGenStep& x, const TGenStep& y) = default;
59+
};
60+
61+
} // NKikimr

ydb/core/util/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ SRCS(
2424
format.h
2525
fragmented_buffer.cpp
2626
fragmented_buffer.h
27+
gen_step.cpp
28+
gen_step.h
2729
hazard.cpp
2830
hyperlog_counter.cpp
2931
hyperlog_counter.h

0 commit comments

Comments
 (0)