Skip to content

Commit 86194b9

Browse files
robdrynkinrobdrynkin
and
robdrynkin
authored
KIKIMR-20521: Add UseVDisksBalancing feature flag (ydb-platform#523)
Co-authored-by: robdrynkin <[email protected]>
1 parent ad5da4d commit 86194b9

File tree

12 files changed

+134
-0
lines changed

12 files changed

+134
-0
lines changed

ydb/core/base/blobstorage.h

+1
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ struct TEvBlobStorage {
706706
EvWriteMetadata,
707707
EvPermitGarbageCollection,
708708
EvReplInvoke,
709+
EvStartBalancing,
709710

710711
EvYardInitResult = EvPut + 9 * 512, /// 268 636 672
711712
EvLogResult,

ydb/core/blobstorage/nodewarden/node_warden_vdisk.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ namespace NKikimr::NStorage {
174174
vdiskConfig->EnableVDiskCooldownTimeout = Cfg->EnableVDiskCooldownTimeout;
175175
vdiskConfig->ReplPausedAtStart = Cfg->VDiskReplPausedAtStart;
176176
vdiskConfig->EnableVPatch = EnableVPatch;
177+
vdiskConfig->FeatureFlags = Cfg->FeatureFlags;
177178

178179
// issue initial report to whiteboard before creating actor to avoid races
179180
Send(WhiteboardId, new NNodeWhiteboard::TEvWhiteboard::TEvVDiskStateUpdate(vdiskId, groupInfo->GetStoragePoolName(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "balancing_actor.h"
2+
#include "defs.h"
3+
4+
5+
namespace NKikimr {
6+
7+
class TBalancingActor : public TActorBootstrapped<TBalancingActor> {
8+
private:
9+
std::shared_ptr<TBalancingCtx> Ctx;
10+
public:
11+
void Bootstrap() {
12+
Become(&TThis::StateFunc);
13+
}
14+
15+
STRICT_STFUNC(StateFunc,
16+
CFunc(NActors::TEvents::TEvPoison::EventType, Die)
17+
);
18+
19+
TBalancingActor(std::shared_ptr<TBalancingCtx> &ctx)
20+
: TActorBootstrapped<TBalancingActor>()
21+
, Ctx(ctx)
22+
{
23+
}
24+
};
25+
26+
IActor* CreateBalancingActor(std::shared_ptr<TBalancingCtx> ctx) {
27+
return new TBalancingActor(ctx);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include "defs.h"
4+
5+
6+
namespace NKikimr {
7+
IActor* CreateBalancingActor(std::shared_ptr<TBalancingCtx> ctx);
8+
} // NKikimr
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include <ydb/core/blobstorage/vdisk/common/vdisk_context.h>
4+
#include <ydb/core/blobstorage/vdisk/common/vdisk_pdiskctx.h>
5+
#include <ydb/core/blobstorage/vdisk/hulldb/hull_ds_all_snap.h>
6+
#include <ydb/core/blobstorage/vdisk/common/vdisk_hulllogctx.h>
7+
8+
9+
namespace NKikimr {
10+
struct TBalancingCtx {
11+
TIntrusivePtr<TVDiskContext> VCtx;
12+
TPDiskCtxPtr PDiskCtx;
13+
TActorId SkeletonId;
14+
NMonGroup::TBalancingGroup MonGroup;
15+
16+
NKikimr::THullDsSnap Snap;
17+
18+
TIntrusivePtr<TVDiskConfig> VDiskCfg;
19+
TIntrusivePtr<TBlobStorageGroupInfo> GInfo;
20+
21+
TBalancingCtx(
22+
TIntrusivePtr<TVDiskContext> vCtx,
23+
TPDiskCtxPtr pDiskCtx,
24+
TActorId skeletonId,
25+
NKikimr::THullDsSnap snap,
26+
TIntrusivePtr<TVDiskConfig> vDiskCfg,
27+
TIntrusivePtr<TBlobStorageGroupInfo> gInfo
28+
)
29+
: VCtx(std::move(vCtx))
30+
, PDiskCtx(std::move(pDiskCtx))
31+
, SkeletonId(skeletonId)
32+
, MonGroup(VCtx->VDiskCounters, "subsystem", "balancing")
33+
, Snap(std::move(snap))
34+
, VDiskCfg(std::move(vDiskCfg))
35+
, GInfo(std::move(gInfo))
36+
{
37+
}
38+
};
39+
40+
struct TEvStartBalancing : TEventLocal<TEvStartBalancing, TEvBlobStorage::EvStartBalancing> {};
41+
} // NKikimr
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
LIBRARY()
2+
3+
PEERDIR(
4+
ydb/core/blobstorage/base
5+
ydb/core/blobstorage/groupinfo
6+
ydb/core/blobstorage/vdisk/common
7+
ydb/core/blobstorage/vdisk/hulldb
8+
ydb/core/blobstorage/vdisk/ingress
9+
ydb/core/blobstorage/vdisk/repl
10+
)
11+
12+
SRCS(
13+
balancing_actor.cpp
14+
)
15+
16+
END()
17+
18+
RECURSE_FOR_TESTS(
19+
ut
20+
)

ydb/core/blobstorage/vdisk/common/vdisk_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ namespace NKikimr {
210210
bool EnableVDiskCooldownTimeout;
211211
TControlWrapper EnableVPatch = true;
212212

213+
///////////// FEATURE FLAGS ////////////////////////
214+
NKikimrConfig::TFeatureFlags FeatureFlags;
215+
213216
TVDiskConfig(const TBaseInfo &baseInfo);
214217
void Merge(const NKikimrBlobStorage::TVDiskConfig &update);
215218
private:

ydb/core/blobstorage/vdisk/common/vdisk_mongroups.h

+10
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,16 @@ public:
547547
COUNTER_DEF(DefragBytesRewritten);
548548
};
549549

550+
///////////////////////////////////////////////////////////////////////////////////
551+
// TBalancingGroup
552+
///////////////////////////////////////////////////////////////////////////////////
553+
class TBalancingGroup : public TBase {
554+
public:
555+
GROUP_CONSTRUCTOR(TBalancingGroup)
556+
{
557+
}
558+
};
559+
550560
} // NMonGroup
551561
} // NKikimr
552562

ydb/core/blobstorage/vdisk/skeleton/blobstorage_skeleton.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <ydb/core/base/feature_flags.h>
2020
#include <ydb/core/blobstorage/groupinfo/blobstorage_groupinfo_iter.h>
2121
#include <ydb/core/blobstorage/vdisk/localrecovery/localrecovery_public.h>
22+
#include <ydb/core/blobstorage/vdisk/balance/balancing_actor.h>
2223
#include <ydb/core/blobstorage/vdisk/hullop/blobstorage_hull.h>
2324
#include <ydb/core/blobstorage/vdisk/hullop/blobstorage_hulllog.h>
2425
#include <ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.h>
@@ -1711,6 +1712,7 @@ namespace NKikimr {
17111712
ReplDone = true;
17121713
}
17131714
UpdateReplState();
1715+
RunBalancing(ctx);
17141716
}
17151717

17161718
void SkeletonErrorState(const TActorContext &ctx,
@@ -2449,6 +2451,20 @@ namespace NKikimr {
24492451
ev->Get()->Callback({}, "replication is not in progress");
24502452
}
24512453

2454+
void RunBalancing(const TActorContext &ctx) {
2455+
if (!Config->FeatureFlags.GetUseVDisksBalancing()) {
2456+
return;
2457+
}
2458+
if (BalancingId) {
2459+
ActiveActors.Erase(BalancingId);
2460+
}
2461+
auto balancingCtx = std::make_shared<TBalancingCtx>(
2462+
VCtx, PDiskCtx, SelfId(), Hull->GetHullDs()->GetIndexSnapshot(), Config, GInfo
2463+
);
2464+
BalancingId = ctx.Register(CreateBalancingActor(balancingCtx));
2465+
ActiveActors.Insert(BalancingId, __FILE__, __LINE__, ctx, NKikimrServices::BLOBSTORAGE);
2466+
}
2467+
24522468
// NOTES: we have 4 state functions, one of which is an error state (StateDatabaseError) and
24532469
// others are good: StateLocalRecovery, StateSyncGuidRecovery, StateNormal
24542470
// We switch between states in the following manner:
@@ -2622,6 +2638,7 @@ namespace NKikimr {
26222638
hFunc(NPDisk::TEvChunkForgetResult, Handle)
26232639
FFunc(TEvPrivate::EvCheckSnapshotExpiration, CheckSnapshotExpiration)
26242640
hFunc(TEvReplInvoke, Handle)
2641+
CFunc(TEvStartBalancing::EventType, RunBalancing)
26252642
)
26262643

26272644
STRICT_STFUNC(StateDatabaseError,
@@ -2730,6 +2747,7 @@ namespace NKikimr {
27302747
bool CommenceRepl = false;
27312748
TActorId ScrubId;
27322749
TActorId DefragId;
2750+
TActorId BalancingId;
27332751
bool HasUnreadableBlobs = false;
27342752
std::unique_ptr<TVDiskCompactionState> VDiskCompactionState;
27352753
TMemorizableControlWrapper EnableVPatch;

ydb/core/blobstorage/vdisk/skeleton/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LIBRARY()
22

33
PEERDIR(
44
ydb/core/base
5+
ydb/core/blobstorage/vdisk/balance
56
ydb/core/blobstorage/vdisk/hulldb/base
67
ydb/core/blobstorage/vdisk/hulldb/bulksst_add
78
ydb/core/blobstorage/vdisk/synclog

ydb/core/blobstorage/vdisk/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ END()
3030

3131
RECURSE(
3232
anubis_osiris
33+
balance
3334
common
3435
defrag
3536
handoff

ydb/core/protos/feature_flags.proto

+1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ message TFeatureFlags {
123123
optional bool EnableTablePgTypes = 108 [default = false];
124124
optional bool EnableLocalDBBtreeIndex = 109 [default = false];
125125
optional bool EnablePDiskHighHDDInFlight = 110 [default = false];
126+
optional bool UseVDisksBalancing = 111 [default = false];
126127
}

0 commit comments

Comments
 (0)