Skip to content

Commit 9f5b3d7

Browse files
authored
Merge 845103f into ffa5093
2 parents ffa5093 + 845103f commit 9f5b3d7

File tree

14 files changed

+215
-7
lines changed

14 files changed

+215
-7
lines changed

ydb/core/grpc_services/rpc_bsconfig.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ydb/core/grpc_services/rpc_common/rpc_common.h>
88
#include <ydb/core/mind/local.h>
99
#include <ydb/core/protos/local.pb.h>
10+
#include <ydb/core/blobstorage/nodewarden/node_warden_events.h>
1011

1112
namespace NKikimr::NGRpcService {
1213

@@ -16,6 +17,9 @@ using TEvReplaceStorageConfigRequest =
1617
using TEvFetchStorageConfigRequest =
1718
TGrpcRequestOperationCall<Ydb::BSConfig::FetchStorageConfigRequest,
1819
Ydb::BSConfig::FetchStorageConfigResponse>;
20+
using TEvBootstrapRequest =
21+
TGrpcRequestOperationCall<Ydb::BSConfig::BootstrapRequest,
22+
Ydb::BSConfig::BootstrapResponse>;
1923

2024
using namespace NActors;
2125
using namespace Ydb;
@@ -112,5 +116,52 @@ void DoFetchBSConfig(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider&)
112116
TActivationContext::AsActorContext().Register(new TFetchStorageConfigRequest(p.release()));
113117
}
114118

119+
void DoBootstrap(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider&) {
120+
class TBootstrapRequest : public TRpcOperationRequestActor<TBootstrapRequest, TEvBootstrapRequest> {
121+
using TBase = TRpcOperationRequestActor<TBootstrapRequest, TEvBootstrapRequest>;
115122

116-
} // namespace NKikimr::NGRpcService
123+
public:
124+
using TBase::TBase;
125+
126+
void Bootstrap(const TActorContext &ctx) {
127+
TBase::Bootstrap(ctx);
128+
Become(&TBootstrapRequest::StateFunc);
129+
130+
const auto& request = *GetProtoRequest();
131+
132+
auto ev = std::make_unique<NStorage::TEvNodeConfigInvokeOnRoot>();
133+
auto& record = ev->Record;
134+
auto *cmd = record.MutableBootstrap();
135+
cmd->SetSelfAssemblyUUID(request.self_assembly_uuid());
136+
Send(MakeBlobStorageNodeWardenID(SelfId().NodeId()), ev.release());
137+
}
138+
139+
void Handle(NStorage::TEvNodeConfigInvokeOnRootResult::TPtr ev) {
140+
auto& record = ev->Get()->Record;
141+
switch (record.GetStatus()) {
142+
case NKikimrBlobStorage::TEvNodeConfigInvokeOnRootResult::OK:
143+
ReplyWithResult(Ydb::StatusIds::SUCCESS, TActivationContext::AsActorContext());
144+
break;
145+
146+
default:
147+
Reply(Ydb::StatusIds::GENERIC_ERROR, record.GetErrorReason(), NKikimrIssues::TIssuesIds::DEFAULT_ERROR,
148+
TActivationContext::AsActorContext());
149+
break;
150+
}
151+
}
152+
153+
protected:
154+
STFUNC(StateFunc) {
155+
switch (ev->GetTypeRewrite()) {
156+
hFunc(NStorage::TEvNodeConfigInvokeOnRootResult, Handle);
157+
158+
default:
159+
return TBase::StateFuncBase(ev);
160+
}
161+
}
162+
};
163+
164+
TActivationContext::AsActorContext().Register(new TBootstrapRequest(p.release()));
165+
}
166+
167+
} // namespace NKikimr::NGRpcService

ydb/core/grpc_services/service_bsconfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ namespace NKikimr::NGRpcService {
1111

1212
void DoFetchBSConfig(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider&);
1313

14-
} // NKikimr::NGRpcService
14+
void DoBootstrap(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider&);
15+
16+
} // NKikimr::NGRpcService

