Skip to content

Commit 3a7aa37

Browse files
authored
[backup] Add draft backup controller tablet (#4103)
1 parent 8a1f080 commit 3a7aa37

34 files changed

+363
-6
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "tablet.h"
2+
#include "tablet_impl.h"
3+
4+
namespace NKikimr::NBackup {
5+
6+
TBackupController::TBackupController(const TActorId& tablet, TTabletStorageInfo* info)
7+
: TActor(&TThis::StateInit)
8+
, TTabletExecutedFlat(info, tablet, new NMiniKQL::TMiniKQLFactory)
9+
{
10+
Y_UNUSED(tablet, info);
11+
}
12+
13+
STFUNC(TBackupController::StateInit) {
14+
StateInitImpl(ev, SelfId());
15+
}
16+
17+
STFUNC(TBackupController::StateWork) {
18+
HandleDefaultEvents(ev, SelfId());
19+
}
20+
21+
void TBackupController::OnDetach(const TActorContext& ctx) {
22+
Die(ctx);
23+
}
24+
25+
void TBackupController::OnTabletDead(TEvTablet::TEvTabletDead::TPtr& ev, const TActorContext& ctx) {
26+
Y_UNUSED(ev);
27+
Die(ctx);
28+
}
29+
30+
void TBackupController::OnActivateExecutor(const TActorContext& ctx) {
31+
RunTxInitSchema(ctx);
32+
}
33+
34+
void TBackupController::DefaultSignalTabletActive(const TActorContext& ctx) {
35+
Y_UNUSED(ctx);
36+
}
37+
38+
39+
void TBackupController::SwitchToWork(const TActorContext& ctx) {
40+
SignalTabletActive(ctx);
41+
Become(&TThis::StateWork);
42+
}
43+
44+
void TBackupController::Reset() {
45+
46+
}
47+
48+
IActor* CreateBackupController(const TActorId& tablet, TTabletStorageInfo* info) {
49+
return new TBackupController(tablet, info);
50+
}
51+
52+
} // namespace NKikimr::NBackup
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <ydb/core/base/blobstorage.h>
4+
#include <ydb/library/actors/core/actor.h>
5+
6+
namespace NKikimr::NBackup {
7+
8+
using namespace NActors;
9+
10+
IActor* CreateBackupController(const TActorId& tablet, TTabletStorageInfo* info);
11+
12+
} // namespace NKikimr::NBackup
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#pragma once
2+
3+
#include <ydb/core/base/blobstorage.h>
4+
#include <ydb/core/base/defs.h>
5+
#include <ydb/core/engine/minikql/flat_local_tx_factory.h>
6+
#include <ydb/core/protos/counters_backup.pb.h>
7+
#include <ydb/core/tablet_flat/flat_cxx_database.h>
8+
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
9+
#include <ydb/core/tx/replication/service/service.h>
10+
11+
#include <ydb/library/actors/core/interconnect.h>
12+
#include <ydb/library/yverify_stream/yverify_stream.h>
13+
14+
namespace NKikimr::NBackup {
15+
16+
struct TBackupControllerSchema : NIceDb::Schema {
17+
struct BackupCollections : Table<1> {
18+
struct ID : Column<1, NScheme::NTypeIds::Uint32> {};
19+
20+
using TKey = TableKey<ID>;
21+
using TColumns = TableColumns<ID>;
22+
};
23+
24+
using TTables = SchemaTables<BackupCollections>;
25+
using TSettings = SchemaSettings<ExecutorLogBatching<true>, ExecutorLogFlushPeriod<TDuration::MicroSeconds(512).GetValue()>>;
26+
};
27+
28+
class TBackupController
29+
: public TActor<TBackupController>
30+
, public NTabletFlatExecutor::TTabletExecutedFlat
31+
{
32+
public:
33+
class TTxBase
34+
: public NTabletFlatExecutor::TTransactionBase<TBackupController>
35+
{
36+
public:
37+
TTxBase(const TString& name, TBackupController* self)
38+
: TTransactionBase(self)
39+
, LogPrefix(name)
40+
{
41+
}
42+
43+
protected:
44+
const TString LogPrefix;
45+
};
46+
using Schema = TBackupControllerSchema;
47+
48+
// local transactions
49+
class TTxInitSchema;
50+
class TTxInit;
51+
52+
// tx runners
53+
void RunTxInitSchema(const TActorContext& ctx);
54+
void RunTxInit(const TActorContext& ctx);
55+
56+
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
57+
return NKikimrServices::TActivity::BACKUP_CONTROLLER_TABLET;
58+
}
59+
60+
explicit TBackupController(const TActorId& tablet, TTabletStorageInfo* info);
61+
62+
STFUNC(StateInit);
63+
64+
STFUNC(StateWork);
65+
66+
void OnDetach(const TActorContext& ctx) override;
67+
68+
void OnTabletDead(TEvTablet::TEvTabletDead::TPtr& ev, const TActorContext& ctx) override;
69+
70+
void OnActivateExecutor(const TActorContext& ctx) override;
71+
72+
void DefaultSignalTabletActive(const TActorContext& ctx) override;
73+
74+
void SwitchToWork(const TActorContext& ctx);
75+
76+
void Reset();
77+
};
78+
79+
} // namespace NKikimr::NBackup
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "tablet_impl.h"
2+
3+
namespace NKikimr::NBackup {
4+
5+
class TBackupController::TTxInit
6+
: public TTxBase
7+
{
8+
inline bool Load(NIceDb::TNiceDb& db) {
9+
Y_UNUSED(db);
10+
Self->Reset();
11+
return true;
12+
}
13+
14+
inline bool Load(NTable::TDatabase& toughDb) {
15+
NIceDb::TNiceDb db(toughDb);
16+
return Load(db);
17+
}
18+
19+
public:
20+
explicit TTxInit(TSelf* self)
21+
: TTxBase("TxInit", self)
22+
{
23+
}
24+
25+
TTxType GetTxType() const override {
26+
return TXTYPE_INIT;
27+
}
28+
29+
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
30+
Y_UNUSED(ctx);
31+
return Load(txc.DB);
32+
}
33+
34+
void Complete(const TActorContext& ctx) override {
35+
Self->SwitchToWork(ctx);
36+
}
37+
}; // TTxInit
38+
39+
void TBackupController::RunTxInit(const TActorContext& ctx) {
40+
Execute(new TTxInit(this), ctx);
41+
}
42+
43+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "tablet_impl.h"
2+
3+
namespace NKikimr::NBackup {
4+
5+
class TBackupController::TTxInitSchema
6+
: public TTxBase
7+
{
8+
public:
9+
explicit TTxInitSchema(TBackupController* self)
10+
: TTxBase("TxInitSchema", self)
11+
{
12+
}
13+
14+
TTxType GetTxType() const override {
15+
return TXTYPE_INIT_SCHEMA;
16+
}
17+
18+
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
19+
Y_UNUSED(ctx);
20+
21+
NIceDb::TNiceDb db(txc.DB);
22+
db.Materialize<Schema>();
23+
24+
return true;
25+
}
26+
27+
void Complete(const TActorContext& ctx) override {
28+
Self->RunTxInit(ctx);
29+
}
30+
31+
}; // TTxInitSchema
32+
33+
void TBackupController::RunTxInitSchema(const TActorContext& ctx) {
34+
Execute(new TTxInitSchema(this), ctx);
35+
}
36+
37+
}

