Skip to content

Commit 5553713

Browse files
authored
issue-3362 [Filestore] add a sensor for direct handles (#4150)
#3362
1 parent 775968a commit 5553713

File tree

8 files changed

+117
-4
lines changed

8 files changed

+117
-4
lines changed

cloud/filestore/libs/storage/tablet/tablet_actor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class TIndexTabletActor final
9090

9191
std::atomic<i64> UsedSessionsCount{0};
9292
std::atomic<i64> UsedHandlesCount{0};
93+
std::atomic<i64> UsedDirectHandlesCount{0};
9394
std::atomic<i64> UsedLocksCount{0};
9495

9596
// Session stats
@@ -364,7 +365,8 @@ class TIndexTabletActor final
364365
const TBlobMetaMapStats& blobMetaMapStats,
365366
const TIndexTabletState::TBackpressureThresholds&
366367
backpressureThresholds,
367-
const TIndexTabletState::TBackpressureValues& backpressureValues);
368+
const TIndexTabletState::TBackpressureValues& backpressureValues,
369+
const THandlesStats& handlesStats);
368370
void UpdatePerformanceMetrics(
369371
TInstant now,
370372
const TDiagnosticsConfig& diagConfig,

cloud/filestore/libs/storage/tablet/tablet_actor_counters.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ void TIndexTabletActor::TMetrics::Register(
345345

346346
REGISTER_AGGREGATABLE_SUM(UsedSessionsCount, EMetricType::MT_ABSOLUTE);
347347
REGISTER_AGGREGATABLE_SUM(UsedHandlesCount, EMetricType::MT_ABSOLUTE);
348+
REGISTER_AGGREGATABLE_SUM(UsedDirectHandlesCount, EMetricType::MT_ABSOLUTE);
348349
REGISTER_AGGREGATABLE_SUM(UsedLocksCount, EMetricType::MT_ABSOLUTE);
349350
REGISTER_AGGREGATABLE_SUM(StatefulSessionsCount, EMetricType::MT_ABSOLUTE);
350351
REGISTER_AGGREGATABLE_SUM(StatelessSessionsCount, EMetricType::MT_ABSOLUTE);
@@ -568,7 +569,8 @@ void TIndexTabletActor::TMetrics::Update(
568569
const TInMemoryIndexStateStats& inMemoryIndexStateStats,
569570
const TBlobMetaMapStats& blobMetaMapStats,
570571
const TIndexTabletState::TBackpressureThresholds& backpressureThresholds,
571-
const TIndexTabletState::TBackpressureValues& backpressureValues)
572+
const TIndexTabletState::TBackpressureValues& backpressureValues,
573+
const THandlesStats& handlesStats)
572574
{
573575
const ui32 blockSize = fileSystem.GetBlockSize();
574576

@@ -580,6 +582,7 @@ void TIndexTabletActor::TMetrics::Update(
580582

581583
Store(UsedSessionsCount, stats.GetUsedSessionsCount());
582584
Store(UsedHandlesCount, stats.GetUsedHandlesCount());
585+
Store(UsedDirectHandlesCount, handlesStats.UsedDirectHandlesCount);
583586
Store(UsedLocksCount, stats.GetUsedLocksCount());
584587

585588
Store(FreshBytesCount, stats.GetFreshBytesCount());
@@ -816,7 +819,8 @@ void TIndexTabletActor::RegisterStatCounters(TInstant now)
816819
GetInMemoryIndexStateStats(),
817820
GetBlobMetaMapStats(),
818821
BuildBackpressureThresholds(),
819-
GetBackpressureValues());
822+
GetBackpressureValues(),
823+
GetHandlesStats());
820824

821825
// TabletStartTimestamp is intialised once per tablet lifetime and thus it is
822826
// acceptable to set it in RegisterStatCounters if it is not set yet.
@@ -876,7 +880,8 @@ void TIndexTabletActor::HandleUpdateCounters(
876880
GetInMemoryIndexStateStats(),
877881
GetBlobMetaMapStats(),
878882
BuildBackpressureThresholds(),
879-
GetBackpressureValues());
883+
GetBackpressureValues(),
884+
GetHandlesStats());
880885
SendMetricsToExecutor(ctx);
881886

882887
UpdateCountersScheduled = false;

cloud/filestore/libs/storage/tablet/tablet_state.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ TMiscNodeStats TIndexTabletState::GetMiscNodeStats() const
234234
};
235235
}
236236

