Skip to content

Commit

Permalink
curvefs: recovey recyclebin file
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanHai authored and ilixiaocui committed Feb 23, 2021
1 parent 17b7a2e commit b5e46ba
Show file tree
Hide file tree
Showing 22 changed files with 1,356 additions and 6 deletions.
4 changes: 4 additions & 0 deletions curvefs_python/cbd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ int CBDClient::DeleteForce(const char* filename, UserInfo_t* userInfo) {
return client_->Unlink(filename, ToCurveClientUserInfo(userInfo), true);
}

int CBDClient::Recover(const char* filename, UserInfo_t* userInfo, uint64_t fileId) { // NOLINT
return client_->Recover(filename, ToCurveClientUserInfo(userInfo), fileId);
}

int CBDClient::Rename(UserInfo_t* userInfo, const char* oldPath,
const char* newPath) {
return client_->Rename(ToCurveClientUserInfo(userInfo), oldPath, newPath);
Expand Down
1 change: 1 addition & 0 deletions curvefs_python/cbd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class CBDClient {
uint64_t stripeUnit, uint64_t stripeCount);
int Unlink(const char* filename, UserInfo_t* info);
int DeleteForce(const char* filename, UserInfo_t* info);
int Recover(const char* filename, UserInfo_t* info, uint64_t fileId);
int Rename(UserInfo_t* info, const char* oldpath, const char* newpath);
int Extend(const char* filename, UserInfo_t* info, uint64_t size);

Expand Down
7 changes: 7 additions & 0 deletions curvefs_python/curvefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ def DeleteForce(filename, info):
return _curvefs.DeleteForce(filename, info)
DeleteForce = _curvefs.DeleteForce

def Recover(filename, info, fileId):
return _curvefs.Recover(filename, info, fileId)
Recover = _curvefs.Recover

def Listdir(dirpath, info):
return _curvefs.Listdir(dirpath, info)
Listdir = _curvefs.Listdir
Expand Down Expand Up @@ -437,6 +441,9 @@ def Unlink(self, filename, info):
def DeleteForce(self, filename, info):
return _curvefs.CBDClient_DeleteForce(self, filename, info)

def Recover(self, filename, info, fileId):
return _curvefs.CBDClient_Recover(self, filename, info, fileId)

def Rename(self, info, oldpath, newpath):
return _curvefs.CBDClient_Rename(self, info, oldpath, newpath)

Expand Down
7 changes: 7 additions & 0 deletions curvefs_python/curvefs_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
fileType = ["INODE_DIRECTORY", "INODE_PAGEFILE", "INODE_APPENDFILE", "INODE_APPENDECFILE", "INODE_SNAPSHOT_PAGEFILE"]
fileStatus = ["Created", "Deleting", "Cloning", "CloneMetaInstalled", "Cloned", "BeingCloned"]
kGB = 1024 * 1024 * 1024
kUnitializedFileID = 0

# 参照curve/include/client/libcurve.h
retCode = { 0 : "OK",
Expand Down Expand Up @@ -80,13 +81,19 @@ def getRetCodeMsg(ret):
if args.password:
user.password = args.password

fileId = kUnitializedFileID

if args.optype == "create":
if args.stripeUnit and args.stripeCount:
ret = cbd.Create2(args.filename, user, args.length * kGB, args.stripeUnit, args.stripeCount)
else:
ret = cbd.Create(args.filename, user, args.length * kGB)
elif args.optype == "delete":
ret = cbd.Unlink(args.filename, user)
elif args.optype == "recover":
if args.id:
fileId = args.id
ret = cbd.Recover(args.filename, user, fileId)
elif args.optype == "extend":
ret = cbd.Extend(args.filename, user, args.length * kGB)
elif args.optype == "stat":
Expand Down
95 changes: 95 additions & 0 deletions curvefs_python/curvefs_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5590,6 +5590,49 @@ SWIGINTERN PyObject *_wrap_Unlink(PyObject *SWIGUNUSEDPARM(self), PyObject *args
}


SWIGINTERN PyObject *_wrap_Recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
char *arg1 = (char *) 0 ;
UserInfo_t *arg2 = (UserInfo_t *) 0 ;
uint64_t arg3 ;
int res1 ;
char *buf1 = 0 ;
int alloc1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
unsigned long long val3 ;
int ecode3 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"OOO:Recover",&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1);
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "Recover" "', argument " "1"" of type '" "char const *""'");
}
arg1 = reinterpret_cast< char * >(buf1);
res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_UserInfo, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "Recover" "', argument " "2"" of type '" "UserInfo_t *""'");
}
arg2 = reinterpret_cast< UserInfo_t * >(argp2);
ecode3 = SWIG_AsVal_unsigned_SS_long_SS_long(obj2, &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "Recover" "', argument " "3"" of type '" "uint64_t""'");
}
arg3 = static_cast< uint64_t >(val3);
result = (int)Recover((char const *)arg1,arg2,arg3);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
return resultobj;
fail:
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
return NULL;
}


