Skip to content

Commit f0def09

Browse files
committed
Move TBillingStats to schemeshard_billing_helpers (#19658)
1 parent 2dc7acb commit f0def09

File tree

5 files changed

+94
-98
lines changed

5 files changed

+94
-98
lines changed
Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
#include "schemeshard_billing_helpers.h"
22

3-
#include <library/cpp/json/json_writer.h>
4-
53
#include <util/generic/size_literals.h>
4+
#include <util/string/builder.h>
65
#include <util/string/cast.h>
76

8-
namespace NKikimr {
9-
namespace NSchemeShard {
7+
namespace NKikimr::NSchemeShard {
8+
9+
TBillingStats::TBillingStats(ui64 readRows, ui64 readBytes, ui64 uploadRows, ui64 uploadBytes)
10+
: UploadRows{uploadRows}
11+
, UploadBytes{uploadBytes}
12+
, ReadRows{readRows}
13+
, ReadBytes{readBytes}
14+
{
15+
}
16+
17+
TBillingStats TBillingStats::operator -(const TBillingStats &other) const {
18+
Y_ENSURE(UploadRows >= other.UploadRows);
19+
Y_ENSURE(UploadBytes >= other.UploadBytes);
20+
Y_ENSURE(ReadRows >= other.ReadRows);
21+
Y_ENSURE(ReadBytes >= other.ReadBytes);
22+
23+
return {UploadRows - other.UploadRows, UploadBytes - other.UploadBytes,
24+
ReadRows - other.ReadRows, ReadBytes - other.ReadBytes};
25+
}
26+
27+
TBillingStats TBillingStats::operator +(const TBillingStats &other) const {
28+
return {UploadRows + other.UploadRows, UploadBytes + other.UploadBytes,
29+
ReadRows + other.ReadRows, ReadBytes + other.ReadBytes};
30+
}
31+
32+
TString TBillingStats::ToString() const {
33+
return TStringBuilder()
34+
<< "{"
35+
<< " upload rows: " << UploadRows
36+
<< ", upload bytes: " << UploadBytes
37+
<< ", read rows: " << ReadRows
38+
<< ", read bytes: " << ReadBytes
39+
<< " }";
40+
}
1041

1142
ui64 TRUCalculator::ReadTable(ui64 bytes) {
1243
return 128 * ((bytes + 1_MB - 1) / 1_MB);
@@ -16,5 +47,9 @@ ui64 TRUCalculator::BulkUpsert(ui64 bytes, ui64 rows) {
1647
return (Max(rows, (bytes + 1_KB - 1) / 1_KB) + 1) / 2;
1748
}
1849

19-
} // NSchemeShard
20-
} // NKikimr
50+
ui64 TRUCalculator::Calculate(const TBillingStats& stats) {
51+
return TRUCalculator::ReadTable(stats.GetReadBytes())
52+
+ TRUCalculator::BulkUpsert(stats.GetUploadBytes(), stats.GetUploadRows());
53+
}
54+
55+
}

ydb/core/tx/schemeshard/schemeshard_billing_helpers.h

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,60 @@
22

33
#include <ydb/core/metering/bill_record.h>
44

5-
namespace NKikimr {
6-
namespace NSchemeShard {
5+
namespace NKikimr::NSchemeShard {
6+
7+
class TBillingStats {
8+
public:
9+
TBillingStats() = default;
10+
TBillingStats(const TBillingStats& other) = default;
11+
TBillingStats& operator = (const TBillingStats& other) = default;
12+
13+
TBillingStats(ui64 uploadRows, ui64 uploadBytes, ui64 readRows, ui64 readBytes);
14+
15+
TBillingStats operator - (const TBillingStats& other) const;
16+
TBillingStats& operator -= (const TBillingStats& other) {
17+
return *this = *this - other;
18+
}
19+
20+
TBillingStats operator + (const TBillingStats& other) const;
21+
TBillingStats& operator += (const TBillingStats& other) {
22+
return *this = *this + other;
23+
}
24+
25+
bool operator == (const TBillingStats& other) const = default;
26+
27+
explicit operator bool () const {
28+
return *this != TBillingStats{};
29+
}
30+
31+
TString ToString() const;
32+
33+
ui64 GetUploadRows() const {
34+
return UploadRows;
35+
}
36+
ui64 GetUploadBytes() const {
37+
return UploadBytes;
38+
}
39+
40+
ui64 GetReadRows() const {
41+
return ReadRows;
42+
}
43+
ui64 GetReadBytes() const {
44+
return ReadBytes;
45+
}
46+
47+
private:
48+
ui64 UploadRows = 0;
49+
ui64 UploadBytes = 0;
50+
ui64 ReadRows = 0;
51+
ui64 ReadBytes = 0;
52+
};
753

854
struct TRUCalculator {
955
// https://a.yandex-team.ru/arc/trunk/arcadia/kikimr/docs/ru/pricing/serverless.md
1056
static ui64 ReadTable(ui64 bytes);
1157
static ui64 BulkUpsert(ui64 bytes, ui64 rows);
58+
static ui64 Calculate(const TBillingStats& stats);
59+
};
1260

13-
}; // TRUCalculator
14-
15-
} // NSchemeShard
16-
} // NKikimr
61+
}

ydb/core/tx/schemeshard/schemeshard_build_index_tx_base.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ void TSchemeShard::TIndexBuilder::TTxBase::ApplySchedule(const TActorContext& ct
5656
}
5757
}
5858