237+
THandlesStats TIndexTabletState::GetHandlesStats() const
238+
{
239+
return {
240+
.UsedDirectHandlesCount = Impl->UsedDirectHandlesCount,
241+
};
242+
}
243+
237244
ui64 TIndexTabletState::CalculateExpectedShardCount() const
238245
{
239246
if (FileSystem.GetShardNo()) {

cloud/filestore/libs/storage/tablet/tablet_state.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ struct TMiscNodeStats
148148
i64 OrphanNodesCount{0};
149149
};
150150

151+
struct THandlesStats
152+
{
153+
i64 UsedDirectHandlesCount{0};
154+
};
155+
151156
struct TWriteMixedBlocksResult
152157
{
153158
ui32 GarbageBlocksCount = 0;
@@ -341,6 +346,7 @@ class TIndexTabletState
341346
}
342347

343348
TMiscNodeStats GetMiscNodeStats() const;
349+
THandlesStats GetHandlesStats() const;
344350

345351
const NProto::TFileStorePerformanceProfile& GetPerformanceProfile() const;
346352

cloud/filestore/libs/storage/tablet/tablet_state_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct TIndexTabletState::TImpl
4848

4949
TNodeToSessionStat NodeToSessionStat;
5050

51+
i64 UsedDirectHandlesCount = 0;
52+
5153
TWriteRequestList WriteBatch;
5254

5355
TRangeLocks RangeLocks;

cloud/filestore/libs/storage/tablet/tablet_state_sessions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ TSessionHandle* TIndexTabletState::CreateHandle(
690690
db.WriteSessionHandle(proto);
691691
IncrementUsedHandlesCount(db);
692692

693+
if (HasFlag(proto.GetFlags(), NProto::TCreateHandleRequest::E_DIRECT)) {
694+
++Impl->UsedDirectHandlesCount;
695+
}
696+
693697
return CreateHandle(session, proto);
694698
}
695699

@@ -703,6 +707,10 @@ void TIndexTabletState::DestroyHandle(
703707

704708
DecrementUsedHandlesCount(db);
705709

710+
if (HasFlag(handle->GetFlags(), NProto::TCreateHandleRequest::E_DIRECT)) {
711+
--Impl->UsedDirectHandlesCount;
712+
}
713+
706714
ReleaseLocks(db, handle->GetHandle());
707715

708716
Impl->ReadAheadCache.OnDestroyHandle(

cloud/filestore/libs/storage/tablet/tablet_ut_counters.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,86 @@ Y_UNIT_TEST_SUITE(TIndexTabletTest_Counters)
882882
}},
883883
});
884884
}
885+
886+
Y_UNIT_TEST(ShouldReportDirectHandleMetrics)
887+
{
888+
TTestEnv env;
889+
auto registry = env.GetRegistry();
890+
891+
env.CreateSubDomain("nfs");
892+
ui32 nodeIdx = env.CreateNode("nfs");
893+
ui64 tabletId = env.BootIndexTablet(nodeIdx);
894+
895+
TIndexTabletClient tablet(env.GetRuntime(), nodeIdx, tabletId);
896+
tablet.InitSession("client", "session");
897+
898+
const auto nodeId =
899+
CreateNode(tablet, TCreateNodeArgs::File(RootNodeId, "test"));
900+
901+
auto advanceTime = [&]()
902+
{
903+
env.GetRuntime().AdvanceCurrentTime(TDuration::Seconds(15));
904+
NActors::TDispatchOptions options;
905+
options.FinalEvents.emplace_back(
906+
TEvIndexTabletPrivate::EvUpdateCounters);
907+
env.GetRuntime().DispatchEvents(options);
908+
};
909+
910+
auto checkHandlesCounters =
911+
[&](i64 expectedDirectHandles, i64 expectedUsedHandles)
912+
{
913+
TTestRegistryVisitor visitor;
914+
registry->Visit(TInstant::Zero(), visitor);
915+
visitor.ValidateExpectedCounters({
916+
{{{"sensor", "UsedDirectHandlesCount"}, {"filesystem", "test"}},
917+
expectedDirectHandles},
918+
{{{"sensor", "UsedHandlesCount"}, {"filesystem", "test"}},
919+
expectedUsedHandles},
920+
});
921+
};
922+
923+
advanceTime();
924+
checkHandlesCounters(0, 0);
925+
926+
const auto handleWithoutDirect =
927+
CreateHandle(tablet, nodeId, {}, TCreateHandleArgs::RDWR);
928+
929+
advanceTime();
930+
checkHandlesCounters(0, 1);
931+
932+
const auto handleWithDirect = CreateHandle(
933+
tablet,
934+
nodeId,
935+
{},
936+
TCreateHandleArgs::RDWR | TCreateHandleArgs::DIRECT);
937+
938+
advanceTime();
939+
checkHandlesCounters(1, 2);
940+
941+
const auto anotherDirectHandle = CreateHandle(
942+
tablet,
943+
nodeId,
944+
{},
945+
TCreateHandleArgs::RDWR | TCreateHandleArgs::DIRECT);
946+
947+
advanceTime();
948+
checkHandlesCounters(2, 3);
949+
950+
tablet.DestroyHandle(handleWithoutDirect);
951+
952+
advanceTime();
953+
checkHandlesCounters(2, 2);
954+
955+
tablet.DestroyHandle(handleWithDirect);
956+
957+
advanceTime();
958+
checkHandlesCounters(1, 1);
959+
960+
tablet.DestroyHandle(anotherDirectHandle);
961+
962+
advanceTime();
963+
checkHandlesCounters(0, 0);
964+
}
885965
}
886966

887967
} // namespace NCloud::NFileStore::NStorage

cloud/filestore/libs/storage/testlib/helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ struct TCreateHandleArgs
254254

255255
static constexpr ui32 TRUNC
256256
= ProtoFlag(NProto::TCreateHandleRequest::E_TRUNCATE);
257+
258+
static constexpr ui32 DIRECT
259+
= ProtoFlag(NProto::TCreateHandleRequest::E_DIRECT);
257260
};
258261

259262
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)