SWIGINTERN PyObject *_wrap_DeleteForce(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
char *arg1 = (char *) 0 ;
Expand Down Expand Up @@ -6232,6 +6275,56 @@ SWIGINTERN PyObject *_wrap_CBDClient_DeleteForce(PyObject *SWIGUNUSEDPARM(self),
return NULL;
}

SWIGINTERN PyObject *_wrap_CBDClient_Recover(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CBDClient *arg1 = (CBDClient *) 0 ;
char *arg2 = (char *) 0 ;
UserInfo_t *arg3 = (UserInfo_t *) 0 ;
uint64_t arg4 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
void *argp3 = 0 ;
int res3 = 0 ;
unsigned long long val4 ;
int ecode4 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"OOOO:CBDClient_Recover",&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CBDClient, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CBDClient_Recover" "', argument " "1"" of type '" "CBDClient *""'");
}
arg1 = reinterpret_cast< CBDClient * >(argp1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CBDClient_Recover" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_UserInfo, 0 | 0 );
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CBDClient_Recover" "', argument " "3"" of type '" "UserInfo_t *""'");
}
arg3 = reinterpret_cast< UserInfo_t * >(argp3);
ecode4 = SWIG_AsVal_unsigned_SS_long_SS_long(obj3, &val4);
if (!SWIG_IsOK(ecode4)) {
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "CBDClient_Recover" "', argument " "4"" of type '" "uint64_t""'");
}
arg4 = static_cast< uint64_t >(val4);
result = (int)(arg1)->Recover((char const *)arg2,arg3,arg4);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return NULL;
}

SWIGINTERN PyObject *_wrap_CBDClient_Rename(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
Expand Down Expand Up @@ -6979,6 +7072,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},
{ (char *)"OpenDir", _wrap_OpenDir, METH_VARARGS, NULL},
{ (char *)"CloseDir", _wrap_CloseDir, METH_VARARGS, NULL},
{ (char *)"Listdir", _wrap_Listdir, METH_VARARGS, NULL},
Expand All @@ -6996,6 +7090,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},
{ (char *)"CBDClient_Rename", _wrap_CBDClient_Rename, METH_VARARGS, NULL},
{ (char *)"CBDClient_Extend", _wrap_CBDClient_Extend, METH_VARARGS, NULL},
{ (char *)"CBDClient_Read", _wrap_CBDClient_Read, METH_VARARGS, NULL},
Expand Down
1 change: 1 addition & 0 deletions curvefs_python/libcurvefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int Close(int fd);
int Rename(UserInfo_t* info, const char* oldpath, const char* newpath);
int Extend(const char* filename, UserInfo_t* info, uint64_t size);
int Unlink(const char* filename, UserInfo_t* info);
int Recover(const char* filename, UserInfo_t* info, uint64_t fileId);
int DeleteForce(const char* filename, UserInfo_t* info);
DirInfos_t* OpenDir(const char* dirpath, UserInfo_t* userinfo);
void CloseDir(DirInfos_t* dirinfo);
Expand Down
7 changes: 7 additions & 0 deletions curvefs_python/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def get_parser():
subparser.add_argument("--filename", help='name of file', type=str, required=True)
subparser.add_argument("--password", help='password of user', type=str)

