-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stat about opened files from one/many sessions (#1818)
* Stat about opened files from one/many sessions * Style * style * simpler * Names * Simpler * Simpler * Simpler * clean * fixes * safe * fixes * Some fixes * better * better * better * better * test name * move * clean * Add test
- Loading branch information
Showing
11 changed files
with
498 additions
and
4 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
cloud/filestore/libs/storage/tablet/model/node_session_stat.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "node_session_stat.h" | ||
|
||
namespace NCloud::NFileStore::NStorage { | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::AddRead( | ||
ui64 nodeId, | ||
const TString& sessionId) | ||
{ | ||
++Stat[nodeId].ReadSessions[sessionId]; | ||
return GetKind(nodeId); | ||
} | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::AddWrite( | ||
ui64 nodeId, | ||
const TString& sessionId) | ||
{ | ||
++Stat[nodeId].WriteSessions[sessionId]; | ||
return GetKind(nodeId); | ||
} | ||
|
||
void TNodeToSessionStat::Clean( | ||
const TStat::iterator& nodeStatIterator, | ||
const TString& sessionId) | ||
{ | ||
auto& nodeStat = nodeStatIterator->second; | ||
|
||
{ | ||
const auto it = nodeStat.WriteSessions.find(sessionId); | ||
if (it != nodeStat.WriteSessions.end() && it->second <= 0) { | ||
nodeStat.WriteSessions.erase(it); | ||
} | ||
} | ||
|
||
{ | ||
const auto it = nodeStat.ReadSessions.find(sessionId); | ||
if (it != nodeStat.ReadSessions.end() && it->second <= 0) { | ||
nodeStat.ReadSessions.erase(it); | ||
} | ||
} | ||
|
||
if (nodeStat.WriteSessions.empty() && nodeStat.ReadSessions.empty()) { | ||
Stat.erase(nodeStatIterator); | ||
} | ||
} | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::RemoveRead( | ||
ui64 nodeId, | ||
const TString& sessionId) | ||
{ | ||
const auto& nodeStatIterator = Stat.find(nodeId); | ||
if (nodeStatIterator != Stat.end()) { | ||
--nodeStatIterator->second.ReadSessions[sessionId]; | ||
Clean(nodeStatIterator, sessionId); | ||
} | ||
return GetKind(nodeStatIterator); | ||
} | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::RemoveWrite( | ||
ui64 nodeId, | ||
const TString& sessionId) | ||
{ | ||
const auto& nodeStatIterator = Stat.find(nodeId); | ||
if (nodeStatIterator != Stat.end()) { | ||
--nodeStatIterator->second.WriteSessions[sessionId]; | ||
Clean(nodeStatIterator, sessionId); | ||
} | ||
return GetKind(nodeStatIterator); | ||
} | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::GetKind(ui64 nodeId) const | ||
{ | ||
const auto& nodeStatIterator = Stat.find(nodeId); | ||
return GetKind(nodeStatIterator); | ||
} | ||
|
||
TNodeToSessionStat::EKind TNodeToSessionStat::GetKind( | ||
const TStat::const_iterator& nodeStatIterator) const | ||
{ | ||
if (nodeStatIterator == Stat.end()) { | ||
return EKind::None; | ||
} | ||
const auto& nodeStat = nodeStatIterator->second; | ||
if (nodeStat.WriteSessions.size() > 1) { | ||
return EKind::NodesOpenForWritingByMultipleSessions; | ||
} | ||
if (nodeStat.WriteSessions.size() == 1) { | ||
return EKind::NodesOpenForWritingBySingleSession; | ||
} | ||
if (nodeStat.ReadSessions.size() > 1) { | ||
return EKind::NodesOpenForReadingByMultipleSessions; | ||
} | ||
if (nodeStat.ReadSessions.size() == 1) { | ||
return EKind::NodesOpenForReadingBySingleSession; | ||
} | ||
return EKind::None; | ||
} | ||
|
||
} // namespace NCloud::NFileStore::NStorage |
43 changes: 43 additions & 0 deletions
43
cloud/filestore/libs/storage/tablet/model/node_session_stat.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <util/generic/hash.h> | ||
#include <util/system/types.h> | ||
|
||
namespace NCloud::NFileStore::NStorage { | ||
|
||
class TNodeToSessionStat | ||
{ | ||
struct TSessionStat | ||
{ | ||
THashMap<TString, i32> ReadSessions; | ||
THashMap<TString, i32> WriteSessions; | ||
}; | ||
using TStat = THashMap<ui64, TSessionStat>; | ||
TStat Stat; | ||
|
||
void Clean( | ||
const TStat::iterator& nodeStatIterator, | ||
const TString& sessionId); | ||
|
||
public: | ||
enum class EKind | ||
{ | ||
None, | ||
NodesOpenForWritingBySingleSession, | ||
NodesOpenForWritingByMultipleSessions, | ||
NodesOpenForReadingBySingleSession, | ||
NodesOpenForReadingByMultipleSessions, | ||
}; | ||
|
||
EKind AddRead(ui64 nodeId, const TString& sessionId); | ||
EKind AddWrite(ui64 nodeId, const TString& sessionId); | ||
EKind RemoveRead(ui64 nodeId, const TString& sessionId); | ||
EKind RemoveWrite(ui64 nodeId, const TString& sessionId); | ||
[[nodiscard]] EKind GetKind(ui64 nodeId) const; | ||
|
||
private: | ||
[[nodiscard]] EKind GetKind( | ||
const TStat::const_iterator& nodeStatIterator) const; | ||
}; | ||
|
||
} // namespace NCloud::NFileStore::NStorage |
98 changes: 98 additions & 0 deletions
98
cloud/filestore/libs/storage/tablet/model/node_session_stat_ut.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "node_session_stat.h" | ||
|
||
#include <library/cpp/testing/unittest/registar.h> | ||
|
||
namespace NCloud::NFileStore::NStorage { | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
Y_UNIT_TEST_SUITE(TNodeToSessionStat) | ||
{ | ||
Y_UNIT_TEST(ShouldStat) | ||
{ | ||
TNodeToSessionStat nodeToSessionStat; | ||
const ui64 nodeId1 = 1; | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.GetKind(nodeId1), | ||
TNodeToSessionStat::EKind::None); | ||
|
||
TString sessionId1 = "1"; | ||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddRead(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForReadingBySingleSession); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddRead(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForReadingBySingleSession); | ||
|
||
TString sessionId2 = "2"; | ||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddRead(nodeId1, sessionId2), | ||
TNodeToSessionStat::EKind::NodesOpenForReadingByMultipleSessions); | ||
|
||
TString sessionId3 = "3"; | ||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddWrite(nodeId1, sessionId3), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingBySingleSession); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddWrite(nodeId1, sessionId2), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveRead(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
const ui64 nodeId2 = 2; | ||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.AddWrite(nodeId2, sessionId2), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingBySingleSession); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.GetKind(nodeId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId2, sessionId2), | ||
TNodeToSessionStat::EKind::None); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.GetKind(nodeId1), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId1, sessionId2), | ||
TNodeToSessionStat::EKind::NodesOpenForWritingBySingleSession); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveWrite(nodeId1, sessionId3), | ||
TNodeToSessionStat::EKind::NodesOpenForReadingByMultipleSessions); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveRead(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::NodesOpenForReadingBySingleSession); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveRead(nodeId1, sessionId2), | ||
TNodeToSessionStat::EKind::None); | ||
|
||
UNIT_ASSERT_EQUAL( | ||
nodeToSessionStat.RemoveRead(nodeId1, sessionId1), | ||
TNodeToSessionStat::EKind::None); | ||
} | ||
} | ||
|
||
} // namespace NCloud::NFileStore::NStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.