-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce DescribeReplication #4904
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
#include "rpc_scheme_base.h" | ||
#include "service_replication.h" | ||
|
||
#include <ydb/core/grpc_services/base/base.h> | ||
#include <ydb/core/tx/replication/controller/public_events.h> | ||
#include <ydb/core/tx/schemeshard/schemeshard.h> | ||
#include <ydb/core/ydb_convert/ydb_convert.h> | ||
#include <ydb/library/actors/core/actor.h> | ||
#include <ydb/library/actors/core/hfunc.h> | ||
#include <ydb/public/api/protos/draft/ydb_replication.pb.h> | ||
|
||
namespace NKikimr::NGRpcService { | ||
|
||
using namespace Ydb; | ||
|
||
using TEvDescribeReplication = TGrpcRequestOperationCall<Replication::DescribeReplicationRequest, Replication::DescribeReplicationResponse>; | ||
|
||
class TDescribeReplicationRPC: public TRpcSchemeRequestActor<TDescribeReplicationRPC, TEvDescribeReplication> { | ||
using TBase = TRpcSchemeRequestActor<TDescribeReplicationRPC, TEvDescribeReplication>; | ||
|
||
public: | ||
using TBase::TBase; | ||
|
||
void Bootstrap() { | ||
DescribeScheme(); | ||
} | ||
|
||
void PassAway() override { | ||
if (ControllerPipeClient) { | ||
NTabletPipe::CloseAndForgetClient(SelfId(), ControllerPipeClient); | ||
} | ||
|
||
TBase::PassAway(); | ||
} | ||
|
||
private: | ||
void DescribeScheme() { | ||
auto ev = std::make_unique<TEvTxUserProxy::TEvNavigate>(); | ||
SetAuthToken(ev, *Request_); | ||
SetDatabase(ev.get(), *Request_); | ||
ev->Record.MutableDescribePath()->SetPath(GetProtoRequest()->path()); | ||
|
||
Send(MakeTxProxyID(), ev.release()); | ||
Become(&TDescribeReplicationRPC::StateDescribeScheme); | ||
} | ||
|
||
STATEFN(StateDescribeScheme) { | ||
switch (ev->GetTypeRewrite()) { | ||
HFunc(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle); | ||
default: | ||
return TBase::StateWork(ev); | ||
} | ||
} | ||
|
||
void Handle(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev, const TActorContext& ctx) { | ||
const auto& record = ev->Get()->GetRecord(); | ||
const auto& desc = record.GetPathDescription(); | ||
|
||
if (record.HasReason()) { | ||
auto issue = NYql::TIssue(record.GetReason()); | ||
Request_->RaiseIssue(issue); | ||
} | ||
|
||
switch (record.GetStatus()) { | ||
case NKikimrScheme::StatusSuccess: | ||
if (desc.GetSelf().GetPathType() != NKikimrSchemeOp::EPathTypeReplication) { | ||
auto issue = NYql::TIssue("Is not a replication"); | ||
Request_->RaiseIssue(issue); | ||
return Reply(Ydb::StatusIds::SCHEME_ERROR, ctx); | ||
} | ||
|
||
ConvertDirectoryEntry(desc.GetSelf(), Result.mutable_self(), true); | ||
return DescribeReplication(desc.GetReplicationDescription().GetControllerId(), | ||
PathIdFromPathId(desc.GetReplicationDescription().GetPathId())); | ||
|
||
case NKikimrScheme::StatusPathDoesNotExist: | ||
case NKikimrScheme::StatusSchemeError: | ||
return Reply(Ydb::StatusIds::SCHEME_ERROR, ctx); | ||
|
||
case NKikimrScheme::StatusAccessDenied: | ||
return Reply(Ydb::StatusIds::UNAUTHORIZED, ctx); | ||
|
||
case NKikimrScheme::StatusNotAvailable: | ||
return Reply(Ydb::StatusIds::UNAVAILABLE, ctx); | ||
|
||
default: { | ||
return Reply(Ydb::StatusIds::GENERIC_ERROR, ctx); | ||
} | ||
} | ||
} | ||
|
||
void DescribeReplication(ui64 tabletId, const TPathId& pathId) { | ||
if (!ControllerPipeClient) { | ||
NTabletPipe::TClientConfig config; | ||
config.RetryPolicy = { | ||
.RetryLimitCount = 3, | ||
}; | ||
ControllerPipeClient = Register(NTabletPipe::CreateClient(SelfId(), tabletId, config)); | ||
} | ||
|
||
auto ev = std::make_unique<NReplication::TEvController::TEvDescribeReplication>(); | ||
PathIdFromPathId(pathId, ev->Record.MutablePathId()); | ||
|
||
NTabletPipe::SendData(SelfId(), ControllerPipeClient, ev.release()); | ||
Become(&TDescribeReplicationRPC::StateDescribeReplication); | ||
} | ||
|
||
STATEFN(StateDescribeReplication) { | ||
switch (ev->GetTypeRewrite()) { | ||
HFunc(NReplication::TEvController::TEvDescribeReplicationResult, Handle); | ||
default: | ||
return TBase::StateWork(ev); | ||
} | ||
} | ||
|
||
void Handle(NReplication::TEvController::TEvDescribeReplicationResult::TPtr& ev, const TActorContext& ctx) { | ||
auto& record = ev->Get()->Record; | ||
|
||
switch (record.GetStatus()) { | ||
case NKikimrReplication::TEvDescribeReplicationResult::SUCCESS: | ||
break; | ||
case NKikimrReplication::TEvDescribeReplicationResult::NOT_FOUND: | ||
return Reply(Ydb::StatusIds::SCHEME_ERROR, ctx); | ||
default: | ||
return Reply(Ydb::StatusIds::INTERNAL_ERROR, ctx); | ||
} | ||
|
||
ConvertConnectionParams(record.GetConnectionParams(), *Result.mutable_connection_params()); | ||
ConvertState(*record.MutableState(), Result); | ||
|
||
for (const auto& target : record.GetTargets()) { | ||
ConvertItem(target, *Result.add_items()); | ||
} | ||
|
||
return ReplyWithResult(Ydb::StatusIds::SUCCESS, Result, ctx); | ||
} | ||
|
||
static void ConvertConnectionParams(const NKikimrReplication::TConnectionParams& from, Ydb::Replication::ConnectionParams& to) { | ||
to.set_endpoint(from.GetEndpoint()); | ||
to.set_database(from.GetDatabase()); | ||
|
||
switch (from.GetCredentialsCase()) { | ||
case NKikimrReplication::TConnectionParams::kStaticCredentials: | ||
return ConvertStaticCredentials(from.GetStaticCredentials(), *to.mutable_static_credentials()); | ||
case NKikimrReplication::TConnectionParams::kOAuthToken: | ||
return ConvertOAuth(from.GetOAuthToken(), *to.mutable_oauth()); | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void ConvertStaticCredentials(const NKikimrReplication::TStaticCredentials& from, Ydb::Replication::ConnectionParams::StaticCredentials& to) { | ||
to.set_user(from.GetUser()); | ||
to.set_password_secret_name(from.GetPasswordSecretName()); | ||
} | ||
|
||
static void ConvertOAuth(const NKikimrReplication::TOAuthToken& from, Ydb::Replication::ConnectionParams::OAuth& to) { | ||
to.set_token_secret_name(from.GetTokenSecretName()); | ||
} | ||
|
||
static void ConvertItem(const NKikimrReplication::TReplicationConfig::TTargetSpecific::TTarget& from, Ydb::Replication::DescribeReplicationResult::Item& to) { | ||
to.set_source_path(from.GetSrcPath()); | ||
to.set_destination_path(from.GetDstPath()); | ||
} | ||
|
||
static void ConvertState(NKikimrReplication::TReplicationState& from, Ydb::Replication::DescribeReplicationResult& to) { | ||
switch (from.GetStateCase()) { | ||
case NKikimrReplication::TReplicationState::kStandBy: | ||
to.mutable_running(); | ||
break; | ||
case NKikimrReplication::TReplicationState::kError: | ||
*to.mutable_error()->mutable_issues() = std::move(*from.MutableError()->MutableIssues()); | ||
break; | ||
case NKikimrReplication::TReplicationState::kDone: | ||
to.mutable_done(); | ||
break; | ||
default: | ||
break; | ||
Comment on lines
+177
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
private: | ||
Ydb::Replication::DescribeReplicationResult Result; | ||
TActorId ControllerPipeClient; | ||
}; | ||
|
||
void DoDescribeReplication(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f) { | ||
f.RegisterActor(new TDescribeReplicationRPC(p.release())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace NKikimr::NGRpcService { | ||
|
||
class IRequestOpCtx; | ||
class IFacilityProvider; | ||
|
||
void DoDescribeReplication(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Выглядит так, что мы таскаем эту копипасту из функции в функцию, в данном ревью не критично, но стоит обобщить.