ydb/core/jaeger_tracing/request_discriminator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum class ERequestType: size_t {
7070

7171
BSCONFIG_REPLACESTORAGECONFIG,
7272
BSCONFIG_FETCHSTORAGECONFIG,
73+
BSCONFIG_BOOTSTRAP,
7374

7475
PING_GRPC,
7576
PING_PROXY,
@@ -141,6 +142,7 @@ static const THashMap<TStringBuf, ERequestType> NameToRequestType = {
141142

142143
{"BSConfig.ReplaceStorageConfig", ERequestType::BSCONFIG_REPLACESTORAGECONFIG},
143144
{"BSConfig.FetchStorageConfig", ERequestType::BSCONFIG_FETCHSTORAGECONFIG},
145+
{"BSConfig.Bootstrap", ERequestType::BSCONFIG_BOOTSTRAP},
144146
};
145147

146148
struct TRequestDiscriminator {

ydb/public/api/grpc/ydb_bsconfig_v1.proto

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import "ydb/public/api/protos/ydb_bsconfig.proto";
1010

1111
service BSConfigService {
1212

13-
// Initialize Blobstorage host configs and box
13+
// Initialize Blobstorage/single config
1414
rpc ReplaceStorageConfig(BSConfig.ReplaceStorageConfigRequest) returns (BSConfig.ReplaceStorageConfigResponse);
1515

16-
// Fetch Blobstorage host configs and box
16+
// Fetch Blobstorage/single config
1717
rpc FetchStorageConfig(BSConfig.FetchStorageConfigRequest) returns (BSConfig.FetchStorageConfigResponse);
1818

19-
}
19+
// Bootstrap automatically configured cluster
20+
rpc Bootstrap(BSConfig.BootstrapRequest) returns (BSConfig.BootstrapResponse);
21+
22+
}

ydb/public/api/protos/ydb_bsconfig.proto

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ message FetchStorageConfigResponse {
3535

3636
message FetchStorageConfigResult {
3737
string yaml_config = 1;
38-
}
38+
}
39+
40+
message BootstrapRequest {
41+
Ydb.Operations.OperationParams operation_params = 1;
42+
string self_assembly_uuid = 2;
43+
}
44+
45+
message BootstrapResponse {
46+
Ydb.Operations.Operation operation = 1;
47+
}

ydb/public/lib/ydb_cli/commands/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SRCS(
99
query_workload.cpp
1010
ydb_admin.cpp
1111
ydb_benchmark.cpp
12+
ydb_cluster.cpp
1213
ydb_debug.cpp
1314
ydb_dynamic_config.cpp
1415
ydb_ping.cpp

ydb/public/lib/ydb_cli/commands/ydb_admin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "ydb_admin.h"
22

33
#include "ydb_dynamic_config.h"
4+
#include "ydb_cluster.h"
45

56
namespace NYdb {
67
namespace NConsoleClient {
@@ -10,6 +11,7 @@ TCommandAdmin::TCommandAdmin()
1011
{
1112
AddCommand(std::make_unique<NDynamicConfig::TCommandConfig>());
1213
AddCommand(std::make_unique<NDynamicConfig::TCommandVolatileConfig>());
14+
AddCommand(std::make_unique<NCluster::TCommandCluster>());
1315
}
1416

1517
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "ydb_cluster.h"
2+
3+
#include <ydb/public/sdk/cpp/client/ydb_bsconfig/bsconfig.h>
4+
5+
using namespace NKikimr;
6+
7+
namespace NYdb::NConsoleClient::NCluster {
8+
9+
TCommandCluster::TCommandCluster()
10+
: TClientCommandTree("cluster", {}, "Cluster-wide administration")
11+
{
12+
AddCommand(std::make_unique<TCommandClusterBootstrap>());
13+
}
14+
15+
TCommandClusterBootstrap::TCommandClusterBootstrap()
16+
: TYdbCommand("bootstrap", {}, "Bootstrap automatically-assembled cluster")
17+
{}
18+
19+
void TCommandClusterBootstrap::Config(TConfig& config) {
20+
TYdbCommand::Config(config);
21+
config.Opts->AddLongOption("guid", "Self-assembly UUID")
22+
.RequiredArgument("STRING").StoreResult(&SelfAssemblyUUID);
23+
config.SetFreeArgsNum(0);
24+
}
25+
26+
void TCommandClusterBootstrap::Parse(TConfig& config) {
27+
TClientCommand::Parse(config);
28+
}
29+
30+
int TCommandClusterBootstrap::Run(TConfig& config) {
31+
auto driver = std::make_unique<NYdb::TDriver>(CreateDriver(config));
32+
auto client = NYdb::NBsConfig::TClient(*driver);
33+
auto result = client.Bootstrap(SelfAssemblyUUID).GetValueSync();
34+
ThrowOnError(result);
35+
return EXIT_SUCCESS;
36+
}
37+
38+
} // namespace NYdb::NConsoleClient::NCluster
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "ydb_command.h"
4+
#include "ydb_common.h"
5+
6+
#include <util/generic/set.h>
7+
8+
namespace NYdb::NConsoleClient::NCluster {
9+
10+
class TCommandCluster : public TClientCommandTree {
11+
public:
12+
TCommandCluster();
13+
};
14+
15+
class TCommandClusterBootstrap : public TYdbCommand {
16+
TString SelfAssemblyUUID;
17+
18+
public:
19+
TCommandClusterBootstrap();
20+
void Config(TConfig& config) override;
21+
void Parse(TConfig& config) override;
22+
int Run(TConfig& config) override;
23+
};
24+
25+
} // namespace NYdb::NConsoleClient::NCluster
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "bsconfig.h"
2+
3+
#include <ydb/public/api/grpc/ydb_bsconfig_v1.grpc.pb.h>
4+
#include <ydb/public/sdk/cpp/client/ydb_common_client/impl/client.h>
5+
#include <ydb/public/sdk/cpp/client/impl/ydb_internal/make_request/make.h>
6+
7+
namespace NYdb::NBsConfig {
8+
9+
class TClient::TImpl : public TClientImplCommon<TClient::TImpl> {
10+
public:
11+
TImpl(std::shared_ptr<TGRpcConnectionsImpl>&& connections, const TCommonClientSettings& settings)
12+
: TClientImplCommon(std::move(connections), settings)
13+
{}
14+
15+
TAsyncStatus Bootstrap(const TString& selfAssemblyUUID, const TBsConfigSettings& settings) {
16+
auto request = MakeOperationRequest<Ydb::BSConfig::BootstrapRequest>(settings);
17+
request.set_self_assembly_uuid(selfAssemblyUUID);
18+
19+
return RunSimple<Ydb::BSConfig::V1::BSConfigService, Ydb::BSConfig::BootstrapRequest, Ydb::BSConfig::BootstrapResponse>(
20+
std::move(request),
21+
&Ydb::BSConfig::V1::BSConfigService::Stub::AsyncBootstrap,
22+
TRpcRequestSettings::Make(settings));
23+
}
24+
};
25+
26+
TClient::TClient(const TDriver& driver, const TCommonClientSettings& settings)
27+
: Impl_(new TImpl(CreateInternalInterface(driver), settings))
28+
{}
29+
30+
TClient::~TClient() = default;
31+
32+
TAsyncStatus TClient::Bootstrap(const TString& selfAssemblyUUID, const TBsConfigSettings& settings) {
33+
return Impl_->Bootstrap(selfAssemblyUUID, settings);
34+
}
35+
36+
} // NYdb::NBsConfig

0 commit comments

Comments
 (0)