-
Notifications
You must be signed in to change notification settings - Fork 40
issue-5293: fixed caching of stale GetNodeAttr responses in case of concurrent WriteData/SetNodeAttr/AllocateData requests #5308
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
Open
qkrorlqr
wants to merge
16
commits into
main
Choose a base branch
from
users/qkrorlqr/fix-set-get-attr-race
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
874c84a
issue-5293: fixed caching of stale GetNodeAttr responses in case of c…
qkrorlqr eca9da6
issue-5293: invalidating node attrs in cache instead of trying to upd…
qkrorlqr 6d6f048
issue-5293: TNodeCache comment
qkrorlqr 410186f
issue-5293: ListDir vs attr modification race ut
qkrorlqr 25023d1
issue-5293: added AttrVersion to TDirectoryContent
qkrorlqr 21d5e7e
issue-5293: extracted TDirectoryBuilder into a separate .h/.cpp file …
qkrorlqr dbe3c41
issue-5293: a func for resetting attr_timeout in serialized directory…
qkrorlqr 2aafc01
issue-5293: ResetAttrTimeout -> VisitEntries
qkrorlqr 7213cab
issue-5293: back to ResetAttrTimeout - but with an ino filter
qkrorlqr 7fb83d2
issue-5293: ShouldNotAllowGuestAttrCachingUponListNodesAndAttrModific…
qkrorlqr 8d1d314
issue-5293: ShouldNotAllowGuestAttrCachingUponListNodesAndAttrModific…
qkrorlqr 40544b4
issue-5293: refactored TNodeCache iface and moved NodeCacheLock into …
qkrorlqr b430327
issue-5293: refactored TNodeCache iface and moved NodeCacheLock into …
qkrorlqr 30776dd
issue-5293: TNodeCache bench
qkrorlqr 639fc09
issue-5293: TNodeCache sharding
qkrorlqr 59fc686
issue-5293: using 16 TNodeCache shards in fs_impl.cpp
qkrorlqr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,109 @@ | ||
| #include <cloud/filestore/libs/vfs_fuse/node_cache.h> | ||
|
|
||
| #include <library/cpp/testing/benchmark/bench.h> | ||
|
|
||
| #include <util/random/fast.h> | ||
| #include <util/thread/factory.h> | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| using namespace NCloud::NFileStore; | ||
| using namespace NFuse; | ||
|
|
||
| namespace { | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| void RunBench(ui64 iters, ui32 threads, ui32 shards) | ||
| { | ||
| TNodeCache cache("fs", shards); | ||
| std::atomic<ui64> version = 0; | ||
| const ui64 nodeCount = 1'000'000; | ||
|
|
||
| struct TContext | ||
| { | ||
| TManualEvent Ev; | ||
| std::atomic<ui32> Todo; | ||
| }; | ||
|
|
||
| auto context = std::make_shared<TContext>(); | ||
| context->Todo = threads; | ||
|
|
||
| for (ui32 i = 0; i < threads; ++i) { | ||
| SystemThreadFactory()->Run( | ||
| [&cache, &version, iters, threads, context] () | ||
| { | ||
| TReallyFastRng32 rng(777); | ||
| for (size_t i = 0; i < iters / threads; ++i) { | ||
| NProto::TNodeAttr attrs; | ||
| attrs.SetId(rng.Uniform(nodeCount)); | ||
| attrs.SetType(NProto::E_REGULAR_NODE); | ||
| cache.UpdateNode( | ||
| attrs, | ||
| version.fetch_add(1, std::memory_order_release)); | ||
| } | ||
|
|
||
| context->Todo.fetch_sub(1, std::memory_order_release); | ||
| context->Ev.Signal(); | ||
| }); | ||
| } | ||
|
|
||
| while (context->Todo.load(std::memory_order_acquire)) { | ||
| context->Ev.WaitI(); | ||
| context->Ev.Reset(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode1, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 1, 1); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode2, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 2, 1); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode4, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 4, 1); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode8, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 8, 1); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 16, 1); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode1_16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 1, 16); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode2_16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 2, 16); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode4_16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 4, 16); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode8_16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 8, 16); | ||
| } | ||
|
|
||
| Y_CPU_BENCHMARK(UpdateNode16_16, iface) | ||
| { | ||
| RunBench(iface.Iterations(), 16, 16); | ||
| } |
This file contains hidden or 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,16 @@ | ||
| Y_BENCHMARK() | ||
|
|
||
| IF (SANITIZER_TYPE) | ||
| TAG(ya:manual) | ||
| ENDIF() | ||
|
|
||
| SRCS( | ||
| main.cpp | ||
| ) | ||
|
|
||
| PEERDIR( | ||
| cloud/filestore/libs/vfs_fuse | ||
| cloud/filestore/libs/vfs_fuse/vhost | ||
| ) | ||
|
|
||
| END() |
This file contains hidden or 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
112 changes: 112 additions & 0 deletions
112
cloud/filestore/libs/vfs_fuse/fs_directory_content_format.cpp
This file contains hidden or 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,112 @@ | ||
| #include "fs_directory_content_format.h" | ||
|
|
||
| #if defined(FUSE_VIRTIO) | ||
| # include<cloud/contrib/virtiofsd/fuse.h> | ||
| #endif | ||
|
|
||
| #include <util/system/align.h> | ||
|
|
||
| namespace NCloud::NFileStore::NFuse { | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| TDirectoryBuilder::TDirectoryBuilder(size_t size) noexcept | ||
| : Buffer(std::make_shared<TBuffer>(size)) | ||
| {} | ||
|
|
||
| void TDirectoryBuilder::Add( | ||
| fuse_req_t req, | ||
| const TString& name, | ||
| const fuse_entry_param& entry, | ||
| size_t offset) | ||
| { | ||
| #if defined(FUSE_VIRTIO) | ||
| size_t entrySize = fuse_add_direntry_plus( | ||
| req, | ||
| nullptr, | ||
| 0, | ||
| name.c_str(), | ||
| &entry, | ||
| 0); | ||
|
|
||
| Buffer->Advance(entrySize); | ||
|
|
||
| fuse_add_direntry_plus( | ||
| req, | ||
| Buffer->Pos() - entrySize, | ||
| entrySize, | ||
| name.c_str(), | ||
| &entry, | ||
| offset + Buffer->Size()); | ||
| #else | ||
| size_t entrySize = fuse_add_direntry( | ||
| req, | ||
| nullptr, | ||
| 0, | ||
| name.c_str(), | ||
| &entry.attr, | ||
| 0); | ||
|
|
||
| Buffer->Advance(entrySize); | ||
|
|
||
| fuse_add_direntry( | ||
| req, | ||
| Buffer->Pos() - entrySize, | ||
| entrySize, | ||
| name.c_str(), | ||
| &entry.attr, | ||
| offset + Buffer->Size()); | ||
| #endif | ||
| } | ||
|
|
||
| TBufferPtr TDirectoryBuilder::Finish() | ||
| { | ||
| return std::move(Buffer); | ||
| } | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| NProto::TError ResetAttrTimeout( | ||
| char* data, | ||
| ui64 len, | ||
| const TNodeIdVisitor& visitor) | ||
| { | ||
| #if defined(FUSE_VIRTIO) | ||
| while (len > sizeof(fuse_direntplus)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably add commit that expect no name with 0 lens |
||
| auto* de = reinterpret_cast<fuse_direntplus*>(data); | ||
|
|
||
| if (de->dirent.ino != de->entry_out.attr.ino) { | ||
| return MakeError(E_INVALID_STATE, TStringBuilder() << "ino mismatch" | ||
| << " in dirent and attr: " << de->dirent.ino << " != " | ||
| << de->entry_out.attr.ino); | ||
| } | ||
|
|
||
| if (visitor(de->dirent.ino)) { | ||
| de->entry_out.attr_valid = 0; | ||
| de->entry_out.attr_valid_nsec = 0; | ||
| } | ||
|
|
||
| const ui64 fullSize = sizeof(fuse_direntplus) | ||
| + AlignUp<ui64>(de->dirent.namelen, sizeof(ui64)); | ||
|
|
||
| if (len < fullSize) { | ||
| return MakeError(E_INVALID_STATE, TStringBuilder() << "expected >= " | ||
| << fullSize << " bytes of dir content, have " << len | ||
| << " bytes"); | ||
| } | ||
|
|
||
| len -= fullSize; | ||
| data += fullSize; | ||
| } | ||
| #else | ||
| // for non-virtiofs builds we don't return attrs in listing results | ||
|
|
||
| Y_UNUSED(data); | ||
| Y_UNUSED(len); | ||
| Y_UNUSED(visitor); | ||
| #endif | ||
|
|
||
| return MakeError(S_OK); | ||
| } | ||
|
|
||
| } // namespace NCloud::NFileStore::NFuse | ||
34 changes: 34 additions & 0 deletions
34
cloud/filestore/libs/vfs_fuse/fs_directory_content_format.h
This file contains hidden or 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,34 @@ | ||
| #pragma once | ||
|
|
||
| #include "fs_directory_handle.h" | ||
|
|
||
| namespace NCloud::NFileStore::NFuse { | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| class TDirectoryBuilder | ||
| { | ||
| private: | ||
| TBufferPtr Buffer; | ||
|
|
||
| public: | ||
| explicit TDirectoryBuilder(size_t size) noexcept; | ||
|
|
||
| void Add( | ||
| fuse_req_t req, | ||
| const TString& name, | ||
| const fuse_entry_param& entry, | ||
| size_t offset); | ||
|
|
||
| TBufferPtr Finish(); | ||
| }; | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| using TNodeIdVisitor = std::function<bool(ui64)>; | ||
| NProto::TError ResetAttrTimeout( | ||
| char* data, | ||
| ui64 len, | ||
| const TNodeIdVisitor& visitor); | ||
|
|
||
| } // namespace NCloud::NFileStore::NFuse |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remainingLen