From c93416fb660a713976842223058849c520dcf75a Mon Sep 17 00:00:00 2001 From: Mikhail Montsev Date: Tue, 4 Feb 2025 20:50:39 +0100 Subject: [PATCH] Rename TCache to TNodeCache; Split CacheLock into NodeCacheLock and DirectoryHandlesLock; Rename XAttrLock to XAttrCacheLock --- cloud/filestore/libs/vfs_fuse/fs_impl.cpp | 24 +++++++++---------- cloud/filestore/libs/vfs_fuse/fs_impl.h | 12 ++++++---- .../filestore/libs/vfs_fuse/fs_impl_attr.cpp | 4 ++-- .../filestore/libs/vfs_fuse/fs_impl_list.cpp | 12 +++++----- .../filestore/libs/vfs_fuse/fs_impl_node.cpp | 8 +++---- cloud/filestore/libs/vfs_fuse/fs_ut.cpp | 2 +- .../vfs_fuse/{cache.cpp => node_cache.cpp} | 10 ++++---- .../libs/vfs_fuse/{cache.h => node_cache.h} | 2 +- cloud/filestore/libs/vfs_fuse/ya.make.inc | 2 +- 9 files changed, 39 insertions(+), 37 deletions(-) rename cloud/filestore/libs/vfs_fuse/{cache.cpp => node_cache.cpp} (90%) rename cloud/filestore/libs/vfs_fuse/{cache.h => node_cache.h} (99%) diff --git a/cloud/filestore/libs/vfs_fuse/fs_impl.cpp b/cloud/filestore/libs/vfs_fuse/fs_impl.cpp index 92376d31248..484c6f97831 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_impl.cpp +++ b/cloud/filestore/libs/vfs_fuse/fs_impl.cpp @@ -111,7 +111,7 @@ bool TFileSystem::ValidateNodeId( return true; } -bool TFileSystem::UpdateNodesCache( +bool TFileSystem::UpdateNodeCache( const NProto::TNodeAttr& attrs, fuse_entry_param& entry) { @@ -119,12 +119,12 @@ bool TFileSystem::UpdateNodesCache( 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(); @@ -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); @@ -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; } @@ -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); } } } @@ -188,7 +188,7 @@ 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; } @@ -196,8 +196,8 @@ void TFileSystem::ReplyEntry( 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); } } } @@ -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; } diff --git a/cloud/filestore/libs/vfs_fuse/fs_impl.h b/cloud/filestore/libs/vfs_fuse/fs_impl.h index fa2df37baef..e4df488104a 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_impl.h +++ b/cloud/filestore/libs/vfs_fuse/fs_impl.h @@ -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 #include @@ -75,12 +75,14 @@ class TFileSystem final NVFS::TFSyncQueue FSyncQueue; - TCache Cache; - TMutex CacheLock; + TNodeCache NodeCache; + TMutex NodeCacheLock; + THashMap> DirectoryHandles; + TMutex DirectoryHandlesLock; TXAttrCache XAttrCache; - TMutex XAttrLock; + TMutex XAttrCacheLock; THandleOpsQueuePtr HandleOpsQueue; TMutex HandleOpsQueueLock; @@ -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); diff --git a/cloud/filestore/libs/vfs_fuse/fs_impl_attr.cpp b/cloud/filestore/libs/vfs_fuse/fs_impl_attr.cpp index 8e2272749e2..e03b1cab3d8 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_impl_attr.cpp +++ b/cloud/filestore/libs/vfs_fuse/fs_impl_attr.cpp @@ -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); @@ -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); } diff --git a/cloud/filestore/libs/vfs_fuse/fs_impl_list.cpp b/cloud/filestore/libs/vfs_fuse/fs_impl_list.cpp index 7e49f0a6ef3..da15f100761 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_impl_list.cpp +++ b/cloud/filestore/libs/vfs_fuse/fs_impl_list.cpp @@ -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(); @@ -233,7 +233,7 @@ void TFileSystem::OpenDir( ui64 id = 0; auto handle = std::make_shared(ino); - with_lock (CacheLock) { + with_lock (DirectoryHandlesLock) { do { id = RandomNumber(); } while (!DirectoryHandles.try_emplace(id, handle).second); @@ -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); } } @@ -265,7 +265,7 @@ void TFileSystem::ReadDir( << " size:" << size); std::shared_ptr handle; - with_lock (CacheLock) { + with_lock (DirectoryHandlesLock) { auto it = DirectoryHandles.find(fi->fh); if (it == DirectoryHandles.end()) { ReplyError( @@ -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__); @@ -405,7 +405,7 @@ bool TFileSystem::ValidateDirectoryHandle( uint64_t fh) { std::shared_ptr handle; - with_lock (CacheLock) { + with_lock (DirectoryHandlesLock) { auto it = DirectoryHandles.find(fh); if (it == DirectoryHandles.end()) { ReplyError( diff --git a/cloud/filestore/libs/vfs_fuse/fs_impl_node.cpp b/cloud/filestore/libs/vfs_fuse/fs_impl_node.cpp index 253575caaea..e3b326fb032 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_impl_node.cpp +++ b/cloud/filestore/libs/vfs_fuse/fs_impl_node.cpp @@ -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); @@ -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); } } diff --git a/cloud/filestore/libs/vfs_fuse/fs_ut.cpp b/cloud/filestore/libs/vfs_fuse/fs_ut.cpp index bcf1534365d..43e19720776 100644 --- a/cloud/filestore/libs/vfs_fuse/fs_ut.cpp +++ b/cloud/filestore/libs/vfs_fuse/fs_ut.cpp @@ -1,7 +1,7 @@ -#include "cache.h" #include "fs.h" #include "log.h" #include "loop.h" +#include "node_cache.h" #include #include diff --git a/cloud/filestore/libs/vfs_fuse/cache.cpp b/cloud/filestore/libs/vfs_fuse/node_cache.cpp similarity index 90% rename from cloud/filestore/libs/vfs_fuse/cache.cpp rename to cloud/filestore/libs/vfs_fuse/node_cache.cpp index d9253c17a5f..dafe6003e27 100644 --- a/cloud/filestore/libs/vfs_fuse/cache.cpp +++ b/cloud/filestore/libs/vfs_fuse/node_cache.cpp @@ -1,4 +1,4 @@ -#include "cache.h" +#include "node_cache.h" #include @@ -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", @@ -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) { @@ -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()) { @@ -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; diff --git a/cloud/filestore/libs/vfs_fuse/cache.h b/cloud/filestore/libs/vfs_fuse/node_cache.h similarity index 99% rename from cloud/filestore/libs/vfs_fuse/cache.h rename to cloud/filestore/libs/vfs_fuse/node_cache.h index 4b391a303e3..83ef4072428 100644 --- a/cloud/filestore/libs/vfs_fuse/cache.h +++ b/cloud/filestore/libs/vfs_fuse/node_cache.h @@ -87,7 +87,7 @@ using TNodeMap = THashSet; //////////////////////////////////////////////////////////////////////////////// -class TCache +class TNodeCache { private: TNodeMap Nodes; diff --git a/cloud/filestore/libs/vfs_fuse/ya.make.inc b/cloud/filestore/libs/vfs_fuse/ya.make.inc index e01bfd59275..d9f748c6f03 100644 --- a/cloud/filestore/libs/vfs_fuse/ya.make.inc +++ b/cloud/filestore/libs/vfs_fuse/ya.make.inc @@ -1,5 +1,4 @@ SRCS( - cache.cpp config.cpp file_ring_buffer.cpp fs.cpp @@ -13,6 +12,7 @@ SRCS( handle_ops_queue.cpp log.cpp loop.cpp + node_cache.cpp ) PEERDIR(