# recover option
subparser = subparsers.add_parser("recover", help="recover file")
subparser.add_argument("--user", help='user of file', type=str, required=True)
subparser.add_argument("--filename", help='name of file', type=str, required=True)
subparser.add_argument("--id", help='inodeid of file', type=int)
subparser.add_argument("--password", help='password of user', type=str)

# extend option
subparser = subparsers.add_parser("extend", help="extend file")
subparser.add_argument("--user", help='user of file', type=str, required=True)
Expand Down
11 changes: 11 additions & 0 deletions include/client/libcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ int Unlink(const char* filename, const C_UserInfo_t* userinfo);
*/
int DeleteForce(const char* filename, const C_UserInfo_t* userinfo);

/**
* recover file
* @param: userinfo
* @param: filename
* @param: fileid
* @return: success 0, otherwise return
* -LIBCURVE_ERROR::FAILED,-LIBCURVE_ERROR::AUTHFAILED and so on
*/
int Recover(const char* filename, const C_UserInfo_t* userinfo,
uint64_t fileId);

/**
* 在获取目录内容之前先打开文件夹
* @param: userinfo是用户信息
Expand Down
17 changes: 17 additions & 0 deletions proto/nameserver2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ enum StatusCode {
kSnapshotCloneConnectFail = 136;
// 快照克隆服务未初始化
kSnapshotCloneServerNotInit = 137;
// recover file status is CloneMetaInstalled
kRecoverFileCloneMetaInstalled = 138;
// recover file fail
kRecoverFileError = 139;

// 元数据存储错误
kStorageError = 501;
Expand Down Expand Up @@ -187,6 +191,18 @@ message DeleteFileResponse {
required StatusCode statusCode = 1;
}

message RecoverFileRequest {
required string fileName = 1;
required string owner = 2;
optional string signature = 3;
required uint64 date = 4;
optional uint64 fileId = 5;
};

message RecoverFileResponse {
required StatusCode statusCode = 1;
}

message GetFileInfoRequest {
required string fileName = 1;

Expand Down Expand Up @@ -513,6 +529,7 @@ service CurveFSService {
// basic rpcs
rpc CreateFile(CreateFileRequest) returns (CreateFileResponse);
rpc DeleteFile(DeleteFileRequest) returns (DeleteFileResponse);
rpc RecoverFile(RecoverFileRequest) returns (RecoverFileResponse);
rpc GetFileInfo(GetFileInfoRequest) returns (GetFileInfoResponse);
rpc GetOrAllocateSegment(GetOrAllocateSegmentRequest)
returns (GetOrAllocateSegmentResponse);
Expand Down
3 changes: 3 additions & 0 deletions src/client/client_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ struct MDSClientMetric {
InterfaceMetric extendFile;
// DeleteFile接口统计信息
InterfaceMetric deleteFile;
// RecoverFile interface metric
InterfaceMetric recoverFile;
// changeowner接口统计信息
InterfaceMetric changeOwner;
// listdir接口统计信息
Expand Down Expand Up @@ -192,6 +194,7 @@ struct MDSClientMetric {
renameFile(prefix, "renameFile"),
extendFile(prefix, "extendFile"),
deleteFile(prefix, "deleteFile"),
recoverFile(prefix, "recoverFile"),
changeOwner(prefix, "changeOwner"),
listDir(prefix, "listDir"),
registerClient(prefix, "registerClient"),
Expand Down
27 changes: 27 additions & 0 deletions src/client/libcurve_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ int FileClient::Unlink(const std::string& filename,
return -ret;
}

int FileClient::Recover(const std::string& filename,
const UserInfo_t& userinfo, uint64_t fileId) {
LIBCURVE_ERROR ret;
if (mdsClient_ != nullptr) {
ret = mdsClient_->RecoverFile(filename, userinfo, fileId);
LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK)
<< "Recover failed, filename: " << filename
<< ", ret: " << ret;
} else {
LOG(ERROR) << "global mds client not inited!";
return -LIBCURVE_ERROR::FAILED;
}
return -ret;
}

int FileClient::StatFile(const std::string& filename,
const UserInfo_t& userinfo, FileStatInfo* finfo) {
FInfo_t fi;
Expand Down Expand Up @@ -806,6 +821,18 @@ int DeleteForce(const char* filename, const C_UserInfo_t* userinfo) {
true);
}

int Recover(const char* filename, const C_UserInfo_t* userinfo,
uint64_t fileId) {
if (globalclient == nullptr) {
LOG(ERROR) << "not inited!";
return -LIBCURVE_ERROR::FAILED;
}

return globalclient->Recover(filename,
UserInfo(userinfo->owner, userinfo->password),
fileId);
}

DirInfo_t* OpenDir(const char* dirpath, const C_UserInfo_t* userinfo) {
if (globalclient == nullptr) {
LOG(ERROR) << "not inited!";
Expand Down
10 changes: 10 additions & 0 deletions src/client/libcurve_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ class FileClient {
const UserInfo_t& userinfo,
bool deleteforce = false);

/**
* recycle file
* @param: userinfo
* @param: filename
* @param: fileId
*/
virtual int Recover(const std::string& filename,
const UserInfo_t& userinfo,
uint64_t fileId);

