41
41
#include " mdsv2/filesystem/fs_info.h"
42
42
#include " mdsv2/filesystem/id_generator.h"
43
43
#include " mdsv2/filesystem/inode.h"
44
+ #include " mdsv2/filesystem/notify_buddy.h"
44
45
#include " mdsv2/filesystem/store_operation.h"
45
46
#include " mdsv2/mds/mds_meta.h"
46
47
#include " mdsv2/service/service_access.h"
@@ -78,14 +79,13 @@ bool IsReserveName(const std::string& name) { return name == kStatsName || name
78
79
bool IsInvalidName (const std::string& name) { return name.empty () || name.size () > FLAGS_filesystem_name_max_size; }
79
80
80
81
FileSystem::FileSystem (int64_t self_mds_id, FsInfoUPtr fs_info, IdGeneratorUPtr id_generator, KVStorageSPtr kv_storage,
81
- RenamerSPtr renamer, OperationProcessorSPtr operation_processor, MDSMetaMapSPtr mds_meta_map,
82
+ OperationProcessorSPtr operation_processor, MDSMetaMapSPtr mds_meta_map,
82
83
notify::NotifyBuddySPtr notify_buddy)
83
84
: self_mds_id_(self_mds_id),
84
85
fs_info_ (std::move(fs_info)),
85
86
fs_id_(fs_info_->GetFsId ()),
86
87
id_generator_(std::move(id_generator)),
87
88
kv_storage_(kv_storage),
88
- renamer_(renamer),
89
89
operation_processor_(operation_processor),
90
90
mds_meta_map_(mds_meta_map),
91
91
parent_memo_(ParentMemo::New(fs_id_)),
@@ -99,6 +99,8 @@ FileSystem::FileSystem(int64_t self_mds_id, FsInfoUPtr fs_info, IdGeneratorUPtr
99
99
FileSystem::~FileSystem () {
100
100
// destroy
101
101
quota_manager_.Destroy ();
102
+
103
+ renamer_.Destroy ();
102
104
}
103
105
104
106
FileSystemSPtr FileSystem::GetSelfPtr () { return std::dynamic_pointer_cast<FileSystem>(shared_from_this ()); }
@@ -114,6 +116,11 @@ bool FileSystem::Init() {
114
116
return false ;
115
117
}
116
118
119
+ if (!renamer_.Init ()) {
120
+ DINGO_LOG (ERROR) << fmt::format (" [fs.{}] init renamer fail." , fs_id_);
121
+ return false ;
122
+ }
123
+
117
124
return true ;
118
125
}
119
126
@@ -269,6 +276,7 @@ Status FileSystem::GetDentryFromStore(Ino parent, const std::string& name, Dentr
269
276
270
277
Status FileSystem::ListDentryFromStore (Ino parent, const std::string& last_name, uint32_t limit, bool is_only_dir,
271
278
std::vector<Dentry>& dentries) {
279
+ limit = limit > 0 ? limit : UINT32_MAX;
272
280
// scan dentry from store
273
281
Range range;
274
282
MetaCodec::EncodeDentryRange (fs_id_, parent, range.start_key , range.end_key );
@@ -491,6 +499,8 @@ Status FileSystem::CreateRoot() {
491
499
attr.set_mtime (time_ns);
492
500
attr.set_atime (time_ns);
493
501
502
+ attr.add_parents (kRootParentIno );
503
+
494
504
auto inode = Inode::New (attr);
495
505
496
506
Dentry dentry (fs_id_, " /" , kRootParentIno , kRootIno , pb::mdsv2::FileType::DIRECTORY, 0 , inode);
@@ -567,6 +577,7 @@ Status FileSystem::Lookup(Context& ctx, Ino parent, const std::string& name, Ent
567
577
}
568
578
569
579
uint64_t FileSystem::GetMdsIdByIno (Ino ino) {
580
+ ino = ino != kRootParentIno ? ino : kRootIno ;
570
581
auto partition_policy = fs_info_->GetPartitionPolicy ();
571
582
const auto & parent_hash = partition_policy.parent_hash ();
572
583
@@ -1398,14 +1409,33 @@ void FileSystem::UpdateParentMemo(const std::vector<Ino>& ancestors) {
1398
1409
void FileSystem::NotifyBuddyRefreshInode (AttrType&& attr) {
1399
1410
if (notify_buddy_ == nullptr ) return ;
1400
1411
1401
- CHECK (attr.parents_size () == 1 ) << fmt::format (" parent size should be 1, but is {} ino({})." , attr.parents_size (),
1402
- attr.ino ());
1403
-
1404
- Ino parent = attr.parents ().at (0 );
1412
+ Ino parent = kRootParentIno ;
1413
+ if (attr.ino () != kRootIno ) {
1414
+ CHECK (attr.parents_size () == 1 ) << fmt::format (" parent size should be 1, but is {} ino({})." , attr.parents_size (),
1415
+ attr.ino ());
1416
+ parent = attr.parents ().at (0 );
1417
+ }
1405
1418
auto mds_id = GetMdsIdByIno (parent);
1406
1419
CHECK (mds_id != 0 ) << fmt::format (" mds id should not be 0, ino({})." , parent);
1420
+ if (mds_id == self_mds_id_) {
1421
+ RefreshInode (attr);
1422
+
1423
+ } else {
1424
+ notify_buddy_->AsyncNotify (notify::RefreshInodeMessage::Create (mds_id, fs_id_, std::move (attr)));
1425
+ }
1426
+ }
1427
+
1428
+ void FileSystem::NotifyBuddyCleanPartitionCache (Ino ino) {
1429
+ if (notify_buddy_ == nullptr ) return ;
1430
+
1431
+ auto mds_id = GetMdsIdByIno (ino);
1432
+ CHECK (mds_id != 0 ) << fmt::format (" mds id should not be 0, ino({})." , ino);
1433
+ if (mds_id == self_mds_id_) {
1434
+ partition_cache_.Delete (ino);
1407
1435
1408
- notify_buddy_->AsyncNotify (notify::RefreshInodeMessage::Create (mds_id, fs_id_, std::move (attr)));
1436
+ } else {
1437
+ notify_buddy_->AsyncNotify (notify::CleanPartitionCacheMessage::Create (mds_id, fs_id_, ino));
1438
+ }
1409
1439
}
1410
1440
1411
1441
Status FileSystem::Rename (Context& ctx, const RenameParam& param, uint64_t & old_parent_version,
@@ -1524,12 +1554,13 @@ Status FileSystem::Rename(Context& ctx, const RenameParam& param, uint64_t& old_
1524
1554
}
1525
1555
1526
1556
} else {
1527
- if (is_same_parent) {
1528
- NotifyBuddyRefreshInode (std::move (old_parent_attr));
1529
- } else {
1530
- NotifyBuddyRefreshInode (std::move (old_parent_attr));
1531
- NotifyBuddyRefreshInode (std::move (new_parent_attr));
1532
- }
1557
+ // clean partition cache
1558
+ NotifyBuddyCleanPartitionCache (old_parent);
1559
+ if (!is_same_parent) NotifyBuddyCleanPartitionCache (new_parent);
1560
+
1561
+ // refresh parent of parent inode cache
1562
+ NotifyBuddyRefreshInode (std::move (old_parent_attr));
1563
+ if (!is_same_parent) NotifyBuddyRefreshInode (std::move (new_parent_attr));
1533
1564
}
1534
1565
1535
1566
return Status::OK ();
@@ -1541,7 +1572,7 @@ Status FileSystem::CommitRename(Context& ctx, const RenameParam& param, Ino& old
1541
1572
return Status (pb::error::ENOT_SERVE, " can not serve" );
1542
1573
}
1543
1574
1544
- return renamer_-> Execute <RenameParam>(GetSelfPtr (), ctx, param, old_parent_version, new_parent_version);
1575
+ return renamer_. Execute <RenameParam>(GetSelfPtr (), ctx, param, old_parent_version, new_parent_version);
1545
1576
}
1546
1577
1547
1578
static uint64_t CalculateDeltaLength (uint64_t length, const std::vector<pb::mdsv2::Slice>& slices) {
@@ -1720,24 +1751,22 @@ Status FileSystem::ListDentry(Context& ctx, Ino parent, const std::string& last_
1720
1751
return ListDentryFromStore (parent, last_name, limit, is_only_dir, dentries);
1721
1752
}
1722
1753
1723
- Status FileSystem::GetInode (Context& ctx, Ino ino, EntryOut& entry_out) {
1754
+ Status FileSystem::GetInode (Context& ctx, Ino ino, bool just_basic, EntryOut& entry_out) {
1724
1755
DINGO_LOG (DEBUG) << fmt::format (" [fs.{}] getinode ino({})." , fs_id_, ino);
1725
1756
1726
- bool bypass_cache = ctx.IsBypassCache ();
1727
- auto & trace = ctx.GetTrace ();
1728
-
1729
1757
InodeSPtr inode;
1730
1758
auto status = GetInode (ctx, ino, inode);
1731
1759
if (!status.ok ()) {
1732
1760
return status;
1733
1761
}
1734
1762
1735
- entry_out.attr = inode->Copy ();
1763
+ entry_out.attr = inode->Copy (just_basic );
1736
1764
1737
1765
return Status::OK ();
1738
1766
}
1739
1767
1740
- Status FileSystem::BatchGetInode (Context& ctx, const std::vector<uint64_t >& inoes, std::vector<EntryOut>& out_entries) {
1768
+ Status FileSystem::BatchGetInode (Context& ctx, const std::vector<uint64_t >& inoes, bool just_basic,
1769
+ std::vector<EntryOut>& out_entries) {
1741
1770
DINGO_LOG (DEBUG) << fmt::format (" [fs.{}] batchgetinode inoes({})." , fs_id_, Helper::VectorToString (inoes));
1742
1771
1743
1772
bool bypass_cache = ctx.IsBypassCache ();
@@ -1753,7 +1782,7 @@ Status FileSystem::BatchGetInode(Context& ctx, const std::vector<uint64_t>& inoe
1753
1782
}
1754
1783
1755
1784
EntryOut entry_out;
1756
- entry_out.attr = inode->Copy ();
1785
+ entry_out.attr = inode->Copy (just_basic );
1757
1786
out_entries.push_back (entry_out);
1758
1787
}
1759
1788
@@ -1766,7 +1795,7 @@ Status FileSystem::BatchGetInode(Context& ctx, const std::vector<uint64_t>& inoe
1766
1795
1767
1796
for (auto & inode : inodes) {
1768
1797
EntryOut entry_out;
1769
- entry_out.attr = inode->Copy ();
1798
+ entry_out.attr = inode->Copy (just_basic );
1770
1799
out_entries.push_back (entry_out);
1771
1800
}
1772
1801
}
@@ -1997,15 +2026,14 @@ Status FileSystem::GetDelSlices(std::vector<TrashSliceList>& delslices) {
1997
2026
1998
2027
FileSystemSet::FileSystemSet (CoordinatorClientSPtr coordinator_client, IdGeneratorUPtr fs_id_generator,
1999
2028
IdGeneratorUPtr slice_id_generator, KVStorageSPtr kv_storage, MDSMeta self_mds_meta,
2000
- MDSMetaMapSPtr mds_meta_map, RenamerSPtr renamer ,
2001
- OperationProcessorSPtr operation_processor, notify::NotifyBuddySPtr notify_buddy)
2029
+ MDSMetaMapSPtr mds_meta_map, OperationProcessorSPtr operation_processor ,
2030
+ notify::NotifyBuddySPtr notify_buddy)
2002
2031
: coordinator_client_(coordinator_client),
2003
2032
id_generator_(std::move(fs_id_generator)),
2004
2033
slice_id_generator_(std::move(slice_id_generator)),
2005
2034
kv_storage_(kv_storage),
2006
2035
self_mds_meta_(self_mds_meta),
2007
2036
mds_meta_map_(mds_meta_map),
2008
- renamer_(renamer),
2009
2037
operation_processor_(operation_processor),
2010
2038
notify_buddy_(notify_buddy) {}
2011
2039
@@ -2015,7 +2043,6 @@ bool FileSystemSet::Init() {
2015
2043
CHECK (coordinator_client_ != nullptr ) << " coordinator client is null." ;
2016
2044
CHECK (kv_storage_ != nullptr ) << " kv_storage is null." ;
2017
2045
CHECK (mds_meta_map_ != nullptr ) << " mds_meta_map is null." ;
2018
- CHECK (renamer_ != nullptr ) << " renamer is null." ;
2019
2046
CHECK (operation_processor_ != nullptr ) << " operation_processor is null." ;
2020
2047
2021
2048
if (!IsExistFsTable ()) {
@@ -2219,7 +2246,7 @@ Status FileSystemSet::CreateFs(const CreateFsParam& param, FsInfoType& fs_info)
2219
2246
CHECK (id_generator != nullptr ) << " new id generator fail." ;
2220
2247
2221
2248
auto fs = FileSystem::New (self_mds_meta_.ID (), FsInfo::NewUnique (fs_info), std::move (id_generator), kv_storage_,
2222
- renamer_, operation_processor_, mds_meta_map_, notify_buddy_);
2249
+ operation_processor_, mds_meta_map_, notify_buddy_);
2223
2250
if (!fs->Init ()) {
2224
2251
cleanup (dentry_table_id, fs_key, " " );
2225
2252
return Status (pb::error::EINTERNAL, " init FileSystem fail" );
@@ -2259,17 +2286,17 @@ Status FileSystemSet::MountFs(Context& ctx, const std::string& fs_name, const pb
2259
2286
return status;
2260
2287
}
2261
2288
2262
- Status FileSystemSet::UmountFs (Context& ctx, const std::string& fs_name, const pb::mdsv2::MountPoint& mountpoint ) {
2289
+ Status FileSystemSet::UmountFs (Context& ctx, const std::string& fs_name, const std::string& client_id ) {
2263
2290
CHECK (!fs_name.empty ()) << " fs name is empty." ;
2264
2291
2265
2292
auto & trace = ctx.GetTrace ();
2266
2293
2267
- UmountFsOperation operation (trace, fs_name, mountpoint );
2294
+ UmountFsOperation operation (trace, fs_name, client_id );
2268
2295
2269
2296
auto status = RunOperation (&operation);
2270
2297
2271
- DINGO_LOG (INFO) << fmt::format (" [fsset] umount fs({}) to {} finish, status({})." , fs_name,
2272
- mountpoint. ShortDebugString (), status.error_str ());
2298
+ DINGO_LOG (INFO) << fmt::format (" [fsset] umount fs({}) to {} finish, status({})." , fs_name, client_id,
2299
+ status.error_str ());
2273
2300
2274
2301
return status;
2275
2302
}
@@ -2502,7 +2529,7 @@ bool FileSystemSet::LoadFileSystems() {
2502
2529
DINGO_LOG (INFO) << fmt::format (" [fsset] add fs name({}) id({})." , fs_info.fs_name (), fs_info.fs_id ());
2503
2530
2504
2531
fs = FileSystem::New (self_mds_meta_.ID (), FsInfo::NewUnique (fs_info), std::move (id_generator), kv_storage_,
2505
- renamer_, operation_processor_, mds_meta_map_, notify_buddy_);
2532
+ operation_processor_, mds_meta_map_, notify_buddy_);
2506
2533
if (!fs->Init ()) {
2507
2534
DINGO_LOG (ERROR) << fmt::format (" [fsset] init FileSystem({}) fail." , fs_info.fs_id ());
2508
2535
continue ;
0 commit comments