Skip to content

Commit 0523407

Browse files
authored
Move CDC_Write test to slow (#12129)
1 parent d6d5488 commit 0523407

File tree

3 files changed

+192
-124
lines changed

3 files changed

+192
-124
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#include <ydb/core/persqueue/ut/common/autoscaling_ut_common.h>
2+
3+
#include <ydb/public/sdk/cpp/client/ydb_topic/ut/ut_utils/topic_sdk_test_setup.h>
4+
5+
#include <library/cpp/testing/unittest/registar.h>
6+
#include <ydb/core/persqueue/partition_key_range/partition_key_range.h>
7+
#include <ydb/core/persqueue/partition_scale_manager.h>
8+
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
9+
#include <ydb/core/tx/schemeshard/ut_helpers/test_env.h>
10+
11+
#include <util/stream/output.h>
12+
13+
namespace NKikimr {
14+
15+
using namespace NYdb::NTopic;
16+
using namespace NYdb::NTopic::NTests;
17+
using namespace NSchemeShardUT_Private;
18+
using namespace NKikimr::NPQ::NTest;
19+
20+
Y_UNIT_TEST_SUITE(SlowTopicAutopartitioning) {
21+
22+
void ExecuteQuery(NYdb::NTable::TSession& session, const TString& query ) {
23+
const auto result = session.ExecuteSchemeQuery(query).GetValueSync();
24+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
25+
}
26+
27+
void ExecuteDataQuery(NYdb::NTable::TSession& session, const TString& query ) {
28+
const auto result = session.ExecuteDataQuery(query, NYdb::NTable::TTxControl::BeginTx().CommitTx()).GetValueSync();
29+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
30+
}
31+
32+
ui64 GetBalancerTabletId(TTopicSdkTestSetup& setup, const TString& topicPath) {
33+
auto pathDescr = setup.GetServer().AnnoyingClient->Ls(topicPath)->Record.GetPathDescription().GetSelf();
34+
auto balancerTabletId = pathDescr.GetBalancerTabletID();
35+
Cerr << ">>>>> BalancerTabletID=" << balancerTabletId << Endl << Flush;
36+
UNIT_ASSERT(balancerTabletId);
37+
return balancerTabletId;
38+
}
39+
40+
void SplitPartitionRB(TTopicSdkTestSetup& setup, const TString& topicPath, ui32 partitionId) {
41+
auto balancerTabletId = GetBalancerTabletId(setup, topicPath);
42+
auto edge = setup.GetRuntime().AllocateEdgeActor();
43+
setup.GetRuntime().SendToPipe(balancerTabletId, edge, new TEvPQ::TEvPartitionScaleStatusChanged(partitionId, NKikimrPQ::EScaleStatus::NEED_SPLIT));
44+
}
45+
46+
void AssertPartitionCount(TTopicSdkTestSetup& setup, const TString& topicPath, size_t expectedCount) {
47+
auto client = setup.MakeClient();
48+
auto describe = client.DescribeTopic(topicPath).GetValueSync();
49+
UNIT_ASSERT_VALUES_EQUAL(describe.GetTopicDescription().GetPartitions().size(), expectedCount);
50+
}
51+
52+
void WaitAndAssertPartitionCount(TTopicSdkTestSetup& setup, const TString& topicPath, size_t expectedCount) {
53+
auto client = setup.MakeClient();
54+
size_t partitionCount = 0;
55+
for (size_t i = 0; i < 10; ++i) {
56+
Sleep(TDuration::Seconds(1));
57+
auto describe = client.DescribeTopic(topicPath).GetValueSync();
58+
partitionCount = describe.GetTopicDescription().GetPartitions().size();
59+
if (partitionCount == expectedCount) {
60+
break;
61+
}
62+
}
63+
UNIT_ASSERT_VALUES_EQUAL(partitionCount, expectedCount);
64+
}
65+
66+
void AssertMessageCountInTopic(TTopicClient client, const TString& topicPath, size_t expected, TDuration timeout = TDuration::Seconds(300)) {
67+
TInstant deadlineTime = TInstant::Now() + timeout;
68+
69+
size_t count = 0;
70+
71+
auto reader = client.CreateReadSession(
72+
TReadSessionSettings()
73+
.AutoPartitioningSupport(true)
74+
.AppendTopics(TTopicReadSettings(topicPath))
75+
.ConsumerName("consumer-1"));
76+
while(deadlineTime > TInstant::Now()) {
77+
for (auto event : reader->GetEvents(false)) {
78+
if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TDataReceivedEvent>(&event)) {
79+
count += x->GetMessages().size();
80+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStartPartitionSessionEvent>(&event)) {
81+
x->Confirm();
82+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
83+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TCommitOffsetAcknowledgementEvent>(&event)) {
84+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
85+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionStatusEvent>(&event)) {
86+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
87+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStopPartitionSessionEvent>(&event)) {
88+
x->Confirm();
89+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
90+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionClosedEvent>(&event)) {
91+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
92+
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TEndPartitionSessionEvent>(&event)) {
93+
x->Confirm();
94+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
95+
} else if (auto* sessionClosedEvent = std::get_if<NYdb::NTopic::TSessionClosedEvent>(&event)) {
96+
x->Confirm();
97+
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
98+
}
99+
100+
if (count == expected) {
101+
return;
102+
}
103+
}
104+
Sleep(TDuration::MilliSeconds(250));
105+
}
106+
107+
UNIT_ASSERT_VALUES_EQUAL(expected, count);
108+
}
109+
110+
Y_UNIT_TEST(CDC_Write) {
111+
TTopicSdkTestSetup setup = CreateSetup();
112+
auto client = setup.MakeClient();
113+
auto tableClient = setup.MakeTableClient();
114+
auto session = tableClient.CreateSession().GetValueSync().GetSession();
115+
116+
ExecuteQuery(session, R"(
117+
--!syntax_v1
118+
CREATE TABLE `/Root/origin` (
119+
id UInt64,
120+
order UInt64,
121+
value Text,
122+
PRIMARY KEY (id, order)
123+
) WITH (
124+
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 64,
125+
AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 64,
126+
UNIFORM_PARTITIONS = 64
127+
);
128+
)");
129+
130+
ExecuteQuery(session, R"(
131+
--!syntax_v1
132+
ALTER TABLE `/Root/origin`
133+
ADD CHANGEFEED `feed` WITH (
134+
MODE = 'UPDATES',
135+
FORMAT = 'JSON',
136+
TOPIC_AUTO_PARTITIONING = 'ENABLED',
137+
TOPIC_MIN_ACTIVE_PARTITIONS = 2
138+
);
139+
)");
140+
141+
{
142+
TAlterTopicSettings alterSettings;
143+
alterSettings
144+
.BeginAlterPartitioningSettings()
145+
.MinActivePartitions(1)
146+
.MaxActivePartitions(10000)
147+
.BeginAlterAutoPartitioningSettings()
148+
.Strategy(EAutoPartitioningStrategy::ScaleUp)
149+
.StabilizationWindow(TDuration::Seconds(1))
150+
.DownUtilizationPercent(1)
151+
.UpUtilizationPercent(2)
152+
.EndAlterAutoPartitioningSettings()
153+
.EndAlterTopicPartitioningSettings()
154+
.BeginAddConsumer()
155+
.ConsumerName("consumer-1")
156+
.EndAddConsumer();
157+
auto f = client.AlterTopic("/Root/origin/feed", alterSettings);
158+
f.Wait();
159+
160+
auto v = f.GetValueSync();
161+
UNIT_ASSERT_C(v.IsSuccess(), "Error: " << v);
162+
}
163+
164+
Cerr << ">>>>> " << TInstant::Now() << " Start table insert" << Endl << Flush;
165+
ExecuteDataQuery(session, R"(
166+
--!syntax_v1
167+
$sample = AsList(
168+
AsStruct(ListFromRange(0, 150000) AS v)
169+
);
170+
171+
UPSERT INTO `/Root/origin` (id, order, value)
172+
SELECT
173+
RandomNumber(v) AS id,
174+
v AS order,
175+
CAST('0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF' AS Utf8?) AS value
176+
FROM as_table($sample)
177+
FLATTEN BY (v);
178+
)");
179+
180+
Cerr << ">>>>> " << TInstant::Now() << " Start read topic" << Endl << Flush;
181+
AssertMessageCountInTopic(client, "/Root/origin/feed/streamImpl", 150000);
182+
Cerr << ">>>>> " << TInstant::Now() << " End" << Endl << Flush;
183+
}
184+
}
185+
186+
} // namespace NKikimr

