-
Notifications
You must be signed in to change notification settings - Fork 522
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
curvefs: recovey recyclebin file #259
Conversation
697e706
to
4aea70f
Compare
required string owner = 2; | ||
optional string signature = 3; | ||
required uint64 date = 4; | ||
optional uint64 fileId = 5; |
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.
fileId没看到在命令行里指定,什么时候会用到fileId?
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.
fileId没看到在命令行里指定,什么时候会用到fileId?
原本是如果recyclebin中有多个同名删除的文件,则恢复最近删除的,这里fileId是留了个接口。这次review修改实现了--id选项(可选)来恢复指定文件。
StatusCode retCode; | ||
retCode = GetRecoverFileInfo(request->filename(), &recoverFileInfo); | ||
if (retCode != StatusCode::kOK || | ||
request->filename() != recoverFileInfo.originalfullpathname()) { |
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.
originfullpathname在里面不是已经判断过了吗?怎么又判断一遍?
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.
originfullpathname在里面不是已经判断过了吗?怎么又判断一遍?
done
signature = request->signature(); | ||
} | ||
|
||
retCode = kCurveFS.CheckFileOwner(recoverFileName, |
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.
除了检查recoverfilename的owner,恢复后的filename的权限也需要检查一下
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.
除了检查recoverfilename的owner,恢复后的filename的权限也需要检查一下
done
src/mds/nameserver2/curvefs.cpp
Outdated
recycleFileInfo.set_filestatus(FileStatus::kFileCreated); | ||
} | ||
|
||
auto ret1 = storage_->RecoverFile(recycleFileInfo, recoverFileInfo); |
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.
这里不能直接使用rename吗?
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.
这里不能直接使用rename吗?
done
curvefs_python/curvefs_wrap.cxx
Outdated
@@ -6979,6 +7053,7 @@ static PyMethodDef SwigMethods[] = { | |||
{ (char *)"Extend", _wrap_Extend, METH_VARARGS, NULL}, | |||
{ (char *)"Unlink", _wrap_Unlink, METH_VARARGS, NULL}, | |||
{ (char *)"DeleteForce", _wrap_DeleteForce, METH_VARARGS, NULL}, | |||
{ (char *)"Recover", _wrap_Recover, METH_VARARGS, NULL}, |
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.
保持对齐
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.
保持对齐
done
curvefs_python/curvefs_wrap.cxx
Outdated
@@ -6996,6 +7071,7 @@ static PyMethodDef SwigMethods[] = { | |||
{ (char *)"CBDClient_Create2", _wrap_CBDClient_Create2, METH_VARARGS, NULL}, | |||
{ (char *)"CBDClient_Unlink", _wrap_CBDClient_Unlink, METH_VARARGS, NULL}, | |||
{ (char *)"CBDClient_DeleteForce", _wrap_CBDClient_DeleteForce, METH_VARARGS, NULL}, | |||
{ (char *)"CBDClient_Recover", _wrap_CBDClient_Recover, METH_VARARGS, NULL}, |
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.
保持对齐
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.
保持对齐
done
proto/nameserver2.proto
Outdated
@@ -137,6 +137,10 @@ enum StatusCode { | |||
kSnapshotCloneConnectFail = 136; | |||
// 快照克隆服务未初始化 | |||
kSnapshotCloneServerNotInit = 137; | |||
// recover file status is BeingCloned |
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.
注释不对
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.
注释不对
done
src/client/mds_client.h
Outdated
* recover file | ||
* @param: userinfo | ||
* @param: filename | ||
* @param: id is inodeid,default 0,will not send to mds if not be set |
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.
id没有看到从哪里传进来
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.
id没有看到从哪里传进来
原本是如果recyclebin中有多个同名删除的文件,则恢复最近删除的,这里fileId是留了个接口。这次review修改实现了--id选项(可选)来恢复指定文件。
StatusCode CurveFS::RecoverFile(const std::string & originFileName, | ||
const std::string & recycleFileName, | ||
uint64_t fileId) { | ||
// check the same file exists |
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.
参考rename做一些前置判断。根目录,相同的name
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.
参考rename做一些前置判断。根目录,相同的name
前置判断在NameSpaceService::RecoverFile中做了,主要是检查originFileName的合法性(IsPathValid),如果是根目录也是合法的,但是在recycleBin中找对应文件信息时会失败
@@ -196,6 +196,144 @@ void NameSpaceService::DeleteFile(::google::protobuf::RpcController* controller, | |||
return; | |||
} | |||
|
|||
StatusCode GetRecoverFileInfo(const std::string& originFileName, |
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.
这个逻辑放curvefs感觉更好一点
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.
这个逻辑放curvefs感觉更好一点
done
src/mds/nameserver2/curvefs.cpp
Outdated
@@ -1655,7 +1726,9 @@ StatusCode CurveFS::CheckPathOwnerInternal(const std::string &filename, | |||
return StatusCode::kNotDirectory; | |||
} | |||
|
|||
if (fileInfo.owner() != owner) { | |||
// fileInfo.filename() != RECYCLEBINDIRNAME for recovery file | |||
if (fileInfo.owner() != owner && |
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.
这里不应该用&&
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.
这里不应该用&&
done, 新增CheckRecycleFileOwner
} | ||
recoverFileName = RECYCLEBINDIR + "/" + recoverFileInfo.filename(); | ||
|
||
FileWriteLockGuard guard(fileLockManager_, recoverFileName); |
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.
两个filename都要加锁,参考rename的加锁
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.
两个filename都要加锁,参考rename的加锁
done
@@ -130,6 +130,69 @@ StoreStatus NameServerStorageImp::DeleteFile(InodeID id, | |||
return getErrorCode(resCode); | |||
} | |||
|
|||
StoreStatus NameServerStorageImp::RecoverFile(const FileInfo &recycleFInfo, |
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.
复用rename
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.
复用rename
done
dfb9628
to
e30a701
Compare
src/mds/nameserver2/curvefs.cpp
Outdated
FileInfo* recoverFileInfo) { | ||
std::vector<FileInfo> fileInfoList; | ||
recoverFileInfo->set_ctime(0); | ||
const std::string recoverDir = "/RecycleBin"; |
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.
不要硬编码
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.
不要硬编码
done
src/mds/nameserver2/curvefs.cpp
Outdated
std::string lastEntry; | ||
auto ret = WalkPath(originFileName, &parentFileInfo, &lastEntry); | ||
if ( ret != StatusCode::kOK ) { | ||
LOG(ERROR) << "WalkPath failed, the middle path of " |
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.
慎重使用ERROR级别的打印。只有需要电话告警的错误才需要ERROR打印,检查下这次commit中的所有ERROR打印是否必要。
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.
慎重使用ERROR级别的打印。只有需要电话告警的错误才需要ERROR打印,检查下这次commit中的所有ERROR打印是否必要。
done
} | ||
return; | ||
} | ||
|
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.
destination 需要check isPathValid
RecycleFile和destination 需要共同check,参考IsRenamePathValid。
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.
destination 需要check isPathValid
RecycleFile和destination 需要共同check,参考IsRenamePathValid。
destination应该不用检查吧,因为恢复后的路径是从fileInfo中获得的(创建时已经处理过了),并且应该不会出现互相包含路径的情况,因为destiantion路径不会包含/RecycleBin
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.
如果是/a/RecycleBin,也会有问题
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.
如果是/a/RecycleBin,也会有问题
实际测试了 /a/RecycleBin(或/a/RecycleBin/file1) 也没问题,因为rename那应该主要是检查出现目录包含后获取锁的问题,而recover场景下, /a/RecycleBin/file 和 /RecycleBin/file 并不是目录包含关系
fileId = request->fileid(); | ||
} | ||
|
||
retCode = kCurveFS.GetRecoverFileInfo(request->filename(), |
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.
这里是否需要先加一小段的读锁,再考虑一下
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.
这里是否需要先加一小段的读锁,再考虑一下
done
@@ -1841,6 +1953,52 @@ StatusCode CurveFS::CheckFileOwner(const std::string &filename, | |||
} | |||
} | |||
|
|||
StatusCode CurveFS::CheckRecycleFileOwner(const std::string &filename, |
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.
为什么要增加这个函数,以前的FileOwner函数不能直接用吗
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.
为什么要增加这个函数,以前的FileOwner函数不能直接用吗
因为原来的检查fileowner需要保证目标文件和上层目录的owner都是相同的,但是恢复recyclebin文件时,recyclebin目录的owner是root,里面的文件owner可以是其他的
return; | ||
} | ||
|
||
retCode = kCurveFS.CheckDestinationOwner( |
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.
同上,为什么不能统一使用CheckFileOwner
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.
同上,为什么不能统一使用CheckFileOwner
CheckFileOwner 在检查文件owner时如果文件不存在则返回失败,CheckDestinationOwner和CheckFileOwner的区别是当文件不存在时返回成功(recover、rename等目的文件应该是不存在的,只检查上层路径owner即可)
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.
那这个不需要,你只需要把路径里的上层目录传给CheckFileOwner就可以了吧。
53dd97c
to
0ab9ffd
Compare
0ab9ffd
to
ddffa79
Compare
} | ||
|
||
{ | ||
FileReadLockGuard guard(fileLockManager_, RECYCLEBINDIR); |
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.
不是对这个文件加锁RECYCLEBINDIR
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.
request->filename()
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.
request->filename()
这个request->filename 是删除前的文件名,这个文件是不存在的,这个是根据删除前的文件名去recyclebin找现在在recyclebin中对应的删除后的文件信息
[WIP] Refine wording for notice
What problem does this PR solve?
Issue Number: close #xxx
Problem Summary:
What is changed and how it works?
What's Changed:
How it Works:
Side effects(Breaking backward compatibility? Performance regression?):
Check List