Skip to content

Support DDL in QueryService for SECRET_ACCESS objects #845

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions ydb/core/testlib/common_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ydb/core/driver_lib/run/run.h>
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>

#include <ydb/public/sdk/cpp/client/ydb_query/client.h>
#include <ydb/public/sdk/cpp/client/ydb_table/table.h>
#include <ydb/public/lib/yson_value/ydb_yson_value.h>

Expand Down Expand Up @@ -136,20 +137,18 @@ void THelper::StartDataRequest(const TString& request, const bool expectSuccess,
UNIT_ASSERT(resultReady);
}

void THelper::StartSchemaRequest(const TString& request, const bool expectSuccess, const bool waiting) const {
void THelper::StartSchemaRequestTableServiceImpl(const TString& request, const bool expectation, const bool waiting) const {
NYdb::NTable::TTableClient tClient(Server.GetDriver(),
NYdb::NTable::TClientSettings().UseQueryCache(false).AuthToken("root@builtin"));
auto expectation = expectSuccess;

std::shared_ptr<bool> rrPtr = std::make_shared<bool>(false);
TString requestInt = request;
tClient.CreateSession().Subscribe([rrPtr, requestInt, expectation](NThreading::TFuture<NYdb::NTable::TCreateSessionResult> f) {
tClient.CreateSession().Subscribe([rrPtr, request, expectation](NThreading::TFuture<NYdb::NTable::TCreateSessionResult> f) {
auto session = f.GetValueSync().GetSession();
session.ExecuteSchemeQuery(requestInt).Subscribe([rrPtr, expectation, requestInt](NYdb::TAsyncStatus f)
session.ExecuteSchemeQuery(request).Subscribe([rrPtr, expectation, request](NYdb::TAsyncStatus f)
{
TStringStream ss;
f.GetValueSync().GetIssues().PrintTo(ss, false);
Cerr << "REQUEST=" << requestInt << ";RESULT=" << ss.Str() << ";EXPECTATION=" << expectation << Endl;
Cerr << "REQUEST=" << request << ";RESULT=" << ss.Str() << ";EXPECTATION=" << expectation << Endl;
UNIT_ASSERT(expectation == f.GetValueSync().IsSuccess());
*rrPtr = true;
});
Expand All @@ -165,6 +164,39 @@ void THelper::StartSchemaRequest(const TString& request, const bool expectSucces
}
}

void THelper::StartSchemaRequestQueryServiceImpl(const TString& request, const bool expectation, const bool waiting) const {
NYdb::NQuery::TQueryClient qClient(Server.GetDriver(),
NYdb::NQuery::TClientSettings().AuthToken("root@builtin"));

std::shared_ptr<bool> rrPtr = std::make_shared<bool>(false);
auto future = qClient.ExecuteQuery(request, NYdb::NQuery::TTxControl::NoTx());
future.Subscribe([rrPtr, expectation, request](NYdb::NQuery::TAsyncExecuteQueryResult f)
{
TStringStream ss;
f.GetValueSync().GetIssues().PrintTo(ss, false);
Cerr << "REQUEST=" << request << ";RESULT=" << ss.Str() << ";EXPECTATION=" << expectation << Endl;
*rrPtr = true;
});
Cerr << "REQUEST=" << request << ";EXPECTATION=" << expectation << ";WAITING=" << waiting << Endl;
if (waiting) {
const TInstant start = TInstant::Now();
while (!*rrPtr && start + TDuration::Seconds(20) > TInstant::Now()) {
Server.GetRuntime()->SimulateSleep(TDuration::Seconds(1));
}
UNIT_ASSERT(*rrPtr);
UNIT_ASSERT_C(expectation == future.GetValueSync().IsSuccess(), future.GetValueSync().GetIssues().ToString());
Cerr << "FINISHED_REQUEST=" << request << ";EXPECTATION=" << expectation << ";WAITING=" << waiting << Endl;
}
}

void THelper::StartSchemaRequest(const TString& request, const bool expectSuccess, const bool waiting) const {
if (UseQueryService) {
StartSchemaRequestQueryServiceImpl(request, expectSuccess, waiting);
} else {
StartSchemaRequestTableServiceImpl(request, expectSuccess, waiting);
}
}

void THelper::DropTable(const TString& tablePath) {
auto* runtime = Server.GetRuntime();
Ydb::Table::DropTableRequest request;
Expand Down
8 changes: 8 additions & 0 deletions ydb/core/testlib/common_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,21 @@ class THelper {
void WaitForSchemeOperation(TActorId sender, ui64 txId);
void PrintResultSet(const NYdb::TResultSet& resultSet, NYson::TYsonWriter& writer) const;

void StartSchemaRequestTableServiceImpl(const TString& request, const bool expectSuccess, const bool waiting) const;
void StartSchemaRequestQueryServiceImpl(const TString& request, const bool expectSuccess, const bool waiting) const;

Tests::TServer& Server;
bool UseQueryService = false;
public:
THelper(TServer& server)
: Server(server) {

}

void SetUseQueryService(bool use = true) {
UseQueryService = use;
}

void DropTable(const TString& tablePath);

void StartScanRequest(const TString& request, const bool expectSuccess, TVector<THashMap<TString, NYdb::TValue>>* result) const;
Expand Down
1 change: 1 addition & 0 deletions ydb/core/testlib/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ PEERDIR(
ydb/public/lib/deprecated/kicli
ydb/public/sdk/cpp/client/ydb_driver
ydb/public/sdk/cpp/client/ydb_persqueue_public/codecs
ydb/public/sdk/cpp/client/ydb_query
ydb/public/sdk/cpp/client/ydb_table
ydb/services/auth
ydb/services/cms
Expand Down
12 changes: 0 additions & 12 deletions ydb/services/metadata/secret/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ NModifications::TOperationParsingResult TAccessManager::DoBuildPatchFromSettings
return result;
}

NMetadata::NModifications::IOperationsManager::TYqlConclusionStatus TAccessManager::DoPrepare(NKqpProto::TKqpSchemeOperation& /*schemeOperation*/, const NYql::TObjectSettingsImpl& /*settings*/,
const NMetadata::IClassBehaviour::TPtr& /*manager*/, NMetadata::NModifications::IOperationsManager::TInternalModificationContext& /*context*/) const {
return NMetadata::NModifications::IOperationsManager::TYqlConclusionStatus::Fail(
"Prepare operations for SECRET_ACCESS objects are not supported");
}

NThreading::TFuture<NMetadata::NModifications::IOperationsManager::TYqlConclusionStatus> TAccessManager::ExecutePrepared(const NKqpProto::TKqpSchemeOperation& /*schemeOperation*/,
const ui32 /*nodeId*/, const NMetadata::IClassBehaviour::TPtr& /*manager*/, const IOperationsManager::TExternalModificationContext& /*context*/) const {
return NThreading::MakeFuture(NMetadata::NModifications::IOperationsManager::TYqlConclusionStatus::Fail(
"Execution of prepare operations for SECRET_ACCESS objects is not supported"));
}

NModifications::TOperationParsingResult TSecretManager::DoBuildPatchFromSettings(const NYql::TObjectSettingsImpl& settings,
TInternalModificationContext& context) const {
static const TString ExtraPathSymbolsAllowed = "!\"#$%&'()*+,-.:;<=>?@[\\]^_`{|}~";
Expand Down
6 changes: 0 additions & 6 deletions ydb/services/metadata/secret/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class TAccessManager: public NModifications::TGenericOperationsManager<TAccess>

virtual NModifications::TOperationParsingResult DoBuildPatchFromSettings(const NYql::TObjectSettingsImpl& settings,
TInternalModificationContext& context) const override;

virtual IOperationsManager::TYqlConclusionStatus DoPrepare(NKqpProto::TKqpSchemeOperation& schemeOperation, const NYql::TObjectSettingsImpl& settings,
const NMetadata::IClassBehaviour::TPtr& manager, IOperationsManager::TInternalModificationContext& context) const override;

virtual NThreading::TFuture<IOperationsManager::TYqlConclusionStatus> ExecutePrepared(const NKqpProto::TKqpSchemeOperation& schemeOperation,
const ui32 nodeId, const NMetadata::IClassBehaviour::TPtr& manager, const IOperationsManager::TExternalModificationContext& context) const override;
};

}
54 changes: 48 additions & 6 deletions ydb/services/metadata/secret/ut/ut_secret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,23 @@ Y_UNIT_TEST_SUITE(Secret) {
}
};

Y_UNIT_TEST(Simple) {
void SimpleImpl(bool useQueryService) {
TPortManager pm;

ui32 grpcPort = pm.GetPort();
ui32 msgbPort = pm.GetPort();

NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);

Tests::TServerSettings serverSettings(msgbPort);
serverSettings.Port = msgbPort;
serverSettings.GrpcPort = grpcPort;
serverSettings.SetDomainName("Root")
.SetUseRealThreads(false)
.SetEnableMetadataProvider(true)
.SetEnableOlapSchemaOperations(true);
.SetEnableOlapSchemaOperations(true)
.SetAppConfig(appConfig);
;

Tests::TServer::TPtr server = new Tests::TServer(serverSettings);
Expand All @@ -185,6 +189,8 @@ Y_UNIT_TEST_SUITE(Secret) {
Cerr << "Initialization finished" << Endl;

Tests::NCS::THelper lHelper(*server);
lHelper.SetUseQueryService(useQueryService);

lHelper.StartSchemaRequest("CREATE OBJECT secret1 (TYPE SECRET) WITH value = `100`");
lHelper.StartSchemaRequest("UPSERT OBJECT secret1_1 (TYPE SECRET) WITH value = `100`");
lHelper.StartSchemaRequest("UPSERT OBJECT secret1_1 (TYPE SECRET) WITH value = `200`");
Expand Down Expand Up @@ -235,19 +241,31 @@ Y_UNIT_TEST_SUITE(Secret) {
}
}

Y_UNIT_TEST(Validation) {
Y_UNIT_TEST(Simple) {
SimpleImpl(false);
}

Y_UNIT_TEST(SimpleQueryService) {
SimpleImpl(true);
}

void ValidationImpl(bool useQueryService) {
TPortManager pm;

ui32 grpcPort = pm.GetPort();
ui32 msgbPort = pm.GetPort();

NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);

Tests::TServerSettings serverSettings(msgbPort);
serverSettings.Port = msgbPort;
serverSettings.GrpcPort = grpcPort;
serverSettings.SetDomainName("Root")
.SetUseRealThreads(false)
.SetEnableMetadataProvider(true)
.SetEnableOlapSchemaOperations(true);
.SetEnableOlapSchemaOperations(true)
.SetAppConfig(appConfig);
;

Tests::TServer::TPtr server = new Tests::TServer(serverSettings);
Expand All @@ -265,6 +283,8 @@ Y_UNIT_TEST_SUITE(Secret) {
Cerr << "Initialization finished" << Endl;

Tests::NCS::THelper lHelper(*server);
lHelper.SetUseQueryService(useQueryService);

lHelper.StartSchemaRequest("CREATE OBJECT secret-1 (TYPE SECRET) WITH value = `100`", false);
lHelper.StartSchemaRequest("ALTER OBJECT secret1 (TYPE SECRET) SET value = `abcde`", false);
lHelper.StartSchemaRequest("CREATE OBJECT secret1 (TYPE SECRET) WITH value = `100`");
Expand All @@ -281,19 +301,31 @@ Y_UNIT_TEST_SUITE(Secret) {
}
}

Y_UNIT_TEST(Deactivated) {
Y_UNIT_TEST(Validation) {
ValidationImpl(false);
}

Y_UNIT_TEST(ValidationQueryService) {
ValidationImpl(true);
}

void DeactivatedImpl(bool useQueryService) {
TPortManager pm;

ui32 grpcPort = pm.GetPort();
ui32 msgbPort = pm.GetPort();

NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);

Tests::TServerSettings serverSettings(msgbPort);
serverSettings.Port = msgbPort;
serverSettings.GrpcPort = grpcPort;
serverSettings.SetDomainName("Root")
.SetUseRealThreads(false)
.SetEnableMetadataProvider(false)
.SetEnableOlapSchemaOperations(true);
.SetEnableOlapSchemaOperations(true)
.SetAppConfig(appConfig);
;

Tests::TServer::TPtr server = new Tests::TServer(serverSettings);
Expand All @@ -311,8 +343,18 @@ Y_UNIT_TEST_SUITE(Secret) {
Cerr << "Initialization finished" << Endl;

Tests::NCS::THelper lHelper(*server);
lHelper.SetUseQueryService(useQueryService);

lHelper.StartSchemaRequest("CREATE OBJECT secret1 (TYPE SECRET) WITH value = `100`", false);
}
}

Y_UNIT_TEST(Deactivated) {
DeactivatedImpl(false);
}

Y_UNIT_TEST(DeactivatedQueryService) {
DeactivatedImpl(true);
}
}
}