Skip to content

Commit 8535261

Browse files
committed
KIKIMR-21403: add StaleRO followers usage test
1 parent 2ce0570 commit 8535261

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

ydb/core/kqp/ut/common/kqp_ut_common.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,36 @@ void WaitForZeroReadIterators(Tests::TServer& server, const TString& path) {
14721472
UNIT_ASSERT_C(iterators == 0, "Unable to wait for proper read iterator count, it looks like cancelation doesn`t work (" << iterators << ")");
14731473
}
14741474

1475+
int GetCumulativeCounterValue(Tests::TServer& server, const TString& path, const TString& counterName) {
1476+
int result = 0;
1477+
1478+
TTestActorRuntime* runtime = server.GetRuntime();
1479+
auto sender = runtime->AllocateEdgeActor();
1480+
auto shards = GetTableShards(&server, sender, path);
1481+
UNIT_ASSERT_C(shards.size() > 0, "Table: " << path << " has no shards");
1482+
1483+
for (auto x : shards) {
1484+
runtime->SendToPipe(
1485+
x,
1486+
sender,
1487+
new TEvTablet::TEvGetCounters,
1488+
0,
1489+
GetPipeConfigWithRetries());
1490+
1491+
auto ev = runtime->GrabEdgeEvent<TEvTablet::TEvGetCountersResponse>(sender);
1492+
UNIT_ASSERT(ev);
1493+
1494+
const NKikimrTabletBase::TEvGetCountersResponse& resp = ev->Get()->Record;
1495+
for (const auto& counter : resp.GetTabletCounters().GetAppCounters().GetCumulativeCounters()) {
1496+
if (counter.GetName() == counterName) {
1497+
result += counter.GetValue();
1498+
}
1499+
}
1500+
}
1501+
1502+
return result;
1503+
}
1504+
14751505
NJson::TJsonValue SimplifyPlan(NJson::TJsonValue& opt, const TGetPlanParams& params) {
14761506
const auto& [_, nodeType] = *opt.GetMapSafe().find("Node Type");
14771507
bool isShuffle = nodeType.GetStringSafe().find("HashShuffle") != TString::npos;

ydb/core/kqp/ut/common/kqp_ut_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ TVector<ui64> GetColumnTableShards(Tests::TServer* server, TActorId sender, cons
382382

383383
void WaitForZeroSessions(const NKqp::TKqpCounters& counters);
384384
void WaitForZeroReadIterators(Tests::TServer& server, const TString& path);
385+
int GetCumulativeCounterValue(Tests::TServer& server, const TString& path, const TString& counterName);
385386

386387
bool JoinOrderAndAlgosMatch(const TString& optimized, const TString& reference);
387388

ydb/core/kqp/ut/opt/kqp_ne_ut.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,11 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
23072307
SELECT * FROM FollowersKv WHERE Key = 21;
23082308
)", TTxControl::BeginTx(TTxSettings::StaleRO()).CommitTx()).ExtractValueSync();
23092309
AssertSuccessResult(result);
2310+
UNIT_ASSERT_UNEQUAL(0, GetCumulativeCounterValue(
2311+
kikimr.GetTestServer(),
2312+
"/Root/FollowersKv",
2313+
"DataShard/TxUpdateFollowerReadEdge/ExecuteCPUTime"
2314+
));
23102315

23112316
CompareYson(R"(
23122317
[
@@ -2320,6 +2325,11 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
23202325
SELECT * FROM FollowersKv WHERE Value != "One" ORDER BY Key;
23212326
)", TTxControl::BeginTx(TTxSettings::StaleRO()).CommitTx()).ExtractValueSync();
23222327
AssertSuccessResult(result);
2328+
UNIT_ASSERT_UNEQUAL(0, GetCumulativeCounterValue(
2329+
kikimr.GetTestServer(),
2330+
"/Root/FollowersKv",
2331+
"DataShard/TxUpdateFollowerReadEdge/ExecuteCPUTime"
2332+
));
23232333

23242334
CompareYson(R"(
23252335
[
@@ -2335,6 +2345,11 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
23352345
SELECT * FROM TwoShard WHERE Key = 2;
23362346
)", TTxControl::BeginTx(TTxSettings::StaleRO()).CommitTx()).ExtractValueSync();
23372347
AssertSuccessResult(result);
2348+
UNIT_ASSERT_EQUAL(0, GetCumulativeCounterValue(
2349+
kikimr.GetTestServer(),
2350+
"/Root/TwoShard",
2351+
"DataShard/TxUpdateFollowerReadEdge/ExecuteCPUTime"
2352+
));
23382353

23392354
CompareYson(R"(
23402355
[
@@ -2355,6 +2370,11 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
23552370
[[4000000001u];["BigOne"];[-1]]
23562371
]
23572372
)", FormatResultSetYson(result.GetResultSet(0)));
2373+
UNIT_ASSERT_EQUAL(0, GetCumulativeCounterValue(
2374+
kikimr.GetTestServer(),
2375+
"/Root/TwoShard",
2376+
"DataShard/TxUpdateFollowerReadEdge/ExecuteCPUTime"
2377+
));
23582378
}
23592379

23602380
Y_UNIT_TEST(StaleRO_Immediate) {
@@ -2379,6 +2399,66 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
23792399
)", FormatResultSetYson(result.GetResultSet(0)));
23802400
}
23812401

2402+
Y_UNIT_TEST_TWIN(StaleRO_IndexFollowers, EnableFollowers) {
2403+
auto kikimr = DefaultKikimrRunner();
2404+
auto db = kikimr.GetTableClient();
2405+
auto session = db.CreateSession().GetValueSync().GetSession();
2406+
2407+
AssertSuccessResult(session.ExecuteSchemeQuery(R"(
2408+
--!syntax_v1
2409+
CREATE TABLE `KeySubkey` (
2410+
Key Uint64,
2411+
Subkey Uint64,
2412+
Value String,
2413+
Order Uint32,
2414+
PRIMARY KEY (Key, Subkey)
2415+
);
2416+
2417+
ALTER TABLE `KeySubkey` ADD INDEX `idx` GLOBAL SYNC ON (`Key`, `Order`) COVER (`Value`);
2418+
)").GetValueSync());
2419+
2420+
if constexpr (EnableFollowers) {
2421+
AssertSuccessResult(session.ExecuteSchemeQuery(R"(
2422+
--!syntax_v1
2423+
ALTER TABLE `KeySubkey` ALTER INDEX `idx` SET READ_REPLICAS_SETTINGS "PER_AZ:1";
2424+
)").GetValueSync());
2425+
}
2426+
2427+
AssertSuccessResult(session.ExecuteDataQuery(R"(
2428+
--!syntax_v1
2429+
2430+
REPLACE INTO `KeySubkey` (`Key`, `Subkey`, `Value`, `Order`) VALUES
2431+
(1u, 2u, "One", 7u),
2432+
(1u, 3u, "Two", 4u),
2433+
(21u, 8u, "Three", 1u),
2434+
(31u, 0u, "Four", 8u);
2435+
)", TTxControl::BeginTx().CommitTx()).GetValueSync());
2436+
2437+
auto result = session.ExecuteDataQuery(R"(
2438+
--!syntax_v1
2439+
SELECT * FROM `KeySubkey` VIEW `idx` WHERE Key = 1 ORDER BY `Order`;
2440+
)", TTxControl::BeginTx(TTxSettings::StaleRO()).CommitTx()).ExtractValueSync();
2441+
AssertSuccessResult(result);
2442+
2443+
const auto FollowerCpuTime = GetCumulativeCounterValue(
2444+
kikimr.GetTestServer(),
2445+
"/Root/KeySubkey/idx/indexImplTable",
2446+
"DataShard/TxUpdateFollowerReadEdge/ExecuteCPUTime"
2447+
);
2448+
if constexpr (EnableFollowers) {
2449+
UNIT_ASSERT_UNEQUAL(0, FollowerCpuTime);
2450+
} else {
2451+
UNIT_ASSERT_EQUAL(0, FollowerCpuTime);
2452+
}
2453+
2454+
CompareYson(R"(
2455+
[
2456+
[[1u];[4u];[3u];["Two"]];
2457+
[[1u];[7u];[2u];["One"]];
2458+
]
2459+
)", FormatResultSetYson(result.GetResultSet(0)));
2460+
}
2461+
23822462
Y_UNIT_TEST(ReadRangeWithParams) {
23832463
auto kikimr = DefaultKikimrRunner();
23842464
auto db = kikimr.GetTableClient();

0 commit comments

Comments
 (0)