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

[Filestore] issue-2865: discard deleted nodes when recovering existing local filestore session #2866

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 13 additions & 7 deletions cloud/filestore/libs/service_local/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,23 @@ class TLocalIndex

// parent already resolved so we can create node and resolve
// this entry
auto node =
TIndexNode::Create(**parentNodeIt, pathElemRecord->Name);
node->SetRecordIndex(pathElemIndex);
try {
auto node =
TIndexNode::Create(**parentNodeIt, pathElemRecord->Name);
node->SetRecordIndex(pathElemIndex);
Nodes.insert(node);

Nodes.insert(node);
STORAGE_TRACE(
"Resolve node end, NodeId=" << pathElemRecord->NodeId);
} catch (...) {
STORAGE_ERROR(
"Resolve node failed, NodeId=" << pathElemRecord->NodeId <<
", Exception=" << CurrentExceptionMessage());
NodeTable->DeleteRecord(pathElemIndex);
}

unresolvedPath.pop();
unresolvedRecords.erase(pathElemRecord->NodeId);

STORAGE_TRACE(
"Resolve node end, NodeId=" << pathElemRecord->NodeId);
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions cloud/filestore/libs/service_local/index_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,68 @@ Y_UNIT_TEST_SUITE(TLocalIndex)

CheckMissingNodes(pathLen, missingNodes);
}

Y_UNIT_TEST_F(ShouldDiscardDeletedNodes, TEnvironment)
{
RootPath.ForceDelete();
RootPath.MkDir();

StatePath.ForceDelete();
StatePath.MkDir();

auto index = std::make_unique<TLocalIndex>(RootPath, StatePath, 100, Log);
auto rootNode = index->LookupNode(RootNodeId);

// create /dir1
auto dir1 = RootPath / "dir1";
dir1.MkDir();
auto node1 = TIndexNode::Create(*rootNode, dir1.GetName());
auto inserted =
index->TryInsertNode(node1, RootNodeId, dir1.GetName());
UNIT_ASSERT_C(inserted, "Failed to insert node: " << dir1.GetName());

// create /dir2/dir3/dir4
auto dir2 = RootPath / "dir2";
dir2.MkDir();
auto node2 = TIndexNode::Create(*rootNode, dir2.GetName());
inserted =
index->TryInsertNode(node2, RootNodeId, dir2.GetName());
UNIT_ASSERT_C(inserted, "Failed to insert node: " << dir2.GetName());

auto dir3 = dir2 / "dir3";
dir3.MkDir();
auto node3 = TIndexNode::Create(*node2, dir3.GetName());
inserted =
index->TryInsertNode(node3, node2->GetNodeId(), dir3.GetName());
UNIT_ASSERT_C(inserted, "Failed to insert node: " << dir3.GetName());

auto dir4 = dir3 / "dir4";
dir4.MkDir();
auto node4 = TIndexNode::Create(*node3, dir4.GetName());
inserted =
index->TryInsertNode(node4, node3->GetNodeId(), dir4.GetName());
UNIT_ASSERT_C(inserted, "Failed to insert node: " << dir4.GetName());

// delete dir3
dir3.ForceDelete();
index = std::make_unique<TLocalIndex>(RootPath, StatePath, 100, Log);

// /dir1 and /dir2 restored
UNIT_ASSERT_C(index->LookupNode(node1->GetNodeId()),
"Failed to lookup node id: " << node1->GetNodeId() <<
", node: " << dir1.GetName());
UNIT_ASSERT_C(index->LookupNode(node2->GetNodeId()),
"Failed to lookup node id: " << node1->GetNodeId() <<
", node: " << dir2.GetName());

// dir3/dir4 discarded
UNIT_ASSERT_C(!index->LookupNode(node3->GetNodeId()),
"Did not failed to lookup node id: " << node3->GetNodeId() <<
", node: " << dir3.GetName());
UNIT_ASSERT_C(!index->LookupNode(node4->GetNodeId()),
"Did not failed to lookup node id: " << node4->GetNodeId() <<
", node: " << dir4.GetName());
}
};

} // namespace NCloud::NFileStore
Loading