Skip to content

Fix tests for default EvWrite #15319

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 14 commits into from
Mar 5, 2025
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
2 changes: 2 additions & 0 deletions .github/config/muted_ya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ydb/core/kqp/ut/olap [*/*] chunk chunk
ydb/core/kqp/ut/query KqpAnalyze.AnalyzeTable+ColumnStore
ydb/core/kqp/ut/query KqpAnalyze.AnalyzeTable-ColumnStore
ydb/core/kqp/ut/query KqpStats.SysViewClientLost
ydb/core/kqp/ut/query KqpLimits.OutOfSpaceYQLUpsertFail+useSink
ydb/core/kqp/ut/query KqpLimits.QSReplySizeEnsureMemoryLimits+useSink
ydb/core/kqp/ut/scheme KqpOlapScheme.TenThousandColumns
ydb/core/kqp/ut/scheme KqpScheme.AlterAsyncReplication
ydb/core/kqp/ut/scheme KqpScheme.AlterTransfer
Expand Down
12 changes: 8 additions & 4 deletions ydb/core/kqp/query_data/kqp_query_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,16 @@ void TQueryData::ValidateParameter(const TString& name, const NKikimrMiniKQL::TT
void TQueryData::PrepareParameters(const TKqpPhyTxHolder::TConstPtr& tx, const TPreparedQueryHolder::TConstPtr& preparedQuery,
NMiniKQL::TTypeEnvironment& txTypeEnv)
{
for (const auto& paramDesc : preparedQuery->GetParameters()) {
ValidateParameter(paramDesc.GetName(), paramDesc.GetType(), txTypeEnv);
if (preparedQuery) {
for (const auto& paramDesc : preparedQuery->GetParameters()) {
ValidateParameter(paramDesc.GetName(), paramDesc.GetType(), txTypeEnv);
}
}

for(const auto& paramBinding: tx->GetParamBindings()) {
MaterializeParamValue(true, paramBinding);
if (tx) {
for(const auto& paramBinding: tx->GetParamBindings()) {
MaterializeParamValue(true, paramBinding);
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions ydb/core/kqp/runtime/kqp_write_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
}
case NKikimrDataEvents::TEvWriteResult::STATUS_WRONG_SHARD_STATE:
CA_LOG_E("Got WRONG SHARD STATE for table `"
<< SchemeEntry->TableId.PathId.ToString() << "`."
<< TableId.PathId.ToString() << "`."
<< " ShardID=" << ev->Get()->Record.GetOrigin() << ","
<< " Sink=" << this->SelfId() << "."
<< getIssues().ToOneLineString());
Expand All @@ -600,7 +600,7 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
RetryResolve();
} else {
RuntimeError(
NYql::NDqProto::StatusIds::PRECONDITION_FAILED,
NYql::NDqProto::StatusIds::UNAVAILABLE,
NYql::TIssuesIds::KIKIMR_TEMPORARILY_UNAVAILABLE,
TStringBuilder() << "Wrong shard state for table `"
<< TablePath << "`.",
Expand Down Expand Up @@ -997,13 +997,13 @@ class TKqpTableWriteActor : public TActorBootstrapped<TKqpTableWriteActor> {
Schedule(reattachState.ReattachInfo.Delay, new TEvPrivate::TEvReattachToShard(ev->Get()->TabletId));
} else {
TxManager->SetError(ev->Get()->TabletId);
if (Mode == EMode::IMMEDIATE_COMMIT || Mode == EMode::COMMIT) {
if (TxManager->GetState(ev->Get()->TabletId) == IKqpTransactionManager::EXECUTING) {
RuntimeError(
NYql::NDqProto::StatusIds::UNDETERMINED,
NYql::TIssuesIds::KIKIMR_OPERATION_STATE_UNKNOWN,
TStringBuilder()
<< "Error writing to table `" << TableId.PathId.ToString() << "`"
<< ". Transaction state unknown for shard " << ev->Get()->TabletId << ".");
<< ". Transaction state unknown for tablet " << ev->Get()->TabletId << ".");
} else {
RuntimeError(
NYql::NDqProto::StatusIds::UNAVAILABLE,
Expand Down Expand Up @@ -1787,12 +1787,13 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
|| State == EState::COMMITTING
|| State == EState::ROLLINGBACK;

if (EnableStreamWrite && outOfMemory) {
if (!EnableStreamWrite && outOfMemory) {
ReplyErrorAndDie(
NYql::NDqProto::StatusIds::PRECONDITION_FAILED,
NYql::TIssuesIds::KIKIMR_PRECONDITION_FAILED,
TStringBuilder() << "Stream write queries aren't allowed.",
{});
return;
}

if (needToFlush) {
Expand Down Expand Up @@ -2363,7 +2364,7 @@ class TKqpBufferWriteActor :public TActorBootstrapped<TKqpBufferWriteActor>, pub
<< getIssues().ToOneLineString());
TxManager->SetError(ev->Get()->Record.GetOrigin());
ReplyErrorAndDie(
NYql::NDqProto::StatusIds::PRECONDITION_FAILED,
NYql::NDqProto::StatusIds::UNAVAILABLE,
NYql::TIssuesIds::KIKIMR_TEMPORARILY_UNAVAILABLE,
TStringBuilder() << "Wrong shard state for tables " << getPathes() << ".",
getIssues());
Expand Down
18 changes: 10 additions & 8 deletions ydb/core/kqp/session_actor/kqp_session_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
return true;
}

YQL_ENSURE(tx || commit);
if (tx) {
switch (tx->GetType()) {
case NKqpProto::TKqpPhyTx::TYPE_COMPUTE:
Expand All @@ -1285,15 +1286,16 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {

QueryState->QueryData->AddUVParam(paramDesc.GetName(), paramType, value);
}
}

try {
QueryState->QueryData->PrepareParameters(tx, QueryState->PreparedQuery, txCtx.TxAlloc->TypeEnv);
} catch (const yexception& ex) {
ythrow TRequestFail(Ydb::StatusIds::BAD_REQUEST) << ex.what();
}
try {
QueryState->QueryData->PrepareParameters(tx, QueryState->PreparedQuery, txCtx.TxAlloc->TypeEnv);
} catch (const yexception& ex) {
ythrow TRequestFail(Ydb::StatusIds::BAD_REQUEST) << ex.what();
}

if (tx) {
request.Transactions.emplace_back(tx, QueryState->QueryData);
} else {
YQL_ENSURE(commit);
}

QueryState->TxCtx->OnNewExecutor(literal);
Expand Down Expand Up @@ -1468,7 +1470,7 @@ class TKqpSessionActor : public TActorBootstrapped<TKqpSessionActor> {
AsyncIoFactory, QueryState ? QueryState->PreparedQuery : nullptr, SelfId(),
QueryState ? QueryState->UserRequestContext : MakeIntrusive<TUserRequestContext>("", Settings.Database, SessionId),
QueryState ? QueryState->StatementResultIndex : 0, FederatedQuerySetup,
(!Settings.TableService.GetEnableOltpSink() && QueryState && QueryState->RequestEv->GetSyntax() == Ydb::Query::Syntax::SYNTAX_PG)
(QueryState && QueryState->RequestEv->GetSyntax() == Ydb::Query::Syntax::SYNTAX_PG)
? GUCSettings : nullptr,
txCtx->ShardIdToTableInfo, txCtx->TxManager, txCtx->BufferActorId);

Expand Down
79 changes: 32 additions & 47 deletions ydb/core/kqp/ut/data_integrity/kqp_data_integrity_trails_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ namespace {
}

Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
Y_UNIT_TEST_TWIN(Upsert, LogEnabled) {
Y_UNIT_TEST_QUAD(Upsert, LogEnabled, UseSink) {
TStringStream ss;
{
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(UseSink);
TKikimrSettings serverSettings;
serverSettings.SetAppConfig(appConfig);
serverSettings.LogStream = &ss;
TKikimrRunner kikimr(serverSettings);

Expand All @@ -44,8 +47,13 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
}

// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), LogEnabled ? 2 : 0);
if (UseSink) {
// check write actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: WriteActor"), LogEnabled ? 1 : 0);
} else {
// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), LogEnabled ? 2 : 0);
}
// check session actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY DEBUG: Component: SessionActor"), LogEnabled ? 2 : 0);
// check grpc logs
Expand All @@ -54,49 +62,13 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: DataShard"), LogEnabled ? 2 : 0);
}

Y_UNIT_TEST(UpsertEvWrite) {
Y_UNIT_TEST_QUAD(UpsertEvWriteQueryService, isOlap, useOltpSink) {
TStringStream ss;
{
NKikimrConfig::TAppConfig AppConfig;
AppConfig.MutableTableServiceConfig()->SetEnableOltpSink(true);
TKikimrSettings serverSettings = TKikimrSettings().SetAppConfig(AppConfig);
serverSettings.LogStream = &ss;
TKikimrRunner kikimr(serverSettings);
kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::DATA_INTEGRITY, NLog::PRI_TRACE);

auto db = kikimr.GetTableClient();
auto session = db.CreateSession().GetValueSync().GetSession();

auto result = session.ExecuteDataQuery(R"(
--!syntax_v1

UPSERT INTO `/Root/KeyValue` (Key, Value) VALUES
(3u, "Value3"),
(101u, "Value101"),
(201u, "Value201");
)", TTxControl::BeginTx().CommitTx()).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
}
AppConfig.MutableTableServiceConfig()->SetEnableOltpSink(useOltpSink);
AppConfig.MutableTableServiceConfig()->SetEnableOlapSink(isOlap);

// check write actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: WriteActor"), 1);
// check session actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY DEBUG: Component: SessionActor"), 2);
// check grpc logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY TRACE: Component: Grpc"), 2);
// check datashard logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: DataShard"), 2);
}

Y_UNIT_TEST_TWIN(UpsertEvWriteQueryService, isOlap) {
TStringStream ss;
{
NKikimrConfig::TAppConfig AppConfig;
if (!isOlap) {
AppConfig.MutableTableServiceConfig()->SetEnableOltpSink(true);
} else {
AppConfig.MutableTableServiceConfig()->SetEnableOlapSink(true);
}
TKikimrSettings serverSettings = TKikimrSettings().SetAppConfig(AppConfig);
serverSettings.LogStream = &ss;
TKikimrRunner kikimr(serverSettings);
Expand Down Expand Up @@ -132,8 +104,13 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
}

if (!isOlap) {
// check write actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: WriteActor"), 1);
if (useOltpSink) {
// check write actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: WriteActor"), 1);
} else {
// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), 2);
}
// check session actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY DEBUG: Component: SessionActor"), 2);
// check grpc logs
Expand All @@ -143,8 +120,13 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
} else {
// check write actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: WriteActor"), 3);
// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), 11);
if (useOltpSink) {
// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), 1);
} else {
// check executer logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: Executer"), 11);
}
// check session actor logs
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY DEBUG: Component: SessionActor"), 2);
// check grpc logs
Expand Down Expand Up @@ -215,10 +197,13 @@ Y_UNIT_TEST_SUITE(KqpDataIntegrityTrails) {
UNIT_ASSERT_VALUES_EQUAL(CountSubstr(ss.Str(), "DATA_INTEGRITY INFO: Component: DataShard"), 0);
}

Y_UNIT_TEST(BrokenReadLock) {
Y_UNIT_TEST_TWIN(BrokenReadLock, UseSink) {
TStringStream ss;
{
NKikimrConfig::TAppConfig AppConfig;
AppConfig.MutableTableServiceConfig()->SetEnableOltpSink(UseSink);
TKikimrSettings serverSettings;
serverSettings.SetAppConfig(AppConfig);
serverSettings.LogStream = &ss;
TKikimrRunner kikimr(serverSettings);
kikimr.GetTestServer().GetRuntime()->SetLogPriority(NKikimrServices::DATA_INTEGRITY, NLog::PRI_TRACE);
Expand Down
20 changes: 15 additions & 5 deletions ydb/core/kqp/ut/opt/kqp_not_null_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
}
}

Y_UNIT_TEST(InsertNotNullPkPg) {
Y_UNIT_TEST_TWIN(InsertNotNullPkPg, useSink) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(useSink);
TKikimrRunner kikimr(NKqp::TKikimrSettings().SetWithSampleTables(false));
auto client = kikimr.GetTableClient();
auto session = client.CreateSession().GetValueSync().GetSession();
Expand Down Expand Up @@ -609,10 +611,13 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
}
}

Y_UNIT_TEST(InsertNotNullPg) {
Y_UNIT_TEST_TWIN(InsertNotNullPg, useSink) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(useSink);
auto settings = TKikimrSettings()
.SetWithSampleTables(false)
.SetEnableNotNullDataColumns(true);
.SetEnableNotNullDataColumns(true)
.SetAppConfig(appConfig);

TKikimrRunner kikimr(settings);
auto client = kikimr.GetTableClient();
Expand Down Expand Up @@ -648,8 +653,13 @@ Y_UNIT_TEST_SUITE(KqpNotNullColumns) {
auto result = session.ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx()).ExtractValueSync();
UNIT_ASSERT(!result.IsSuccess());
UNIT_ASSERT_C(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_COLUMN_TYPE), result.GetIssues().ToString());
UNIT_ASSERT_NO_DIFF(result.GetIssues().ToString(), "<main>: Error: Execution, code: 1060\n"
" <main>: Error: Tried to insert NULL value into NOT NULL column: Value, code: 2031\n");
if (useSink) {
UNIT_ASSERT_NO_DIFF(result.GetIssues().ToString(),
"<main>: Error: Tried to insert NULL value into NOT NULL column: Value, code: 2031\n");
} else {
UNIT_ASSERT_NO_DIFF(result.GetIssues().ToString(), "<main>: Error: Execution, code: 1060\n"
" <main>: Error: Tried to insert NULL value into NOT NULL column: Value, code: 2031\n");
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions ydb/core/kqp/ut/pg/pg_catalog_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ Y_UNIT_TEST_SUITE(PgCatalog) {
}
}

Y_UNIT_TEST(PgDatabase) {
TKikimrRunner kikimr(NKqp::TKikimrSettings().SetWithSampleTables(false));
Y_UNIT_TEST_TWIN(PgDatabase, useSink) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnableOltpSink(useSink);
TKikimrRunner kikimr(NKqp::TKikimrSettings().SetWithSampleTables(false).SetAppConfig(appConfig));
auto db = kikimr.GetQueryClient();
auto settings = NYdb::NQuery::TExecuteQuerySettings().Syntax(NYdb::NQuery::ESyntax::Pg);
{
Expand Down
Loading
Loading