@@ -11,56 +11,45 @@ namespace NCloud::NFileStore::NFuse {
1111
1212// //////////////////////////////////////////////////////////////////////////////
1313
14- TNode* TNodeCache::AddNode (const NProto::TNodeAttr& attrs)
14+ bool TNodeCache::UpdateNode (const NProto::TNodeAttr& attrs, ui64 version )
1515{
16- auto [it, inserted] = Id2Node.emplace (attrs.GetId (), attrs);
17- STORAGE_VERIFY_C (
18- inserted,
19- TWellKnownEntityTypes::FILESYSTEM,
20- FileSystemId,
21- TStringBuilder () << " failed to insert node "
22- << attrs.ShortUtf8DebugString ());
23-
24- STORAGE_VERIFY_C (
25- it->second .IsValid (),
26- TWellKnownEntityTypes::FILESYSTEM,
27- FileSystemId,
28- TStringBuilder () << " invalid attrs: " << attrs.ShortUtf8DebugString ());
29-
30- return &it->second ;
31- }
32-
33- TNode* TNodeCache::TryAddNode (const NProto::TNodeAttr& attrs, ui64 version)
34- {
35- auto * node = FindNode (attrs.GetId ());
36- if (!node) {
37- node = AddNode (attrs);
38- node->LastUpdateVersion = version;
16+ auto g = Guard (Lock);
17+
18+ auto [it, inserted] = Id2Node.emplace (attrs.GetId (), TNode (attrs));
19+ auto & node = it->second ;
20+ bool updated = false ;
21+ if (inserted) {
22+ node.LastUpdateVersion = version;
23+ updated = true ;
3924 } else {
40- if (version >= node-> LastUpdateVersion ) {
41- node-> UpdateAttrs (attrs, version);
42- node-> LastUpdateVersion = version;
25+ if (version >= node. LastUpdateVersion ) {
26+ node. UpdateAttrs (attrs, version);
27+ node. LastUpdateVersion = version;
4328
4429 STORAGE_VERIFY_C (
45- node-> IsValid (),
30+ node. IsValid (),
4631 TWellKnownEntityTypes::FILESYSTEM,
4732 FileSystemId,
4833 TStringBuilder () << " invalid attrs: "
4934 << attrs.ShortUtf8DebugString ()
5035 << " , version: " << version);
36+
37+ updated = true ;
5138 }
5239
53- node-> Ref ();
40+ node. Ref ();
5441 }
5542
56- return node ;
43+ return updated ;
5744}
5845
5946void TNodeCache::InvalidateNode (ui64 ino, ui64 version)
6047{
48+ auto g = Guard (Lock);
49+
6150 NProto::TNodeAttr attrs;
6251 attrs.SetId (ino);
63- auto [it, inserted] = Id2Node.emplace (ino, attrs);
52+ auto [it, inserted] = Id2Node.emplace (ino, TNode ( std::move ( attrs)) );
6453 if (version >= it->second .LastUpdateVersion ) {
6554 if (!inserted) {
6655 it->second .Attrs = std::move (attrs);
@@ -72,6 +61,8 @@ void TNodeCache::InvalidateNode(ui64 ino, ui64 version)
7261
7362void TNodeCache::ForgetNode (ui64 ino, size_t count)
7463{
64+ auto g = Guard (Lock);
65+
7566 auto it = Id2Node.find (ino);
7667 if (it == Id2Node.end ()) {
7768 // we lose our cache after restart, so we should expect forget requests
@@ -88,9 +79,12 @@ void TNodeCache::ForgetNode(ui64 ino, size_t count)
8879 }
8980}
9081
91- TNode* TNodeCache::FindNode (ui64 ino)
82+ ui64 TNodeCache::GetNodeVersion (ui64 ino) const
9283{
93- return Id2Node.FindPtr (ino);
84+ auto g = Guard (Lock);
85+
86+ const auto * node = Id2Node.FindPtr (ino);
87+ return node ? node->LastUpdateVersion : 0 ;
9488}
9589
9690// //////////////////////////////////////////////////////////////////////////////
0 commit comments