ydb/core/backup/controller/ya.make

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
LIBRARY()
2+
3+
SRCS(
4+
tablet.cpp
5+
tx_init.cpp
6+
tx_init_schema.cpp
7+
)
8+
9+
PEERDIR(
10+
library/cpp/lwtrace/protos
11+
ydb/core/tablet_flat
12+
ydb/core/protos
13+
ydb/core/scheme/protos
14+
)
15+
16+
END()

ydb/core/backup/ya.make

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RECURSE(
2+
controller
3+
)

ydb/core/cms/console/console__create_tenant.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
127127
Tenant->IsExternalHive = Self->FeatureFlags.GetEnableExternalHive();
128128
Tenant->IsExternalSysViewProcessor = Self->FeatureFlags.GetEnableSystemViews();
129129
Tenant->IsExternalStatisticsAggregator = Self->FeatureFlags.GetEnableStatistics();
130+
Tenant->IsExternalBackupController = Self->FeatureFlags.GetEnableBackupService();
130131

131132
if (rec.options().disable_external_subdomain()) {
132133
Tenant->IsExternalSubdomain = false;
@@ -145,11 +146,13 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
145146
Tenant->IsExternalHive = false;
146147
Tenant->IsExternalSysViewProcessor = false;
147148
Tenant->IsExternalStatisticsAggregator = false;
149+
Tenant->IsExternalBackupController = false;
148150
}
149151

