Skip to content

Commit 1928e96

Browse files
authored
stable-25-3-1: cherry-pick PR 25678, PR 27729 (#27795)
2 parents b764976 + 323f348 commit 1928e96

File tree

12 files changed

+283
-66
lines changed

12 files changed

+283
-66
lines changed

ydb/core/client/server/grpc_server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void TGRpcService::SetupIncomingRequests(NYdbGrpc::TLoggerPtr logger) {
124124
ActorSystem->Send(GRpcRequestProxyId, new TGrpcRequestNoOperationCall< \
125125
NKikimrClient::In, \
126126
NKikimrClient::Out, \
127+
NRuntimeEvents::EType::COMMON, \
127128
NLegacyGrpcService::TLegacyGrpcMethodAccessorTraits<NKikimrClient::In, NKikimrClient::Out>>( \
128129
reqCtx, createActorCb, \
129130
TRequestAuxSettings { \

ydb/core/grpc_services/base/base.h

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ struct TRpcServices {
259259
struct TEvForgetOperation : public TEventLocal<TEvForgetOperation, TRpcServices::EvForgetOperation> {};
260260
};
261261

262+
namespace NRuntimeEvents {
263+
264+
enum class EType {
265+
COMMON,
266+
BOOTSTRAP_CLUSTER,
267+
};
268+
269+
} // NRuntimeEvents
270+
262271
// Should be specialized for real responses
263272
template <class T>
264273
void FillYdbStatus(T& resp, const NYql::TIssues& issues, Ydb::StatusIds::StatusCode status);
@@ -1118,6 +1127,18 @@ class TEvProxyRuntimeEvent
11181127
const TMaybe<TString> GetGrpcUserAgent() const {
11191128
return GetPeerMetaValues(NYdbGrpc::GRPC_USER_AGENT_HEADER);
11201129
}
1130+
1131+
virtual NRuntimeEvents::EType GetRuntimeEventType() {
1132+
return NRuntimeEvents::EType::COMMON;
1133+
}
1134+
};
1135+
1136+
template <NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON>
1137+
class TEvProxyRuntimeEventWithType : public TEvProxyRuntimeEvent {
1138+
public:
1139+
NRuntimeEvents::EType GetRuntimeEventType() override {
1140+
return RuntimeEventType;
1141+
}
11211142
};
11221143

11231144
template <ui32 TRpcId, typename TDerived>
@@ -1135,13 +1156,13 @@ class TEvProxyLegacyEvent
11351156
}
11361157
};
11371158

1138-
template <ui32 TRpcId, typename TReq, typename TResp, bool IsOperation, typename TDerived, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
1159+
template <ui32 TRpcId, typename TReq, typename TResp, bool IsOperation, typename TDerived, NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
11391160
class TGRpcRequestWrapperImpl
11401161
: public std::conditional_t<IsOperation,
11411162
TGrpcResponseSenderImpl<TGRpcRequestWrapperImpl<TRpcId, TReq, TResp, IsOperation, TDerived>>,
11421163
IRequestNoOpCtx>
11431164
, public std::conditional_t<TRpcId == TRpcServices::EvGrpcRuntimeRequest,
1144-
TEvProxyRuntimeEvent,
1165+
TEvProxyRuntimeEventWithType<RuntimeEventType>,
11451166
TEvProxyLegacyEvent<TRpcId, TDerived>>
11461167
{
11471168
friend class TProtoResponseHelper;
@@ -1499,12 +1520,12 @@ class TGRpcRequestWrapperImpl
14991520
TMaybe<TString> TraceId;
15001521
};
15011522

1502-
template <ui32 TRpcId, typename TReq, typename TResp, bool IsOperation, typename TDerived, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
1503-
class TGRpcRequestValidationWrapperImpl : public TGRpcRequestWrapperImpl<TRpcId, TReq, TResp, IsOperation, TDerived, TMethodAccessorTraits> {
1523+
template <ui32 TRpcId, typename TReq, typename TResp, bool IsOperation, typename TDerived, NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
1524+
class TGRpcRequestValidationWrapperImpl : public TGRpcRequestWrapperImpl<TRpcId, TReq, TResp, IsOperation, TDerived, RuntimeEventType, TMethodAccessorTraits> {
15041525
public:
15051526

15061527
TGRpcRequestValidationWrapperImpl(NYdbGrpc::IRequestContextBase* ctx)
1507-
: TGRpcRequestWrapperImpl<TRpcId, TReq, TResp, IsOperation, TDerived, TMethodAccessorTraits>(ctx)
1528+
: TGRpcRequestWrapperImpl<TRpcId, TReq, TResp, IsOperation, TDerived, RuntimeEventType, TMethodAccessorTraits>(ctx)
15081529
{ }
15091530

15101531
bool Validate(TString& error) override {
@@ -1529,13 +1550,13 @@ struct TProtoHasValidate {
15291550

15301551
class IFacilityProvider;
15311552

1532-
template <typename TReq, typename TResp, bool IsOperation, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
1553+
template <typename TReq, typename TResp, bool IsOperation, NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, IsOperation>>
15331554
class TGrpcRequestCall
15341555
: public std::conditional_t<TProtoHasValidate<TReq>::Value,
15351556
TGRpcRequestValidationWrapperImpl<
1536-
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, TMethodAccessorTraits>, TMethodAccessorTraits>,
1557+
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, RuntimeEventType, TMethodAccessorTraits>, RuntimeEventType, TMethodAccessorTraits>,
15371558
TGRpcRequestWrapperImpl<
1538-
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, TMethodAccessorTraits>, TMethodAccessorTraits>>
1559+
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, RuntimeEventType, TMethodAccessorTraits>, RuntimeEventType, TMethodAccessorTraits>>
15391560
{
15401561
using TRequestIface = typename std::conditional<IsOperation, IRequestOpCtx, IRequestNoOpCtx>::type;
15411562

@@ -1549,9 +1570,9 @@ class TGrpcRequestCall
15491570

15501571
using TBase = std::conditional_t<TProtoHasValidate<TReq>::Value,
15511572
TGRpcRequestValidationWrapperImpl<
1552-
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, TMethodAccessorTraits>, TMethodAccessorTraits>,
1573+
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, RuntimeEventType, TMethodAccessorTraits>, RuntimeEventType, TMethodAccessorTraits>,
15531574
TGRpcRequestWrapperImpl<
1554-
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, TMethodAccessorTraits>, TMethodAccessorTraits>>;
1575+
TRpcServices::EvGrpcRuntimeRequest, TReq, TResp, IsOperation, TGrpcRequestCall<TReq, TResp, IsOperation, RuntimeEventType, TMethodAccessorTraits>, RuntimeEventType, TMethodAccessorTraits>>;
15551576

15561577
template <typename TCallback>
15571578
TGrpcRequestCall(NYdbGrpc::IRequestContextBase* ctx, TCallback&& cb, TRequestAuxSettings auxSettings = {})
@@ -1606,11 +1627,11 @@ class TGrpcRequestCall
16061627
const TRequestAuxSettings AuxSettings;
16071628
};
16081629

1609-
template <typename TReq, typename TResp, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, true>>
1610-
using TGrpcRequestOperationCall = TGrpcRequestCall<TReq, TResp, true, TMethodAccessorTraits>;
1630+
template <typename TReq, typename TResp, NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, true>>
1631+
using TGrpcRequestOperationCall = TGrpcRequestCall<TReq, TResp, true, RuntimeEventType, TMethodAccessorTraits>;
16111632

1612-
template <typename TReq, typename TResp, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, false>>
1613-
using TGrpcRequestNoOperationCall = TGrpcRequestCall<TReq, TResp, false, TMethodAccessorTraits>;
1633+
template <typename TReq, typename TResp, NRuntimeEvents::EType RuntimeEventType = NRuntimeEvents::EType::COMMON, class TMethodAccessorTraits = TYdbGrpcMethodAccessorTraits<TReq, TResp, false>>
1634+
using TGrpcRequestNoOperationCall = TGrpcRequestCall<TReq, TResp, false, RuntimeEventType, TMethodAccessorTraits>;
16141635

16151636
template <ui32 TRpcId, typename TReq, typename TResp, bool IsOperation, TRateLimiterMode RlMode = TRateLimiterMode::Off>
16161637
class TGRpcRequestWrapper

ydb/core/grpc_services/grpc_request_proxy.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class TGRpcRequestProxyImpl
139139
return true;
140140
}
141141

142+
template<typename TEvent>
143+
void HandleBootstrapClusterEvent(TAutoPtr<TEventHandle<TEvent>>& event);
144+
template<typename TEvent>
145+
static constexpr bool IsBootstrapClusterEvent(TAutoPtr<TEventHandle<TEvent>>& event);
146+
142147
template<class TEvent>
143148
void PreHandle(TAutoPtr<TEventHandle<TEvent>>& event, const TActorContext& ctx) {
144149
LogRequest(event);
@@ -184,9 +189,14 @@ class TGRpcRequestProxyImpl
184189
bool skipResourceCheck = false;
185190
// do not check connect rights for the deprecated requests without database
186191
// remove this along with AllowYdbRequestsWithoutDatabase flag
187-
bool skipCheckConnectRigths = false;
192+
bool skipCheckConnectRights = false;
188193

189194
if (state.State == NYdbGrpc::TAuthState::AS_NOT_PERFORMED) {
195+
if (IsBootstrapClusterEvent(event)) {
196+
// Allow handle bootstrap cluster event without database
197+
HandleBootstrapClusterEvent(event);
198+
return;
199+
}
190200
const auto& maybeDatabaseName = requestBaseCtx->GetDatabaseName();
191201
if (maybeDatabaseName && !maybeDatabaseName.GetRef().empty()) {
192202
databaseName = CanonizePath(maybeDatabaseName.GetRef());
@@ -198,7 +208,7 @@ class TGRpcRequestProxyImpl
198208
} else {
199209
databaseName = RootDatabase;
200210
skipResourceCheck = true;
201-
skipCheckConnectRigths = true;
211+
skipCheckConnectRights = true;
202212
}
203213
}
204214
if (databaseName.empty()) {
@@ -290,7 +300,7 @@ class TGRpcRequestProxyImpl
290300
database->SecurityObject,
291301
event.Release(),
292302
Counters,
293-
skipCheckConnectRigths,
303+
skipCheckConnectRights,
294304
rootAttributes,
295305
this));
296306
return;
@@ -457,6 +467,47 @@ bool TGRpcRequestProxyImpl::IsAuthStateOK(const IRequestProxyCtx& ctx) {
457467
return false;
458468
}
459469

470+
template<typename TEvent>
471+
void TGRpcRequestProxyImpl::HandleBootstrapClusterEvent(TAutoPtr<TEventHandle<TEvent>>& event) {
472+
IRequestProxyCtx* requestProxyCtx = event->Get();
473+
if (requestProxyCtx->IsClientLost()) {
474+
// Any status here
475+
LOG_DEBUG(*TlsActivationContext, NKikimrServices::GRPC_SERVER,
476+
"Client was disconnected before processing request (grpc request proxy)");
477+
requestProxyCtx->ReplyWithYdbStatus(Ydb::StatusIds::UNAVAILABLE);
478+
requestProxyCtx->FinishSpan();
479+
return;
480+
}
481+
482+
TSchemeBoardEvents::TDescribeSchemeResult schemeData;
483+
TIntrusivePtr<TSecurityObject> securityObject = nullptr; // Do not have security object, cluster is not initialized. Check rights via list administration_allowed_sids or bootstrap_allowed_sids
484+
static const bool skipCheckConnectRights = true; // Do not check connect rights for bootstrap cluster
485+
static const TVector<std::pair<TString, TString>> rootAttributes = {}; // Empty rootAttributes
486+
Register(CreateGrpcRequestCheckActor<TEvent>(SelfId(),
487+
schemeData,
488+
securityObject,
489+
event.Release(),
490+
Counters,
491+
skipCheckConnectRights,
492+
rootAttributes,
493+
this));
494+
return;
495+
}
496+
497+
template<typename TEvent>
498+
constexpr bool TGRpcRequestProxyImpl::IsBootstrapClusterEvent(TAutoPtr<TEventHandle<TEvent>>& event) {
499+
if constexpr (TEvent::EventType == TRpcServices::EvGrpcRuntimeRequest) {
500+
switch (event->Get()->GetRuntimeEventType()) {
501+
case NRuntimeEvents::EType::BOOTSTRAP_CLUSTER:
502+
return true;
503+
case NRuntimeEvents::EType::COMMON:
504+
return false;
505+
}
506+
} else {
507+
return false;
508+
}
509+
}
510+
460511
template<class TEvent>
461512
void TGRpcRequestProxyImpl::MaybeStartTracing(TAutoPtr<TEventHandle<TEvent>>& event) {
462513
IRequestProxyCtx& ctx = *event->Get();

ydb/core/grpc_services/rpc_config.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ using TEvFetchStorageConfigRequest =
2424
Ydb::Config::FetchConfigResponse>;
2525
using TEvBootstrapClusterRequest =
2626
TGrpcRequestOperationCall<Ydb::Config::BootstrapClusterRequest,
27-
Ydb::Config::BootstrapClusterResponse>;
27+
Ydb::Config::BootstrapClusterResponse,
28+
NRuntimeEvents::EType::BOOTSTRAP_CLUSTER>;
2829

2930
using namespace NActors;
3031
using namespace Ydb;
@@ -162,7 +163,7 @@ class TReplaceStorageConfigRequest : public TBSConfigRequestGrpc<TReplaceStorage
162163
return;
163164
}
164165
self->Become(&TReplaceStorageConfigRequest::StateFunc);
165-
self->Send(MakeBlobStorageNodeWardenID(ctx.SelfID.NodeId()), new TEvNodeWardenQueryStorageConfig(false));
166+
self->Send(MakeBlobStorageNodeWardenID(ctx.SelfID.NodeId()), new TEvNodeWardenQueryStorageConfig(false));
166167
}
167168

168169
bool ValidateRequest(Ydb::StatusIds::StatusCode& status, NYql::TIssues& issues) override {
@@ -254,14 +255,14 @@ class TReplaceStorageConfigRequest : public TBSConfigRequestGrpc<TReplaceStorage
254255
TargetDatabase = metadata.Database;
255256
}
256257
else {
257-
Reply(Ydb::StatusIds::BAD_REQUEST, "No database name found in metadata",
258+
Reply(Ydb::StatusIds::BAD_REQUEST, "No database name found in metadata",
258259
NKikimrIssues::TIssuesIds::DEFAULT_ERROR, ActorContext());
259260
return;
260261
}
261262

262-
if (*TargetDatabase == ("/" + AppData()->DomainsInfo->Domain->Name) ||
263+
if (*TargetDatabase == ("/" + AppData()->DomainsInfo->Domain->Name) ||
263264
*TargetDatabase == AppData()->DomainsInfo->Domain->Name) {
264-
Reply(Ydb::StatusIds::BAD_REQUEST, "Provided database is a domain database.",
265+
Reply(Ydb::StatusIds::BAD_REQUEST, "Provided database is a domain database.",
265266
NKikimrIssues::TIssuesIds::DEFAULT_ERROR, ActorContext());
266267
return;
267268
}
@@ -289,14 +290,14 @@ class TReplaceStorageConfigRequest : public TBSConfigRequestGrpc<TReplaceStorage
289290
};
290291
auto pipe = NTabletPipe::CreateClient(SelfId(), MakeConsoleID(), pipeConfig);
291292
ConsolePipe = RegisterWithSameMailbox(pipe);
292-
293+
293294
auto PrepareAndSendRequest = [&](auto requestType) {
294295
using TRequestType = decltype(requestType);
295296
auto request = std::make_unique<TRequestType>();
296297
request->Record.SetUserToken(Request_->GetSerializedToken());
297298
request->Record.SetPeerName(Request_->GetPeerName());
298299
request->Record.SetIngressDatabase(*TargetDatabase);
299-
300+
300301
auto& req = *request->Record.MutableRequest();
301302
req.set_config(*DatabaseConfig);
302303

@@ -606,4 +607,3 @@ void DoBootstrapCluster(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvide
606607
}
607608

608609
} // namespace NKikimr::NGRpcService
609-

ydb/library/grpc/server/grpc_method_setup.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include <string>
66
#include <grpcpp/grpcpp.h>
77

8-
// Общий макрос для настройки методов gRPC
9-
#define SETUP_METHOD(methodName, method, rlMode, requestType, serviceType, counterName, auditMode) \
8+
#define SETUP_RUNTIME_EVENT_METHOD(methodName, method, rlMode, requestType, serviceType, counterName, auditMode, runtimeEventType) \
109
MakeIntrusive<NGRpcService::TGRpcRequest< \
1110
Ydb::serviceType::Y_CAT(methodName, Request), \
1211
Ydb::serviceType::Y_CAT(methodName, Response), \
@@ -19,7 +18,8 @@
1918
NGRpcService::ReportGrpcReqToMon(*ActorSystem, reqCtx->GetPeer()); \
2019
ActorSystem->Send(GRpcRequestProxyId, new TGrpcRequestOperationCall< \
2120
Ydb::serviceType::Y_CAT(methodName, Request), \
22-
Ydb::serviceType::Y_CAT(methodName, Response)>(reqCtx, &method, \
21+
Ydb::serviceType::Y_CAT(methodName, Response), \
22+
NRuntimeEvents::EType::runtimeEventType>(reqCtx, &method, \
2323
TRequestAuxSettings { \
2424
.RlMode = TRateLimiterMode::rlMode, \
2525
.AuditMode = auditMode, \
@@ -32,4 +32,9 @@
3232
getCounterBlock(Y_STRINGIZE(counterName), Y_STRINGIZE(methodName)) \
3333
)->Run()
3434

35+
36+
// Общий макрос для настройки методов gRPC
37+
#define SETUP_METHOD(methodName, method, rlMode, requestType, serviceType, counterName, auditMode) \
38+
SETUP_RUNTIME_EVENT_METHOD(methodName, method, rlMode, requestType, serviceType, counterName, auditMode, COMMON)
39+
3540
#endif // GRPC_METHOD_SETUP_H

ydb/services/config/grpc_service.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ void TConfigGRpcService::SetupIncomingRequests(NYdbGrpc::TLoggerPtr logger) {
3030

3131
SETUP_BS_METHOD(ReplaceConfig, DoReplaceConfig, Rps, CONFIG_REPLACECONFIG, TAuditMode::Modifying(TAuditMode::TLogClassConfig::ClusterAdmin));
3232
SETUP_BS_METHOD(FetchConfig, DoFetchConfig, Rps, CONFIG_FETCHCONFIG, TAuditMode::NonModifying());
33-
SETUP_BS_METHOD(BootstrapCluster, DoBootstrapCluster, Rps, CONFIG_BOOTSTRAP, TAuditMode::Modifying(TAuditMode::TLogClassConfig::ClusterAdmin));
3433

3534
#undef SETUP_BS_METHOD
35+
36+
37+
#define SETUP_BOOTSTRAP_CLUSTER_METHOD(methodName, method, rlMode, requestType, auditModeFlags) \
38+
SETUP_RUNTIME_EVENT_METHOD(methodName, method, rlMode, requestType, Config, config, auditModeFlags, BOOTSTRAP_CLUSTER)
39+
40+
SETUP_BOOTSTRAP_CLUSTER_METHOD(BootstrapCluster, DoBootstrapCluster, Rps, CONFIG_BOOTSTRAP, TAuditMode::Modifying(TAuditMode::TLogClassConfig::ClusterAdmin));
41+
42+
#undef SETUP_BS_METHOD_WITH_TYPE
3643
}
3744

3845
} // namespace NKikimr::NGRpcService

0 commit comments

Comments
 (0)