ydb/core/persqueue/ut/slow/ya.make

+6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ PEERDIR(
1212
library/cpp/svnversion
1313
ydb/core/persqueue/ut/common
1414
ydb/core/testlib/default
15+
ydb/public/sdk/cpp/client/ydb_persqueue_core/ut/ut_utils
16+
ydb/public/sdk/cpp/client/ydb_persqueue_public/ut/ut_utils
17+
ydb/public/sdk/cpp/client/ydb_topic/ut/ut_utils
18+
19+
ydb/core/tx/schemeshard/ut_helpers
1520
)
1621

1722
YQL_LAST_ABI_VERSION()
1823

1924
SRCS(
25+
autopartitioning_ut.cpp
2026
pq_ut.cpp
2127
)
2228

ydb/core/persqueue/ut/ut_with_sdk/autoscaling_ut.cpp

-124
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,6 @@ Y_UNIT_TEST_SUITE(TopicAutoscaling) {
929929
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
930930
}
931931

932-
void ExecuteDataQuery(NYdb::NTable::TSession& session, const TString& query ) {
933-
const auto result = session.ExecuteDataQuery(query, NYdb::NTable::TTxControl::BeginTx().CommitTx()).GetValueSync();
934-
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::SUCCESS, result.GetIssues().ToString());
935-
}
936-
937932
ui64 GetBalancerTabletId(TTopicSdkTestSetup& setup, const TString& topicPath) {
938933
auto pathDescr = setup.GetServer().AnnoyingClient->Ls(topicPath)->Record.GetPathDescription().GetSelf();
939934
auto balancerTabletId = pathDescr.GetBalancerTabletID();
@@ -1016,125 +1011,6 @@ Y_UNIT_TEST_SUITE(TopicAutoscaling) {
10161011
WaitAndAssertPartitionCount(setup, "/Root/origin/feed", 3);
10171012
}
10181013

1019-
void AssertMessageCountInTopic(TTopicClient client, const TString& topicPath, size_t expected, TDuration timeout = TDuration::Seconds(30)) {
1020-
TInstant deadlineTime = TInstant::Now() + timeout;
1021-
1022-
size_t count = 0;
1023-
1024-
auto reader = client.CreateReadSession(
1025-
TReadSessionSettings()
1026-
.AutoPartitioningSupport(true)
1027-
.AppendTopics(TTopicReadSettings(topicPath))
1028-
.ConsumerName("consumer-1"));
1029-
while(deadlineTime > TInstant::Now()) {
1030-
for (auto event : reader->GetEvents(false)) {
1031-
if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TDataReceivedEvent>(&event)) {
1032-
count += x->GetMessages().size();
1033-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStartPartitionSessionEvent>(&event)) {
1034-
x->Confirm();
1035-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1036-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TCommitOffsetAcknowledgementEvent>(&event)) {
1037-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1038-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionStatusEvent>(&event)) {
1039-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1040-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TStopPartitionSessionEvent>(&event)) {
1041-
x->Confirm();
1042-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1043-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TPartitionSessionClosedEvent>(&event)) {
1044-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1045-
} else if (auto* x = std::get_if<NYdb::NTopic::TReadSessionEvent::TEndPartitionSessionEvent>(&event)) {
1046-
x->Confirm();
1047-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1048-
} else if (auto* sessionClosedEvent = std::get_if<NYdb::NTopic::TSessionClosedEvent>(&event)) {
1049-
x->Confirm();
1050-
Cerr << ">>>>> " << x->DebugString() << Endl << Flush;
1051-
}
1052-
1053-
if (count == expected) {
1054-
return;
1055-
}
1056-
}
1057-
Sleep(TDuration::MilliSeconds(250));
1058-
}
1059-
1060-
UNIT_ASSERT_VALUES_EQUAL(expected, count);
1061-
}
1062-
1063-
Y_UNIT_TEST(CDC_Write) {
1064-
TTopicSdkTestSetup setup = CreateSetup();
1065-
auto client = setup.MakeClient();
1066-
auto tableClient = setup.MakeTableClient();
1067-
auto session = tableClient.CreateSession().GetValueSync().GetSession();
1068-
1069-
ExecuteQuery(session, R"(
1070-
--!syntax_v1
1071-
CREATE TABLE `/Root/origin` (
1072-
id UInt64,
1073-
order UInt64,
1074-
value Text,
1075-
PRIMARY KEY (id, order)
1076-
) WITH (
1077-
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 64,
1078-
AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 64,
1079-
UNIFORM_PARTITIONS = 64
1080-
);
1081-
)");
1082-
1083-
ExecuteQuery(session, R"(
1084-
--!syntax_v1
1085-
ALTER TABLE `/Root/origin`
1086-
ADD CHANGEFEED `feed` WITH (
1087-
MODE = 'UPDATES',
1088-
FORMAT = 'JSON',
1089-
TOPIC_AUTO_PARTITIONING = 'ENABLED',
1090-
TOPIC_MIN_ACTIVE_PARTITIONS = 2
1091-
);
1092-
)");
1093-
1094-
{
1095-
TAlterTopicSettings alterSettings;
1096-
alterSettings
1097-
.BeginAlterPartitioningSettings()
1098-
.MinActivePartitions(1)
1099-
.MaxActivePartitions(10000)
1100-
.BeginAlterAutoPartitioningSettings()
1101-
.Strategy(EAutoPartitioningStrategy::ScaleUp)
1102-
.StabilizationWindow(TDuration::Seconds(1))
1103-
.DownUtilizationPercent(1)
1104-
.UpUtilizationPercent(2)
1105-
.EndAlterAutoPartitioningSettings()
1106-
.EndAlterTopicPartitioningSettings()
1107-
.BeginAddConsumer()
1108-
.ConsumerName("consumer-1")
1109-
.EndAddConsumer();
1110-
auto f = client.AlterTopic("/Root/origin/feed", alterSettings);
1111-
f.Wait();
1112-
1113-
auto v = f.GetValueSync();
1114-
UNIT_ASSERT_C(v.IsSuccess(), "Error: " << v);
1115-
}
1116-
1117-
Cerr << ">>>>> " << TInstant::Now() << " Start table insert" << Endl << Flush;
1118-
ExecuteDataQuery(session, R"(
1119-
--!syntax_v1
1120-
$sample = AsList(
1121-
AsStruct(ListFromRange(0, 150000) AS v)
1122-
);
1123-
1124-
UPSERT INTO `/Root/origin` (id, order, value)
1125-
SELECT
1126-
RandomNumber(v) AS id,
1127-
v AS order,
1128-
CAST('0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF' AS Utf8?) AS value
1129-
FROM as_table($sample)
1130-
FLATTEN BY (v);
1131-
)");
1132-
1133-
Cerr << ">>>>> " << TInstant::Now() << " Start read topic" << Endl << Flush;
1134-
AssertMessageCountInTopic(client, "/Root/origin/feed/streamImpl", 150000);
1135-
Cerr << ">>>>> " << TInstant::Now() << " End" << Endl << Flush;
1136-
}
1137-
11381014
Y_UNIT_TEST(ControlPlane_CDC) {
11391015
TTopicSdkTestSetup setup = CreateSetup();
11401016
auto tableClient = setup.MakeTableClient();

0 commit comments

Comments
 (0)