59-
ui64 TSchemeShard::TIndexBuilder::TTxBase::RequestUnits(const TBillingStats& stats) {
60-
return TRUCalculator::ReadTable(stats.GetReadBytes())
61-
+ TRUCalculator::BulkUpsert(stats.GetUploadBytes(), stats.GetUploadRows());
62-
}
63-
6459
void TSchemeShard::TIndexBuilder::TTxBase::RoundPeriod(TInstant& start, TInstant& end) {
6560
if (start.Hours() == end.Hours()) {
6661
return; // that is OK
@@ -157,7 +152,7 @@ void TSchemeShard::TIndexBuilder::TTxBase::ApplyBill(NTabletFlatExecutor::TTrans
157152
billed += toBill;
158153
Self->PersistBuildIndexBilled(db, buildInfo);
159154

160-
ui64 requestUnits = RequestUnits(toBill);
155+
ui64 requestUnits = TRUCalculator::Calculate(toBill);
161156

162157
const TString billRecord = TBillRecord()
163158
.Id(id)

ydb/core/tx/schemeshard/schemeshard_info_types.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,39 +2426,6 @@ bool TTopicInfo::FillKeySchema(const TString& tabletConfig) {
24262426
return FillKeySchema(proto, unused);
24272427
}
24282428

2429-
TBillingStats::TBillingStats(ui64 readRows, ui64 readBytes, ui64 uploadRows, ui64 uploadBytes)
2430-
: UploadRows{uploadRows}
2431-
, UploadBytes{uploadBytes}
2432-
, ReadRows{readRows}
2433-
, ReadBytes{readBytes}
2434-
{
2435-
}
2436-
2437-
TBillingStats TBillingStats::operator -(const TBillingStats &other) const {
2438-
Y_ENSURE(UploadRows >= other.UploadRows);
2439-
Y_ENSURE(UploadBytes >= other.UploadBytes);
2440-
Y_ENSURE(ReadRows >= other.ReadRows);
2441-
Y_ENSURE(ReadBytes >= other.ReadBytes);
2442-
2443-
return {UploadRows - other.UploadRows, UploadBytes - other.UploadBytes,
2444-
ReadRows - other.ReadRows, ReadBytes - other.ReadBytes};
2445-
}
2446-
2447-
TBillingStats TBillingStats::operator +(const TBillingStats &other) const {
2448-
return {UploadRows + other.UploadRows, UploadBytes + other.UploadBytes,
2449-
ReadRows + other.ReadRows, ReadBytes + other.ReadBytes};
2450-
}
2451-
2452-
TString TBillingStats::ToString() const {
2453-
return TStringBuilder()
2454-
<< "{"
2455-
<< " upload rows: " << UploadRows
2456-
<< ", upload bytes: " << UploadBytes
2457-
<< ", read rows: " << ReadRows
2458-
<< ", read bytes: " << ReadBytes
2459-
<< " }";
2460-
}
2461-
24622429
TSequenceInfo::TSequenceInfo(
24632430
ui64 alterVersion,
24642431
NKikimrSchemeOp::TSequenceDescription&& description,

ydb/core/tx/schemeshard/schemeshard_info_types.h

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <ydb/core/base/table_vector_index.h>
1818
#include <ydb/core/persqueue/partition_key_range/partition_key_range.h>
1919
#include <ydb/core/persqueue/utils.h>
20+
#include <ydb/core/tx/schemeshard/schemeshard_billing_helpers.h>
2021
#include <ydb/services/lib/sharding/sharding.h>
2122
#include <ydb/core/tablet_flat/flat_cxx_database.h>
2223
#include <ydb/core/tablet_flat/flat_dbase_scheme.h>
@@ -2941,53 +2942,6 @@ struct TImportInfo: public TSimpleRefCount<TImportInfo> {
29412942
}; // TImportInfo
29422943
// } // NImport
29432944

2944-
class TBillingStats {
2945-
public:
2946-
TBillingStats() = default;
2947-
TBillingStats(const TBillingStats& other) = default;
2948-
TBillingStats& operator = (const TBillingStats& other) = default;
2949-
2950-
TBillingStats(ui64 uploadRows, ui64 uploadBytes, ui64 readRows, ui64 readBytes);
2951-
2952-
TBillingStats operator - (const TBillingStats& other) const;
2953-
TBillingStats& operator -= (const TBillingStats& other) {
2954-
return *this = *this - other;
2955-
}
2956-
2957-
TBillingStats operator + (const TBillingStats& other) const;
2958-
TBillingStats& operator += (const TBillingStats& other) {
2959-
return *this = *this + other;
2960-
}
2961-
2962-
bool operator == (const TBillingStats& other) const = default;
2963-
2964-
explicit operator bool () const {
2965-
return *this != TBillingStats{};
2966-
}
2967-
2968-
TString ToString() const;
2969-
2970-
ui64 GetUploadRows() const {
2971-
return UploadRows;
2972-
}
2973-
ui64 GetUploadBytes() const {
2974-
return UploadBytes;
2975-
}
2976-
2977-
ui64 GetReadRows() const {
2978-
return ReadRows;
2979-
}
2980-
ui64 GetReadBytes() const {
2981-
return ReadBytes;
2982-
}
2983-
2984-
private:
2985-
ui64 UploadRows = 0;
2986-
ui64 UploadBytes = 0;
2987-
ui64 ReadRows = 0;
2988-
ui64 ReadBytes = 0;
2989-
};
2990-
29912945
// TODO(mbkkt) separate it to 3 classes: TBuildColumnsInfo TBuildSecondaryInfo TBuildVectorInfo with single base TBuildInfo
29922946
struct TIndexBuildInfo: public TSimpleRefCount<TIndexBuildInfo> {
29932947
using TPtr = TIntrusivePtr<TIndexBuildInfo>;

0 commit comments

Comments
 (0)