Skip to content

Commit f81692f

Browse files
healthcheck hive sync period tests (#4619)
1 parent c054f5e commit f81692f

File tree

2 files changed

+102
-4
lines changed

2 files changed

+102
-4
lines changed

ydb/core/health_check/health_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ class TSelfCheckRequest : public TActorBootstrapped<TSelfCheckRequest> {
11701170
static const int HIVE_SYNCHRONIZATION_PERIOD_MS = 10000;
11711171

11721172
bool IsHiveSynchronizationPeriod(NKikimrHive::TEvResponseHiveInfo& hiveInfo) {
1173-
return hiveInfo.GetStartTimeTimestamp() + HIVE_SYNCHRONIZATION_PERIOD_MS < hiveInfo.GetResponseTimestamp();
1173+
return hiveInfo.GetResponseTimestamp() < hiveInfo.GetStartTimeTimestamp() + HIVE_SYNCHRONIZATION_PERIOD_MS;
11741174
}
11751175

11761176
void AggregateHiveInfo() {

ydb/core/health_check/health_check_ut.cpp

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ Y_UNIT_TEST_SUITE(THealthCheckTest) {
5959
const int GROUP_START_ID = 0x80000000;
6060
const int VCARD_START_ID = 55;
6161

62+
const TPathId SUBDOMAIN_KEY = {7000000000, 1};
6263
const TPathId SERVERLESS_DOMAIN_KEY = {7000000000, 2};
63-
const TPathId SHARED_DOMAIN_KEY = {7000000000, 1};
64+
const TPathId SHARED_DOMAIN_KEY = {7000000000, 3};
6465
const TString STORAGE_POOL_NAME = "/Root:test";
6566

6667
void ChangeDescribeSchemeResult(TEvSchemeShard::TEvDescribeSchemeResult::TPtr* ev, ui64 size = 20000000, ui64 quota = 90000000) {
@@ -1304,8 +1305,6 @@ Y_UNIT_TEST_SUITE(THealthCheckTest) {
13041305

13051306
ui32 dynNodeId = runtime.GetNodeId(1);
13061307

1307-
const TPathId SUBDOMAIN_KEY = {7000000000, 1};
1308-
13091308
auto observerFunc = [&](TAutoPtr<IEventHandle>& ev) {
13101309
switch (ev->GetTypeRewrite()) {
13111310
case NConsole::TEvConsole::EvGetTenantStatusResponse: {
@@ -1451,5 +1450,104 @@ Y_UNIT_TEST_SUITE(THealthCheckTest) {
14511450
UNIT_ASSERT_VALUES_EQUAL(database_status.storage().pools().size(), 1);
14521451
UNIT_ASSERT_VALUES_EQUAL(database_status.storage().pools()[0].id(), "static");
14531452
}
1453+
1454+
void HiveSyncTest(bool syncPeriod) {
1455+
TPortManager tp;
1456+
ui16 port = tp.GetPort(2134);
1457+
ui16 grpcPort = tp.GetPort(2135);
1458+
auto settings = TServerSettings(port)
1459+
.SetNodeCount(1)
1460+
.SetDynamicNodeCount(1)
1461+
.SetUseRealThreads(false)
1462+
.SetDomainName("Root");
1463+
TServer server(settings);
1464+
server.EnableGRpc(grpcPort);
1465+
TClient client(settings);
1466+
TTestActorRuntime& runtime = *server.GetRuntime();
1467+
1468+
ui32 dynNodeId = runtime.GetNodeId(1);
1469+
1470+
auto observerFunc = [&](TAutoPtr<IEventHandle>& ev) {
1471+
switch (ev->GetTypeRewrite()) {
1472+
case TEvHive::EvResponseHiveInfo: {
1473+
auto *x = reinterpret_cast<TEvHive::TEvResponseHiveInfo::TPtr*>(&ev);
1474+
auto& record = (*x)->Get()->Record;
1475+
record.SetStartTimeTimestamp(0);
1476+
if (syncPeriod) {
1477+
record.SetResponseTimestamp(NHealthCheck::TSelfCheckRequest::HIVE_SYNCHRONIZATION_PERIOD_MS / 2);
1478+
} else {
1479+
record.SetResponseTimestamp(NHealthCheck::TSelfCheckRequest::HIVE_SYNCHRONIZATION_PERIOD_MS * 2);
1480+
}
1481+
auto *tablet = record.MutableTablets()->Add();
1482+
tablet->SetTabletID(1);
1483+
tablet->SetNodeID(dynNodeId);
1484+
tablet->SetTabletType(NKikimrTabletBase::TTabletTypes::DataShard);
1485+
tablet->SetVolatileState(NKikimrHive::TABLET_VOLATILE_STATE_BOOTING);
1486+
tablet->MutableObjectDomain()->SetSchemeShard(SUBDOMAIN_KEY.OwnerId);
1487+
tablet->MutableObjectDomain()->SetPathId(SUBDOMAIN_KEY.LocalPathId);
1488+
break;
1489+
}
1490+
case TEvHive::EvResponseHiveNodeStats: {
1491+
auto *x = reinterpret_cast<TEvHive::TEvResponseHiveNodeStats::TPtr*>(&ev);
1492+
auto &record = (*x)->Get()->Record;
1493+
auto *nodeStats = record.MutableNodeStats()->Add();
1494+
nodeStats->SetNodeId(dynNodeId);
1495+
nodeStats->MutableNodeDomain()->SetSchemeShard(SUBDOMAIN_KEY.OwnerId);
1496+
nodeStats->MutableNodeDomain()->SetPathId(SUBDOMAIN_KEY.LocalPathId);
1497+
break;
1498+
}
1499+
case NConsole::TEvConsole::EvGetTenantStatusResponse: {
1500+
auto *x = reinterpret_cast<NConsole::TEvConsole::TEvGetTenantStatusResponse::TPtr*>(&ev);
1501+
ChangeGetTenantStatusResponse(x, "/Root/database");
1502+
break;
1503+
}
1504+
case TEvTxProxySchemeCache::EvNavigateKeySetResult: {
1505+
auto *x = reinterpret_cast<TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr*>(&ev);
1506+
TSchemeCacheNavigate::TEntry& entry((*x)->Get()->Request->ResultSet.front());
1507+
entry.Status = TSchemeCacheNavigate::EStatus::Ok;
1508+
entry.Kind = TSchemeCacheNavigate::EKind::KindExtSubdomain;
1509+
entry.Path = {"Root", "database"};
1510+
entry.DomainInfo = MakeIntrusive<TDomainInfo>(SUBDOMAIN_KEY, SUBDOMAIN_KEY);
1511+
1512+
break;
1513+
}
1514+
}
1515+
1516+
return TTestActorRuntime::EEventAction::PROCESS;
1517+
};
1518+
runtime.SetObserverFunc(observerFunc);
1519+
1520+
TActorId sender = runtime.AllocateEdgeActor();
1521+
TAutoPtr<IEventHandle> handle;
1522+
1523+
auto *request = new NHealthCheck::TEvSelfCheckRequest;
1524+
request->Request.set_return_verbose_status(true);
1525+
request->Database = "/Root/database";
1526+
runtime.Send(new IEventHandle(NHealthCheck::MakeHealthCheckID(), sender, request, 0));
1527+
const auto result = runtime.GrabEdgeEvent<NHealthCheck::TEvSelfCheckResult>(handle)->Result;
1528+
1529+
Cerr << result.ShortDebugString() << Endl;
1530+
1531+
UNIT_ASSERT_VALUES_EQUAL(result.database_status_size(), 1);
1532+
1533+
bool deadTabletIssueFoundInResult = false;
1534+
for (const auto &issue_log : result.issue_log()) {
1535+
if (issue_log.level() == 4 && issue_log.type() == "TABLET") {
1536+
UNIT_ASSERT_VALUES_EQUAL(issue_log.location().compute().tablet().id().size(), 1);
1537+
UNIT_ASSERT_VALUES_EQUAL(issue_log.location().compute().tablet().type(), "DataShard");
1538+
deadTabletIssueFoundInResult = true;
1539+
}
1540+
}
1541+
1542+
UNIT_ASSERT_VALUES_EQUAL(syncPeriod, !deadTabletIssueFoundInResult);
1543+
}
1544+
1545+
Y_UNIT_TEST(HiveSyncPeriodIgnoresTabletsState) {
1546+
HiveSyncTest(true);
1547+
}
1548+
1549+
Y_UNIT_TEST(AfterHiveSyncPeriodReportsTabletsState) {
1550+
HiveSyncTest(false);
1551+
}
14541552
}
14551553
}

0 commit comments

Comments
 (0)