Skip to content

Commit 6b51eee

Browse files
rock-gitchuandew
authored andcommitted
[feat][mdsv2] Fixup known issues..
1 parent efaff89 commit 6b51eee

26 files changed

+229
-151
lines changed

dev-scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ eval set -- "${FLAGS_ARGV}"
1616

1717

1818
for ((i=1; i<=${FLAGS_num}; ++i)); do
19-
padded=$(printf "%05d" $i)
19+
padded=$(printf "%07d" $i)
2020

2121
if [ "${FLAGS_type}" == "file" ]; then
2222
file_path=${FLAGS_path}/file${padded}

src/client/vfs/meta/v2/filesystem.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,7 @@ bool MDSV2FileSystem::MountFs() {
251251
}
252252

253253
bool MDSV2FileSystem::UnmountFs() {
254-
pb::mdsv2::MountPoint mount_point;
255-
mount_point.set_client_id(client_id_.ID());
256-
mount_point.set_hostname(client_id_.Hostname());
257-
mount_point.set_port(client_id_.Port());
258-
mount_point.set_path(client_id_.Mountpoint());
259-
260-
auto status = mds_client_->UmountFs(name_, mount_point);
254+
auto status = mds_client_->UmountFs(name_, client_id_.ID());
261255
if (!status.ok()) {
262256
LOG(ERROR) << fmt::format("[meta.{}] mount fs info fail, mountpoint({}).",
263257
name_, client_id_.Mountpoint());

src/client/vfs/meta/v2/mds_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ Status MDSClient::MountFs(const std::string& name,
159159
}
160160

161161
Status MDSClient::UmountFs(const std::string& name,
162-
const pb::mdsv2::MountPoint& mount_point) {
162+
const std::string& client_id) {
163163
pb::mdsv2::UmountFsRequest request;
164164
pb::mdsv2::UmountFsResponse response;
165165

166166
request.set_fs_name(name);
167-
request.mutable_mount_point()->CopyFrom(mount_point);
167+
request.set_client_id(client_id);
168168

169169
auto status = rpc_->SendRequest("MDSService", "UmountFs", request, response);
170170
if (!status.ok()) {

src/client/vfs/meta/v2/mds_client.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class MDSClient {
6666

6767
Status MountFs(const std::string& name,
6868
const pb::mdsv2::MountPoint& mount_point);
69-
Status UmountFs(const std::string& name,
70-
const pb::mdsv2::MountPoint& mount_point);
69+
Status UmountFs(const std::string& name, const std::string& client_id);
7170

7271
Status Lookup(Ino parent, const std::string& name, Attr& out_attr);
7372

src/mdsv2/background/monitor.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,8 @@ Status Monitor::MonitorClient() {
325325
if (!fs_name.empty()) {
326326
// umount fs from client
327327
Context ctx;
328-
pb::mdsv2::MountPoint mountpoint;
329-
mountpoint.set_client_id(client.id());
330-
mountpoint.set_hostname(client.hostname());
331-
mountpoint.set_port(client.port());
332-
mountpoint.set_path(client.mountpoint());
333328

334-
auto status = fs_set_->UmountFs(ctx, fs_name, mountpoint);
329+
auto status = fs_set_->UmountFs(ctx, fs_name, client.id());
335330
if (!status.ok()) {
336331
DINGO_LOG(ERROR) << fmt::format("[monitor] umount fs({}) from client({}) fail, {}.", fs_name, client.id(),
337332
status.error_str());

src/mdsv2/client/mds.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,7 @@ UmountFsResponse MDSClient::UmountFs(const std::string& fs_name, const std::stri
164164
UmountFsResponse response;
165165

166166
request.set_fs_name(fs_name);
167-
auto* mountpoint = request.mutable_mount_point();
168-
mountpoint->set_client_id(client_id);
169-
mountpoint->set_hostname("127.0.0.1");
170-
mountpoint->set_port(10000);
171-
mountpoint->set_path("/mnt/dingo");
167+
request.set_client_id(client_id);
172168

173169
interaction_->SendRequest("MDSService", "UmountFs", request, response);
174170

src/mdsv2/filesystem/dentry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Dentry::Dentry(const Dentry& dentry, InodeSPtr inode)
4343

4444
Dentry::~Dentry() {} // NOLINT
4545

46-
DentryType Dentry::CopyTo() const {
46+
DentryType Dentry::Copy() const {
4747
DentryType dentry;
4848

4949
dentry.set_fs_id(fs_id_);

src/mdsv2/filesystem/dentry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Dentry {
4949

5050
InodeSPtr Inode() const { return inode_.lock(); }
5151

52-
DentryType CopyTo() const;
52+
DentryType Copy() const;
5353

5454
private:
5555
std::string name_;

src/mdsv2/filesystem/filesystem.cc

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "mdsv2/filesystem/fs_info.h"
4242
#include "mdsv2/filesystem/id_generator.h"
4343
#include "mdsv2/filesystem/inode.h"
44+
#include "mdsv2/filesystem/notify_buddy.h"
4445
#include "mdsv2/filesystem/store_operation.h"
4546
#include "mdsv2/mds/mds_meta.h"
4647
#include "mdsv2/service/service_access.h"
@@ -78,14 +79,13 @@ bool IsReserveName(const std::string& name) { return name == kStatsName || name
7879
bool IsInvalidName(const std::string& name) { return name.empty() || name.size() > FLAGS_filesystem_name_max_size; }
7980

8081
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,
8283
notify::NotifyBuddySPtr notify_buddy)
8384
: self_mds_id_(self_mds_id),
8485
fs_info_(std::move(fs_info)),
8586
fs_id_(fs_info_->GetFsId()),
8687
id_generator_(std::move(id_generator)),
8788
kv_storage_(kv_storage),
88-
renamer_(renamer),
8989
operation_processor_(operation_processor),
9090
mds_meta_map_(mds_meta_map),
9191
parent_memo_(ParentMemo::New(fs_id_)),
@@ -99,6 +99,8 @@ FileSystem::FileSystem(int64_t self_mds_id, FsInfoUPtr fs_info, IdGeneratorUPtr
9999
FileSystem::~FileSystem() {
100100
// destroy
101101
quota_manager_.Destroy();
102+
103+
renamer_.Destroy();
102104
}
103105

104106
FileSystemSPtr FileSystem::GetSelfPtr() { return std::dynamic_pointer_cast<FileSystem>(shared_from_this()); }
@@ -114,6 +116,11 @@ bool FileSystem::Init() {
114116
return false;
115117
}
116118

119+
if (!renamer_.Init()) {
120+
DINGO_LOG(ERROR) << fmt::format("[fs.{}] init renamer fail.", fs_id_);
121+
return false;
122+
}
123+
117124
return true;
118125
}
119126

@@ -269,6 +276,7 @@ Status FileSystem::GetDentryFromStore(Ino parent, const std::string& name, Dentr
269276

270277
Status FileSystem::ListDentryFromStore(Ino parent, const std::string& last_name, uint32_t limit, bool is_only_dir,
271278
std::vector<Dentry>& dentries) {
279+
limit = limit > 0 ? limit : UINT32_MAX;
272280
// scan dentry from store
273281
Range range;
274282
MetaCodec::EncodeDentryRange(fs_id_, parent, range.start_key, range.end_key);
@@ -491,6 +499,8 @@ Status FileSystem::CreateRoot() {
491499
attr.set_mtime(time_ns);
492500
attr.set_atime(time_ns);
493501

502+
attr.add_parents(kRootParentIno);
503+
494504
auto inode = Inode::New(attr);
495505

496506
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
567577
}
568578

569579
uint64_t FileSystem::GetMdsIdByIno(Ino ino) {
580+
ino = ino != kRootParentIno ? ino : kRootIno;
570581
auto partition_policy = fs_info_->GetPartitionPolicy();
571582
const auto& parent_hash = partition_policy.parent_hash();
572583

@@ -1398,14 +1409,33 @@ void FileSystem::UpdateParentMemo(const std::vector<Ino>& ancestors) {
13981409
void FileSystem::NotifyBuddyRefreshInode(AttrType&& attr) {
13991410
if (notify_buddy_ == nullptr) return;
14001411

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+
}
14051418
auto mds_id = GetMdsIdByIno(parent);
14061419
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);
14071435

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+
}
14091439
}
14101440

14111441
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_
15241554
}
15251555

15261556
} 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));
15331564
}
15341565

15351566
return Status::OK();
@@ -1541,7 +1572,7 @@ Status FileSystem::CommitRename(Context& ctx, const RenameParam& param, Ino& old
15411572
return Status(pb::error::ENOT_SERVE, "can not serve");
15421573
}
15431574

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);
15451576
}
15461577

15471578
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_
17201751
return ListDentryFromStore(parent, last_name, limit, is_only_dir, dentries);
17211752
}
17221753

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) {
17241755
DINGO_LOG(DEBUG) << fmt::format("[fs.{}] getinode ino({}).", fs_id_, ino);
17251756

1726-
bool bypass_cache = ctx.IsBypassCache();
1727-
auto& trace = ctx.GetTrace();
1728-
17291757
InodeSPtr inode;
17301758
auto status = GetInode(ctx, ino, inode);
17311759
if (!status.ok()) {
17321760
return status;
17331761
}
17341762

1735-
entry_out.attr = inode->Copy();
1763+
entry_out.attr = inode->Copy(just_basic);
17361764

17371765
return Status::OK();
17381766
}
17391767

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) {
17411770
DINGO_LOG(DEBUG) << fmt::format("[fs.{}] batchgetinode inoes({}).", fs_id_, Helper::VectorToString(inoes));
17421771

17431772
bool bypass_cache = ctx.IsBypassCache();
@@ -1753,7 +1782,7 @@ Status FileSystem::BatchGetInode(Context& ctx, const std::vector<uint64_t>& inoe
17531782
}
17541783

17551784
EntryOut entry_out;
1756-
entry_out.attr = inode->Copy();
1785+
entry_out.attr = inode->Copy(just_basic);
17571786
out_entries.push_back(entry_out);
17581787
}
17591788

@@ -1766,7 +1795,7 @@ Status FileSystem::BatchGetInode(Context& ctx, const std::vector<uint64_t>& inoe
17661795

17671796
for (auto& inode : inodes) {
17681797
EntryOut entry_out;
1769-
entry_out.attr = inode->Copy();
1798+
entry_out.attr = inode->Copy(just_basic);
17701799
out_entries.push_back(entry_out);
17711800
}
17721801
}
@@ -1997,15 +2026,14 @@ Status FileSystem::GetDelSlices(std::vector<TrashSliceList>& delslices) {
19972026

19982027
FileSystemSet::FileSystemSet(CoordinatorClientSPtr coordinator_client, IdGeneratorUPtr fs_id_generator,
19992028
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)
20022031
: coordinator_client_(coordinator_client),
20032032
id_generator_(std::move(fs_id_generator)),
20042033
slice_id_generator_(std::move(slice_id_generator)),
20052034
kv_storage_(kv_storage),
20062035
self_mds_meta_(self_mds_meta),
20072036
mds_meta_map_(mds_meta_map),
2008-
renamer_(renamer),
20092037
operation_processor_(operation_processor),
20102038
notify_buddy_(notify_buddy) {}
20112039

@@ -2015,7 +2043,6 @@ bool FileSystemSet::Init() {
20152043
CHECK(coordinator_client_ != nullptr) << "coordinator client is null.";
20162044
CHECK(kv_storage_ != nullptr) << "kv_storage is null.";
20172045
CHECK(mds_meta_map_ != nullptr) << "mds_meta_map is null.";
2018-
CHECK(renamer_ != nullptr) << "renamer is null.";
20192046
CHECK(operation_processor_ != nullptr) << "operation_processor is null.";
20202047

20212048
if (!IsExistFsTable()) {
@@ -2219,7 +2246,7 @@ Status FileSystemSet::CreateFs(const CreateFsParam& param, FsInfoType& fs_info)
22192246
CHECK(id_generator != nullptr) << "new id generator fail.";
22202247

22212248
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_);
22232250
if (!fs->Init()) {
22242251
cleanup(dentry_table_id, fs_key, "");
22252252
return Status(pb::error::EINTERNAL, "init FileSystem fail");
@@ -2259,17 +2286,17 @@ Status FileSystemSet::MountFs(Context& ctx, const std::string& fs_name, const pb
22592286
return status;
22602287
}
22612288

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) {
22632290
CHECK(!fs_name.empty()) << "fs name is empty.";
22642291

22652292
auto& trace = ctx.GetTrace();
22662293

2267-
UmountFsOperation operation(trace, fs_name, mountpoint);
2294+
UmountFsOperation operation(trace, fs_name, client_id);
22682295

22692296
auto status = RunOperation(&operation);
22702297

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());
22732300

22742301
return status;
22752302
}
@@ -2502,7 +2529,7 @@ bool FileSystemSet::LoadFileSystems() {
25022529
DINGO_LOG(INFO) << fmt::format("[fsset] add fs name({}) id({}).", fs_info.fs_name(), fs_info.fs_id());
25032530

25042531
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_);
25062533
if (!fs->Init()) {
25072534
DINGO_LOG(ERROR) << fmt::format("[fsset] init FileSystem({}) fail.", fs_info.fs_id());
25082535
continue;

0 commit comments

Comments
 (0)