Skip to content
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

issue-2969: add hive reconnect time counter #2970

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 14 additions & 9 deletions cloud/blockstore/libs/storage/init/disk_agent/actorsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ class TStorageServicesInitializer final
// HiveProxy
//

auto hiveProxy = CreateHiveProxy({
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
.HiveLockExpireTimeout = Args.StorageConfig->GetHiveLockExpireTimeout(),
.LogComponent = TBlockStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = {},
.FallbackMode = false,
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
});
auto hiveProxy = CreateHiveProxy(
{
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
.HiveLockExpireTimeout = Args.StorageConfig->GetHiveLockExpireTimeout(),
.LogComponent = TBlockStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = {},
.FallbackMode = false,
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
},
appData
->Counters
->GetSubgroup("counters", "blockstore")
->GetSubgroup("component", "service"));

setup->LocalServices.emplace_back(
MakeHiveProxyServiceId(),
Expand Down
23 changes: 14 additions & 9 deletions cloud/blockstore/libs/storage/init/server/actorsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,20 @@ class TStorageServicesInitializer final
// HiveProxy
//

auto hiveProxy = CreateHiveProxy({
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
.HiveLockExpireTimeout = Args.StorageConfig->GetHiveLockExpireTimeout(),
.LogComponent = TBlockStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = Args.StorageConfig->GetTabletBootInfoBackupFilePath(),
.FallbackMode = Args.StorageConfig->GetHiveProxyFallbackMode(),
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
});
auto hiveProxy = CreateHiveProxy(
{
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
.HiveLockExpireTimeout = Args.StorageConfig->GetHiveLockExpireTimeout(),
.LogComponent = TBlockStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = Args.StorageConfig->GetTabletBootInfoBackupFilePath(),
.FallbackMode = Args.StorageConfig->GetHiveProxyFallbackMode(),
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
},
appData
->Counters
->GetSubgroup("counters", "blockstore")
->GetSubgroup("component", "service"));

setup->LocalServices.emplace_back(
MakeHiveProxyServiceId(),
Expand Down
25 changes: 15 additions & 10 deletions cloud/filestore/libs/storage/init/actorsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,21 @@ class TStorageServicesInitializer final
// HiveProxy
//

auto hiveProxy = CreateHiveProxy({
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
// HiveLockExpireTimeout, used by NBS, doesn't matter
.HiveLockExpireTimeout = TDuration::Seconds(1),
.LogComponent = TFileStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = Args.StorageConfig->GetTabletBootInfoBackupFilePath(),
.FallbackMode = Args.StorageConfig->GetHiveProxyFallbackMode(),
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
});
auto hiveProxy = CreateHiveProxy(
{
.PipeClientRetryCount = Args.StorageConfig->GetPipeClientRetryCount(),
.PipeClientMinRetryTime = Args.StorageConfig->GetPipeClientMinRetryTime(),
// HiveLockExpireTimeout, used by NBS, doesn't matter
.HiveLockExpireTimeout = TDuration::Seconds(1),
.LogComponent = TFileStoreComponents::HIVE_PROXY,
.TabletBootInfoBackupFilePath = Args.StorageConfig->GetTabletBootInfoBackupFilePath(),
.FallbackMode = Args.StorageConfig->GetHiveProxyFallbackMode(),
.TenantHiveTabletId = Args.StorageConfig->GetTenantHiveTabletId(),
},
appData
->Counters
->GetSubgroup("counters", "filestore")
->GetSubgroup("component", "service"));

setup->LocalServices.emplace_back(
MakeHiveProxyServiceId(),
Expand Down
13 changes: 13 additions & 0 deletions cloud/storage/core/libs/hive_proxy/hive_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ IActorPtr CreateHiveProxy(THiveProxyConfig config)
return std::make_unique<THiveProxyActor>(std::move(config));
}

IActorPtr CreateHiveProxy(
THiveProxyConfig config,
NMonitoring::TDynamicCounterPtr CountersRoot)
{
if (config.FallbackMode) {
return std::make_unique<THiveProxyFallbackActor>(std::move(config));
}
yegorskii marked this conversation as resolved.
Show resolved Hide resolved

return std::make_unique<THiveProxyActor>(
std::move(config),
std::move(CountersRoot));
}

} // namespace NCloud::NStorage
5 changes: 5 additions & 0 deletions cloud/storage/core/libs/hive_proxy/hive_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
#include <cloud/storage/core/libs/actors/public.h>
#include <cloud/storage/core/libs/common/public.h>

#include <library/cpp/monlib/dynamic_counters/counters.h>

namespace NCloud::NStorage {

////////////////////////////////////////////////////////////////////////////////

NActors::IActorPtr CreateHiveProxy(THiveProxyConfig config);
NActors::IActorPtr CreateHiveProxy(
THiveProxyConfig config,
NMonitoring::TDynamicCounterPtr CountersRoot);
yegorskii marked this conversation as resolved.
Show resolved Hide resolved

} // namespace NCloud::NStorage
49 changes: 44 additions & 5 deletions cloud/storage/core/libs/hive_proxy/hive_proxy_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ std::unique_ptr<NTabletPipe::IClientCache> CreateTabletPipeClientCache(

////////////////////////////////////////////////////////////////////////////////

THiveProxyActor::THiveProxyActor(THiveProxyConfig config)
THiveProxyActor::THiveProxyActor(
THiveProxyConfig config,
NMonitoring::TDynamicCounterPtr countersRoot)
: ClientCache(CreateTabletPipeClientCache(config))
, LockExpireTimeout(config.HiveLockExpireTimeout)
, LogComponent(config.LogComponent)
, TabletBootInfoBackupFilePath(config.TabletBootInfoBackupFilePath)
, TenantHiveTabletId(config.TenantHiveTabletId)
, CountersRoot(std::move(countersRoot))
{}

THiveProxyActor::THiveProxyActor(THiveProxyConfig config)
: THiveProxyActor(std::move(config), {})
{}

void THiveProxyActor::Bootstrap(const TActorContext& ctx)
Expand All @@ -55,10 +62,26 @@ void THiveProxyActor::Bootstrap(const TActorContext& ctx)
TabletBootInfoBackup = ctx.Register(
cache.release(), TMailboxType::HTSwap, AppData()->IOPoolId);
}
if (CountersRoot) {
ReconnectPipeCounter = CountersRoot->GetCounter("HiveReconnectTime", true);
}
}

