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] rename TCache to TNodeCache; Split CacheLock into NodeCacheLock and DirectoryHandlesLock; Rename XAttrLock to XAttrCacheLock #2976

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
24 changes: 12 additions & 12 deletions cloud/filestore/libs/vfs_fuse/fs_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ bool TFileSystem::ValidateNodeId(
return true;
}

bool TFileSystem::UpdateNodesCache(
bool TFileSystem::UpdateNodeCache(
const NProto::TNodeAttr& attrs,
fuse_entry_param& entry)
{
if (attrs.GetId() == InvalidNodeId) {
return false;
}

with_lock (CacheLock) {
auto* node = Cache.TryAddNode(attrs);
with_lock (NodeCacheLock) {
auto* node = NodeCache.TryAddNode(attrs);
Y_ABORT_UNLESS(node);

entry.ino = attrs.GetId();
entry.generation = Cache.Generation();
entry.generation = NodeCache.Generation();
entry.attr_timeout = Config->GetAttrTimeout().Seconds();
entry.entry_timeout = Config->GetEntryTimeout().Seconds();

Expand All @@ -141,7 +141,7 @@ void TFileSystem::UpdateXAttrCache(
ui64 version,
const NProto::TError& error)
{
TGuard g{XAttrLock};
TGuard g{XAttrCacheLock};
if (HasError(error)) {
if (STATUS_FROM_CODE(error.GetCode()) == NProto::E_FS_NOXATTR) {
XAttrCache.AddAbsent(ino, name);
Expand All @@ -162,7 +162,7 @@ void TFileSystem::ReplyCreate(
STORAGE_TRACE("inserting node: " << DumpMessage(attrs));

fuse_entry_param entry = {};
if (!UpdateNodesCache(attrs, entry)) {
if (!UpdateNodeCache(attrs, entry)) {
ReplyError(callContext, MakeError(E_FS_IO), req, EIO);
return;
}
Expand All @@ -173,8 +173,8 @@ void TFileSystem::ReplyCreate(
const int res = ReplyCreate(callContext, error, req, &entry, &fi);
if (res == -ENOENT) {
// syscall was interrupted
with_lock (CacheLock) {
Cache.ForgetNode(entry.ino, 1);
with_lock (NodeCacheLock) {
NodeCache.ForgetNode(entry.ino, 1);
}
}
}
Expand All @@ -188,16 +188,16 @@ void TFileSystem::ReplyEntry(
STORAGE_TRACE("inserting node: " << DumpMessage(attrs));

fuse_entry_param entry = {};
if (!UpdateNodesCache(attrs, entry)) {
if (!UpdateNodeCache(attrs, entry)) {
ReplyError(callContext, MakeError(E_FS_IO), req, EIO);
return;
}

const int res = ReplyEntry(callContext, error, req, &entry);
if (res == -ENOENT) {
// syscall was interrupted
with_lock (CacheLock) {
Cache.ForgetNode(entry.ino, 1);
with_lock (NodeCacheLock) {
NodeCache.ForgetNode(entry.ino, 1);
}
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ void TFileSystem::ReplyAttr(
const NProto::TNodeAttr& attrs)
{
fuse_entry_param entry = {};
if (!UpdateNodesCache(attrs, entry)) {
if (!UpdateNodeCache(attrs, entry)) {
ReplyError(callContext, MakeError(E_FS_IO), req, EIO);
return;
}
Expand Down
12 changes: 7 additions & 5 deletions cloud/filestore/libs/vfs_fuse/fs_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include "public.h"

#include "cache.h"
#include "config.h"
#include "fs.h"
#include "handle_ops_queue.h"
#include "node_cache.h"

#include <cloud/filestore/libs/diagnostics/request_stats.h>
#include <cloud/filestore/libs/service/context.h>
Expand Down Expand Up @@ -75,12 +75,14 @@ class TFileSystem final

NVFS::TFSyncQueue FSyncQueue;

TCache Cache;
TMutex CacheLock;
TNodeCache NodeCache;
TMutex NodeCacheLock;

THashMap<ui64, std::shared_ptr<TDirectoryHandle>> DirectoryHandles;
TMutex DirectoryHandlesLock;

TXAttrCache XAttrCache;
TMutex XAttrLock;
TMutex XAttrCacheLock;

THandleOpsQueuePtr HandleOpsQueue;
TMutex HandleOpsQueueLock;
Expand Down Expand Up @@ -384,7 +386,7 @@ class TFileSystem final
fuse_ino_t ino,
uint64_t fh);

bool UpdateNodesCache(
bool UpdateNodeCache(
const NProto::TNodeAttr& attrs,
fuse_entry_param& entry);

Expand Down
4 changes: 2 additions & 2 deletions cloud/filestore/libs/vfs_fuse/fs_impl_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void TFileSystem::GetXAttr(
return;
}

with_lock (XAttrLock) {
with_lock (XAttrCacheLock) {
if (auto xattr = XAttrCache.Get(ino, name)) {
if (xattr->Value) {
ReplyXAttrInt(*callContext, {}, req, *xattr->Value, size);
Expand Down Expand Up @@ -327,7 +327,7 @@ void TFileSystem::RemoveXAttr(
self->FSyncQueue.Dequeue(reqId, error, TNodeId {ino});

if (CheckResponse(self, *callContext, req, response)) {
with_lock (self->XAttrLock) {
with_lock (self->XAttrCacheLock) {
self->XAttrCache.Forget(ino, name);
}

Expand Down
12 changes: 6 additions & 6 deletions cloud/filestore/libs/vfs_fuse/fs_impl_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class TDirectoryBuilder

void TFileSystem::ClearDirectoryCache()
{
with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
STORAGE_DEBUG("clear directory cache of size %lu",
DirectoryHandles.size());
DirectoryHandles.clear();
Expand All @@ -233,7 +233,7 @@ void TFileSystem::OpenDir(

ui64 id = 0;
auto handle = std::make_shared<TDirectoryHandle>(ino);
with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
do {
id = RandomNumber<ui64>();
} while (!DirectoryHandles.try_emplace(id, handle).second);
Expand All @@ -246,7 +246,7 @@ void TFileSystem::OpenDir(
const int res = ReplyOpen(*callContext, {}, req, &info);
if (res != 0) {
// syscall was interrupted
with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
DirectoryHandles.erase(id);
}
}
Expand All @@ -265,7 +265,7 @@ void TFileSystem::ReadDir(
<< " size:" << size);

std::shared_ptr<TDirectoryHandle> handle;
with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
auto it = DirectoryHandles.find(fi->fh);
if (it == DirectoryHandles.end()) {
ReplyError(
Expand Down Expand Up @@ -386,7 +386,7 @@ void TFileSystem::ReleaseDir(
{
STORAGE_DEBUG("ReleaseDir #" << ino);

with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
auto it = DirectoryHandles.find(fi->fh);
if (it != DirectoryHandles.end()) {
CheckDirectoryHandle(req, ino, *it->second, Log, __func__);
Expand All @@ -405,7 +405,7 @@ bool TFileSystem::ValidateDirectoryHandle(
uint64_t fh)
{
std::shared_ptr<TDirectoryHandle> handle;
with_lock (CacheLock) {
with_lock (DirectoryHandlesLock) {
auto it = DirectoryHandles.find(fh);
if (it == DirectoryHandles.end()) {
ReplyError(
Expand Down
8 changes: 4 additions & 4 deletions cloud/filestore/libs/vfs_fuse/fs_impl_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void TFileSystem::Forget(
fuse_ino_t ino,
unsigned long nlookup)
{
with_lock (CacheLock) {
Cache.ForgetNode(ino, nlookup);
with_lock (NodeCacheLock) {
NodeCache.ForgetNode(ino, nlookup);
}

ReplyNone(*callContext, {}, req);
Expand All @@ -69,9 +69,9 @@ void TFileSystem::ForgetMulti(
size_t count,
fuse_forget_data* forgets)
{
with_lock (CacheLock) {
with_lock (NodeCacheLock) {
for (size_t i = 0; i < count; ++i) {
Cache.ForgetNode(forgets[i].ino, forgets[i].nlookup);
NodeCache.ForgetNode(forgets[i].ino, forgets[i].nlookup);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cloud/filestore/libs/vfs_fuse/fs_ut.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cache.h"
#include "fs.h"
#include "log.h"
#include "loop.h"
#include "node_cache.h"

#include <cloud/filestore/libs/client/config.h>
#include <cloud/filestore/libs/client/session.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cache.h"
#include "node_cache.h"

#include <cloud/filestore/libs/service/request.h>

Expand All @@ -8,7 +8,7 @@ namespace NCloud::NFileStore::NFuse {

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

TNode* TCache::AddNode(const NProto::TNodeAttr& attrs)
TNode* TNodeCache::AddNode(const NProto::TNodeAttr& attrs)
{
auto [it, inserted] = Nodes.emplace(attrs);
Y_ABORT_UNLESS(inserted, "failed to insert %s",
Expand All @@ -18,7 +18,7 @@ TNode* TCache::AddNode(const NProto::TNodeAttr& attrs)
return node;
}

TNode* TCache::TryAddNode(const NProto::TNodeAttr& attrs)
TNode* TNodeCache::TryAddNode(const NProto::TNodeAttr& attrs)
{
auto* node = FindNode(attrs.GetId());
if (!node) {
Expand All @@ -31,7 +31,7 @@ TNode* TCache::TryAddNode(const NProto::TNodeAttr& attrs)
return node;
}

void TCache::ForgetNode(ui64 ino, size_t count)
void TNodeCache::ForgetNode(ui64 ino, size_t count)
{
auto it = Nodes.find(ino);
if (it == Nodes.end()) {
Expand All @@ -49,7 +49,7 @@ void TCache::ForgetNode(ui64 ino, size_t count)
}
}

TNode* TCache::FindNode(ui64 ino)
TNode* TNodeCache::FindNode(ui64 ino)
{
auto it = Nodes.find(ino);
return it != Nodes.end() ? (TNode*)&*it : nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ using TNodeMap = THashSet<TNode, TNodeOps::THash, TNodeOps::TEqual>;

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

class TCache
class TNodeCache
{
private:
TNodeMap Nodes;
Expand Down
2 changes: 1 addition & 1 deletion cloud/filestore/libs/vfs_fuse/ya.make.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SRCS(
cache.cpp
config.cpp
file_ring_buffer.cpp
fs.cpp
Expand All @@ -13,6 +12,7 @@ SRCS(
handle_ops_queue.cpp
log.cpp
loop.cpp
node_cache.cpp
)

PEERDIR(
Expand Down
Loading