Skip to content

Commit

Permalink
issue-1146: resetsession should update in-memory cache as it can modi…
Browse files Browse the repository at this point in the history
…fy node index (#2525)
  • Loading branch information
debnatkh authored Nov 19, 2024
1 parent 8519982 commit 05b435c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ bool TIndexTabletActor::PrepareTx_ResetSession(
args.SessionSeqNo,
args.Request.GetSessionState().size());

TIndexTabletDatabase db(tx.DB);
TIndexTabletDatabaseProxy db(tx.DB, args.NodeUpdates);

bool ready = true;
auto commitId = GetCurrentCommitId();
Expand Down Expand Up @@ -119,7 +119,7 @@ void TIndexTabletActor::ExecuteTx_ResetSession(
TTransactionContext& tx,
TTxIndexTablet::TResetSession& args)
{
TIndexTabletDatabase db(tx.DB);
TIndexTabletDatabaseProxy db(tx.DB, args.NodeUpdates);

auto* session = FindSession(args.SessionId);
if (!session) {
Expand Down
3 changes: 2 additions & 1 deletion cloud/filestore/libs/storage/tablet/tablet_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ struct TTxIndexTablet
// ResetSession
//

struct TResetSession
struct TResetSession : TIndexStateNodeUpdates
{
/* const */ TRequestInfoPtr RequestInfo;
const TString SessionId;
Expand All @@ -500,6 +500,7 @@ struct TTxIndexTablet

void Clear()
{
TIndexStateNodeUpdates::Clear();
Nodes.clear();
}
};
Expand Down
54 changes: 54 additions & 0 deletions cloud/filestore/libs/storage/tablet/tablet_ut_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,60 @@ Y_UNIT_TEST_SUITE(TIndexTabletTest_NodesCache)
UNIT_ASSERT_VALUES_EQUAL(5, statsAfter.RWCount - statsBefore.RWCount);
}

Y_UNIT_TEST(ShouldUpdateCacheUponResetSession)
{
NProto::TStorageConfig storageConfig;
storageConfig.SetInMemoryIndexCacheEnabled(true);
storageConfig.SetInMemoryIndexCacheNodesCapacity(2);
storageConfig.SetInMemoryIndexCacheNodeRefsCapacity(2);
TTestEnv env({}, storageConfig);
env.CreateSubDomain("nfs");

ui32 nodeIdx = env.CreateNode("nfs");
ui64 tabletId = env.BootIndexTablet(nodeIdx);

TIndexTabletClient tablet(env.GetRuntime(), nodeIdx, tabletId);
tablet.InitSession("client", "session");

auto statsBefore = GetTxStats(env, tablet);

auto id = tablet.CreateNode(TCreateNodeArgs::File(RootNodeId, "test"))
->Record.GetNode()
.GetId();
auto handle = tablet.CreateHandle(id, TCreateHandleArgs::RDWR);

// Cache hit
tablet.GetNodeAttr(id, "")->Record.GetNode();

tablet.UnlinkNode(RootNodeId, "test", false);
// Should work as there is an existing handle
tablet.GetNodeAttr(id, "");

// Upon reset session the node should be removed from the cache as well
// as the localDB
tablet.ResetSession("");

tablet.InitSession("client", "session2");

UNIT_ASSERT_VALUES_EQUAL(
E_FS_NOENT,
tablet.AssertGetNodeAttrFailed(id, "")->GetError().GetCode());

auto statsAfter = GetTxStats(env, tablet);
// First two GetNodeAttr calls should have been performed with the cache
UNIT_ASSERT_VALUES_EQUAL(
2,
statsAfter.ROCacheHitCount - statsBefore.ROCacheHitCount);
// Last GetNodeAttr call should have been a cache miss as it is not
// supposed to be present in the cache
UNIT_ASSERT_VALUES_EQUAL(
1,
statsAfter.ROCacheMissCount - statsBefore.ROCacheMissCount);
// CreateNode, CreateHandle, UnlinkNode, DestroySession and InitSession
// are RW txs
UNIT_ASSERT_VALUES_EQUAL(5, statsAfter.RWCount - statsBefore.RWCount);
}

Y_UNIT_TEST(ShouldUpdateCacheUponSetNodeAttr)
{
NProto::TStorageConfig storageConfig;
Expand Down
11 changes: 10 additions & 1 deletion cloud/filestore/libs/storage/tablet/tablet_ut_cache_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TRequestGenerator
CREATE_HANDLE,
DESTROY_HANDLE,
REBOOT_TABLET,
RESET_SESSION,

OPERATION_COUNT
};
Expand Down Expand Up @@ -106,8 +107,11 @@ class TRequestGenerator
case REBOOT_TABLET:
response = DoRebootTablet();
break;
default:
case RESET_SESSION:
response = DoResetSession();
break;
default:
ythrow yexception() << "must be unreachable";
}

if (!response.empty()) {
Expand Down Expand Up @@ -317,6 +321,11 @@ class TRequestGenerator
return "Tablet rebooted";
}

TString DoResetSession()
{
return Tablet->ResetSession("")->Record.DebugString();
}

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

// All timestamps after this timestamp are pruned, so we can safely
Expand Down

0 comments on commit 05b435c

Please sign in to comment.