/**
* 枚举目录内容
* @param: userinfo是用户信息
Expand Down
32 changes: 32 additions & 0 deletions src/client/mds_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ using curve::mds::PageFileChunkInfo;
using curve::mds::PageFileSegment;
using curve::mds::CreateFileResponse;
using curve::mds::DeleteFileResponse;
using curve::mds::RecoverFileResponse;
using curve::mds::GetFileInfoResponse;
using curve::mds::GetOrAllocateSegmentResponse;
using curve::mds::RenameFileResponse;
Expand Down Expand Up @@ -1059,6 +1060,37 @@ LIBCURVE_ERROR MDSClient::DeleteFile(const std::string& filename,
return rpcExcutor.DoRPCTask(task, metaServerOpt_.mdsMaxRetryMS);
}

LIBCURVE_ERROR MDSClient::RecoverFile(const std::string& filename,
const UserInfo_t& userinfo,
uint64_t fileid) {
auto task = RPCTaskDefine {
RecoverFileResponse response;
mdsClientMetric_.recoverFile.qps.count << 1;
LatencyGuard lg(&mdsClientMetric_.recoverFile.latency);
mdsClientBase_.RecoverFile(filename, userinfo, fileid,
&response, cntl, channel);
if (cntl->Failed()) {
mdsClientMetric_.recoverFile.eps.count << 1;
LOG(WARNING) << "RecoverFile invoke failed, errcorde = "
<< cntl->ErrorCode() << ", error content:"
<< cntl->ErrorText() << ", log id = " << cntl->log_id();
return -cntl->ErrorCode();
}

LIBCURVE_ERROR retcode;
StatusCode stcode = response.statuscode();
MDSStatusCode2LibcurveError(stcode, &retcode);
LOG_IF(WARNING, retcode != LIBCURVE_ERROR::OK)
<< "RecoverFile: filename = " << filename
<< ", owner = " << userinfo.owner
<< ", errocde = " << retcode
<< ", error msg = " << StatusCode_Name(stcode)
<< ", log id = " << cntl->log_id();
return retcode;
};
return rpcExcutor.DoRPCTask(task, metaServerOpt_.mdsMaxRetryMS);
}

LIBCURVE_ERROR MDSClient::ChangeOwner(const std::string& filename,
const std::string& newOwner,
const UserInfo_t& userinfo) {
Expand Down
Loading

0 comments on commit b5e46ba

Please sign in to comment.