150152
Tenant->IsExternalHive &= Tenant->IsExternalSubdomain; // external hive without external sub domain is pointless
151153
Tenant->IsExternalSysViewProcessor &= Tenant->IsExternalSubdomain;
152154
Tenant->IsExternalStatisticsAggregator &= Tenant->IsExternalSubdomain;
155+
Tenant->IsExternalBackupController &= Tenant->IsExternalSubdomain;
153156

154157
Tenant->StorageUnitsQuota = Self->Config.DefaultStorageUnitsQuota;
155158
Tenant->ComputationalUnitsQuota = Self->Config.DefaultComputationalUnitsQuota;

ydb/core/cms/console/console__scheme.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ struct Schema : NIceDb::Schema {
4848
struct AlterIdempotencyKey : Column<26, NScheme::NTypeIds::Utf8> {};
4949
struct DatabaseQuotas : Column<27, NScheme::NTypeIds::String> {};
5050
struct IsExternalStatisticsAggregator : Column<28, NScheme::NTypeIds::Bool> {};
51+
struct IsExternalBackupController : Column<29, NScheme::NTypeIds::Bool> {};
5152

5253
using TKey = TableKey<Path>;
5354
using TColumns = TableColumns<Path, State, Coordinators, Mediators, PlanResolution,
5455
Issue, TxId, UserToken, SubdomainVersion, ConfirmedSubdomain, TimeCastBucketsPerMediator,
5556
Attributes, Generation, SchemeShardId, PathId, ErrorCode, IsExternalSubDomain, IsExternalHive,
5657
AreResourcesShared, SharedDomainSchemeShardId, SharedDomainPathId, IsExternalSysViewProcessor,
57-
SchemaOperationQuotas, CreateIdempotencyKey, AlterIdempotencyKey, DatabaseQuotas, IsExternalStatisticsAggregator>;
58+
SchemaOperationQuotas, CreateIdempotencyKey, AlterIdempotencyKey, DatabaseQuotas, IsExternalStatisticsAggregator,
59+
IsExternalBackupController>;
5860
};
5961

6062
struct TenantPools : Table<3> {

ydb/core/cms/console/console_tenants_manager.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ class TSubDomainManip : public TActorBootstrapped<TSubDomainManip> {
461461
if (Tenant->IsExternalStatisticsAggregator) {
462462
subdomain.SetExternalStatisticsAggregator(true);
463463
}
464+
if (Tenant->IsExternalBackupController) {
465+
subdomain.SetExternalBackupController(true);
466+
}
464467
}
465468

466469
if (SharedTenant) {
@@ -486,6 +489,9 @@ class TSubDomainManip : public TActorBootstrapped<TSubDomainManip> {
486489
if (Tenant->IsExternalStatisticsAggregator) {
487490
subdomain.SetExternalStatisticsAggregator(true);
488491
}
492+
if (Tenant->IsExternalBackupController) {
493+
subdomain.SetExternalBackupController(true);
494+
}
489495
}
490496
if (tablets) {
491497
subdomain.SetCoordinators(Tenant->Coordinators);
@@ -1196,6 +1202,7 @@ TTenantsManager::TTenant::TTenant(const TString &path,
11961202
, IsExternalHive(false)
11971203
, IsExternalSysViewProcessor(false)
11981204
, IsExternalStatisticsAggregator(false)
1205+
, IsExternalBackupController(false)
11991206
, AreResourcesShared(false)
12001207
{
12011208
}

0 commit comments

Comments
 (0)