////////////////////////////////////////////////////////////////////////////////

void THiveProxyActor::SendRequest(
const TActorContext& ctx,
ui64 hive,
IEventBase* request)
{
if (auto clientId = ClientCache->Send(ctx, hive, request);
clientId != HiveClientId)
{
HiveClientId = clientId;
ReconnectStartTime = GetCycleCount();
}
}

ui64 THiveProxyActor::GetHive(
const TActorContext& ctx,
ui64 tabletId,
Expand Down Expand Up @@ -98,15 +121,15 @@ void THiveProxyActor::SendLockRequest(
hiveRequest->Record.SetMaxReconnectTimeout(
LockExpireTimeout.MilliSeconds());
hiveRequest->Record.SetReconnect(reconnect);
ClientCache->Send(ctx, hive, hiveRequest.release());
SendRequest(ctx, hive, hiveRequest.release());
}

void THiveProxyActor::SendUnlockRequest(
const TActorContext& ctx, ui64 hive, ui64 tabletId)
{
auto hiveRequest =
std::make_unique<TEvHive::TEvUnlockTabletExecution>(tabletId);
ClientCache->Send(ctx, hive, hiveRequest.release());
SendRequest(ctx, hive, hiveRequest.release());
}

void THiveProxyActor::SendGetTabletStorageInfoRequest(
Expand All @@ -115,7 +138,7 @@ void THiveProxyActor::SendGetTabletStorageInfoRequest(
{
auto hiveRequest =
std::make_unique<TEvHive::TEvGetTabletStorageInfo>(tabletId);
ClientCache->Send(ctx, hive, hiveRequest.release());
SendRequest(ctx, hive, hiveRequest.release());
}

void THiveProxyActor::SendLockReply(
Expand Down Expand Up @@ -198,7 +221,7 @@ void THiveProxyActor::SendTabletMetrics(
prTabletId.second.OnStatsSend();
}
if (record.TabletMetricsSize() > 0) {
ClientCache->Send(ctx, hive, event.Release());
SendRequest(ctx, hive, event.Release());
}
}

Expand All @@ -216,6 +239,13 @@ void THiveProxyActor::HandleConnect(
auto error = MakeKikimrError(msg->Status, TStringBuilder()
<< "Connect to hive " << hive << " failed");
HandleConnectionError(ctx, error, hive, true);
} else if (msg->ClientId == HiveClientId && ReconnectStartTime)
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
{
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
if (ReconnectPipeCounter) {
ReconnectPipeCounter->Add(
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
CyclesToDuration(GetCycleCount() - ReconnectStartTime).MicroSeconds());
}
ReconnectStartTime = 0;
}
}

Expand All @@ -227,6 +257,7 @@ void THiveProxyActor::HandleDisconnect(

ui64 hive = msg->TabletId;
ClientCache->OnDisconnect(ev);
HiveClientId = {};

auto error = MakeError(E_REJECTED, TStringBuilder()
<< "Disconnected from hive " << hive);
Expand All @@ -242,6 +273,8 @@ void THiveProxyActor::HandleConnectionError(
Y_UNUSED(error);
Y_UNUSED(connectFailed);

HiveClientId = {};

LOG_ERROR_S(ctx, LogComponent,
"Pipe to hive" << hive << " has been reset ");

Expand Down Expand Up @@ -307,6 +340,12 @@ void THiveProxyActor::HandleConnectionError(

for (const auto& actorId: states->Actors) {
auto clientId = ClientCache->Prepare(ctx, hive);
if (!HiveClientId) {
HiveClientId = clientId;
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
if (!ReconnectStartTime) {
ReconnectStartTime = GetCycleCount();
}
}
NCloud::Send<TEvHiveProxyPrivate::TEvChangeTabletClient>(
ctx,
actorId,
Expand Down
14 changes: 14 additions & 0 deletions cloud/storage/core/libs/hive_proxy/hive_proxy_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,28 @@ class THiveProxyActor final

const ui64 TenantHiveTabletId;

const NMonitoring::TDynamicCounterPtr CountersRoot;
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
NMonitoring::TDynamicCounters::TCounterPtr ReconnectPipeCounter;
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
ui64 ReconnectStartTime = 0;
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
NActors::TActorId HiveClientId;

public:
explicit THiveProxyActor(THiveProxyConfig config);

THiveProxyActor(
THiveProxyConfig config,
NMonitoring::TDynamicCounterPtr countersRoot);

void Bootstrap(const NActors::TActorContext& ctx);

private:
STFUNC(StateWork);

void SendRequest(
const NActors::TActorContext& ctx,
ui64 hive,
NActors::IEventBase* request);

ui64 GetHive(
const NActors::TActorContext& ctx,
ui64 tabletId,
Expand Down
42 changes: 41 additions & 1 deletion cloud/storage/core/libs/hive_proxy/hive_proxy_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ struct TTestEnv
.TenantHiveTabletId = tenantHive,
};
HiveProxyActorId = Runtime.Register(
CreateHiveProxy(std::move(config)).release());
CreateHiveProxy(
std::move(config), Runtime.GetAppData(0).Counters).release());
yegorskii marked this conversation as resolved.
Show resolved Hide resolved
Runtime.EnableScheduleForActor(HiveProxyActorId);
Runtime.RegisterService(MakeHiveProxyServiceId(), HiveProxyActorId);
}
Expand Down Expand Up @@ -1541,6 +1542,45 @@ Y_UNIT_TEST_SUITE(THiveProxyTest)
UNIT_ASSERT_VALUES_EQUAL(1, hiveMessages);
UNIT_ASSERT_VALUES_EQUAL(1, wakeups);
}

Y_UNIT_TEST(ShouldReportHiveReconnectTime)
{
TTestBasicRuntime runtime;
TTestEnv env(runtime);

auto sender = runtime.AllocateEdgeActor();

auto counter = env.Runtime.GetAppData(0).Counters
->GetCounter("HiveReconnectTime", true);

env.SendLockRequest(sender, FakeTablet2);
UNIT_ASSERT_VALUES_UNEQUAL(0, counter->Val());

auto oldVal = counter->Val();

int hiveLockRequests = 0;
runtime.SetObserverFunc([&](TAutoPtr<IEventHandle>& event) {
Y_UNUSED(runtime);
if (event->GetTypeRewrite() == TEvHive::EvLockTabletExecution) {
++hiveLockRequests;
}
return TTestActorRuntime::EEventAction::PROCESS;
});

env.EnableTabletResolverScheduling();
env.RebootHive();

for (int retries = 0; retries < 5 && !hiveLockRequests; ++retries) {
// Pipe to hive may take a long time to connect
// Wait until hive receives the lock request
runtime.DispatchEvents(TDispatchOptions(), TDuration::Seconds(1));
}
yegorskii marked this conversation as resolved.
Show resolved Hide resolved

runtime.SetObserverFunc(&TTestActorRuntime::DefaultObserverFunc);

// Rebooting hive should reconnect the lock
UNIT_ASSERT_GT(counter->Val(), oldVal);
}
}

} // namespace NCloud::NStorage
2 changes: 2 additions & 0 deletions cloud/storage/core/libs/hive_proxy/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ PEERDIR(
contrib/ydb/core/tablet_flat

contrib/ydb/library/actors/core

library/cpp/monlib/dynamic_counters
)

END()
Expand Down
Loading