From 5bfe64d54859876a6335c917834e46d1a1c0b236 Mon Sep 17 00:00:00 2001 From: gueFDF <3237455241@qq.com> Date: Fri, 3 Mar 2023 15:01:14 +0000 Subject: [PATCH] Signed-off-by: gueFDF <3237455241@qq.com> [fix]curve/src Printed some more meaningful log messages. [style] cuerve/src Modify some code specifications. --- curvefs/src/volume/block_device_client.cpp | 81 +- include/client/libcbd.h | 102 +- include/client/libcurve_define.h | 74 +- src/chunkserver/clone_copyer.cpp | 57 +- src/client/chunkserver_broadcaster.cpp | 12 +- src/client/chunkserver_client.cpp | 91 +- src/client/discard_task.cpp | 21 +- src/client/io_tracker.cpp | 282 ++-- src/client/lease_executor.cpp | 32 +- src/client/libcbd_ext4.cpp | 58 +- src/client/libcbd_libcurve.cpp | 1 + src/client/libcurve_file.cpp | 457 +++--- src/client/libcurve_snapshot.cpp | 14 +- src/client/mds_client.cpp | 120 +- src/client/source_reader.cpp | 3 +- src/snapshotcloneserver/clone/clone_core.cpp | 909 +++++------ .../snapshot/snapshot_core.cpp | 407 ++--- .../snapshotcloneserver_recover_test.cpp | 3 +- .../test_snapshot_core.cpp | 1420 ++++++----------- 19 files changed, 1779 insertions(+), 2365 deletions(-) diff --git a/curvefs/src/volume/block_device_client.cpp b/curvefs/src/volume/block_device_client.cpp index 001bf48aab..25616299bc 100644 --- a/curvefs/src/volume/block_device_client.cpp +++ b/curvefs/src/volume/block_device_client.cpp @@ -52,25 +52,23 @@ BlockDeviceClientImpl::BlockDeviceClientImpl() : fd_(-1), fileClient_(std::make_shared()) {} BlockDeviceClientImpl::BlockDeviceClientImpl( - const std::shared_ptr& fileClient) + const std::shared_ptr &fileClient) : fd_(-1), fileClient_(fileClient) {} -bool BlockDeviceClientImpl::Init(const BlockDeviceClientOptions& options) { +bool BlockDeviceClientImpl::Init(const BlockDeviceClientOptions &options) { auto ret = fileClient_->Init(options.configPath); if (ret != LIBCURVE_ERROR::OK) { - LOG(ERROR) << "Init file client error: " << ret; + LOG(ERROR) << "Init file client error: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); return false; } return true; } +void BlockDeviceClientImpl::UnInit() { fileClient_->UnInit(); } -void BlockDeviceClientImpl::UnInit() { - fileClient_->UnInit(); -} - -bool BlockDeviceClientImpl::Open(const std::string& filename, - const std::string& owner) { +bool BlockDeviceClientImpl::Open(const std::string &filename, + const std::string &owner) { UserInfo userInfo(owner); curve::client::OpenFlags flags; auto retCode = fileClient_->Open(filename, userInfo, flags); @@ -93,7 +91,8 @@ bool BlockDeviceClientImpl::Close() { int retCode; if ((retCode = fileClient_->Close(fd_)) != LIBCURVE_ERROR::OK) { - LOG(ERROR) << "Close file failed, retCode = " << retCode; + LOG(ERROR) << "Close file failed, retCode = " << retCode + << LibCurveErrorName((LIBCURVE_ERROR)retCode); return false; } @@ -101,28 +100,31 @@ bool BlockDeviceClientImpl::Close() { return true; } -bool BlockDeviceClientImpl::Stat(const std::string& filename, - const std::string& owner, - BlockDeviceStat* statInfo) { +bool BlockDeviceClientImpl::Stat(const std::string &filename, + const std::string &owner, + BlockDeviceStat *statInfo) { FileStatInfo fileStatInfo; UserInfo userInfo(owner); auto retCode = fileClient_->StatFile(filename, userInfo, &fileStatInfo); if (retCode != LIBCURVE_ERROR::OK) { - LOG(ERROR) << "Stat file failed, retCode = " << retCode; + LOG(ERROR) << "Stat file failed, retCode = " << retCode + << LibCurveErrorName((LIBCURVE_ERROR)retCode); return false; } statInfo->length = fileStatInfo.length; if (!ConvertFileStatus(fileStatInfo.fileStatus, &statInfo->status)) { LOG(ERROR) << "Stat file failed, unknown file status: " - << fileStatInfo.fileStatus; + << fileStatInfo.fileStatus + << LibCurveErrorName((LIBCURVE_ERROR)retCode); + return false; } return true; } -ssize_t BlockDeviceClientImpl::Read(char* buf, off_t offset, size_t length) { +ssize_t BlockDeviceClientImpl::Read(char *buf, off_t offset, size_t length) { VLOG(9) << "read request, offset: " << offset << ", length: " << length; LatencyUpdater updater(&g_read_latency); @@ -138,7 +140,7 @@ ssize_t BlockDeviceClientImpl::Read(char* buf, off_t offset, size_t length) { return request.Wait(); } -ssize_t BlockDeviceClientImpl::Readv(const std::vector& iov) { +ssize_t BlockDeviceClientImpl::Readv(const std::vector &iov) { if (iov.size() == 1) { VLOG(9) << "read block offset: " << iov[0].offset << ", length: " << iov[0].length; @@ -148,7 +150,7 @@ ssize_t BlockDeviceClientImpl::Readv(const std::vector& iov) { std::vector> requests; requests.reserve(iov.size()); - for (const auto& io : iov) { + for (const auto &io : iov) { requests.push_back(absl::make_unique( io.offset, io.length, io.data, fileClient_.get(), fd_)); @@ -157,7 +159,7 @@ ssize_t BlockDeviceClientImpl::Readv(const std::vector& iov) { bool error = false; ssize_t total = 0; - for (const auto& r : requests) { + for (const auto &r : requests) { auto nr = r->Wait(); if (nr < 0) { error = true; @@ -171,11 +173,8 @@ ssize_t BlockDeviceClientImpl::Readv(const std::vector& iov) { return error ? -1 : total; } -ssize_t BlockDeviceClientImpl::Write(const char* buf, - off_t offset, +ssize_t BlockDeviceClientImpl::Write(const char *buf, off_t offset, size_t length) { - VLOG(9) << "write request, offset: " << offset << ", length: " << length; - LatencyUpdater updater(&g_write_latency); if (fd_ < 0) { @@ -189,7 +188,7 @@ ssize_t BlockDeviceClientImpl::Write(const char* buf, return request.Wait(); } -ssize_t BlockDeviceClientImpl::Writev(const std::vector& iov) { +ssize_t BlockDeviceClientImpl::Writev(const std::vector &iov) { if (iov.size() == 1) { return Write(iov[0].data, iov[0].offset, iov[0].length); } @@ -197,7 +196,7 @@ ssize_t BlockDeviceClientImpl::Writev(const std::vector& iov) { std::vector> requests; requests.reserve(iov.size()); - for (const auto& io : iov) { + for (const auto &io : iov) { requests.push_back(absl::make_unique( io.offset, io.length, io.data, fileClient_.get(), fd_)); @@ -206,7 +205,7 @@ ssize_t BlockDeviceClientImpl::Writev(const std::vector& iov) { bool error = false; ssize_t total = 0; - for (const auto& r : requests) { + for (const auto &r : requests) { auto nr = r->Wait(); if (nr < 0) { error = true; @@ -220,12 +219,11 @@ ssize_t BlockDeviceClientImpl::Writev(const std::vector& iov) { return error ? -1 : total; } -bool BlockDeviceClientImpl::WritePadding(char* writeBuffer, - off_t writeStart, +bool BlockDeviceClientImpl::WritePadding(char *writeBuffer, off_t writeStart, off_t writeEnd, off_t offset, // actual offset size_t length) { // actual length - std::vector> readvec; // Align reads + std::vector> readvec; // Align reads off_t readEnd = 0; // Padding leading @@ -244,7 +242,7 @@ bool BlockDeviceClientImpl::WritePadding(char* writeBuffer, } } - for (const auto& item : readvec) { + for (const auto &item : readvec) { auto retCode = AlignRead(writeBuffer + item.first - writeStart, item.first, item.second); if (retCode != item.second) { @@ -255,8 +253,7 @@ bool BlockDeviceClientImpl::WritePadding(char* writeBuffer, return true; } -ssize_t BlockDeviceClientImpl::AlignRead(char* buf, - off_t offset, +ssize_t BlockDeviceClientImpl::AlignRead(char *buf, off_t offset, size_t length) { auto ret = fileClient_->Read(fd_, buf, offset, length); if (ret < 0) { @@ -271,8 +268,7 @@ ssize_t BlockDeviceClientImpl::AlignRead(char* buf, return length; } -ssize_t BlockDeviceClientImpl::AlignWrite(const char* buf, - off_t offset, +ssize_t BlockDeviceClientImpl::AlignWrite(const char *buf, off_t offset, size_t length) { auto ret = fileClient_->Write(fd_, buf, offset, length); if (ret < 0) { @@ -288,15 +284,14 @@ ssize_t BlockDeviceClientImpl::AlignWrite(const char* buf, } bool BlockDeviceClientImpl::ConvertFileStatus(int fileStatus, - BlockDeviceStatus* bdStatus) { - static const std::map fileStatusMap { - { 0, BlockDeviceStatus::CREATED }, - { 1, BlockDeviceStatus::DELETING }, - { 2, BlockDeviceStatus::CLONING }, - { 3, BlockDeviceStatus::CLONE_META_INSTALLED }, - { 4, BlockDeviceStatus::CLONED }, - { 5, BlockDeviceStatus::BEING_CLONED } - }; + BlockDeviceStatus *bdStatus) { + static const std::map fileStatusMap{ + {0, BlockDeviceStatus::CREATED}, + {1, BlockDeviceStatus::DELETING}, + {2, BlockDeviceStatus::CLONING}, + {3, BlockDeviceStatus::CLONE_META_INSTALLED}, + {4, BlockDeviceStatus::CLONED}, + {5, BlockDeviceStatus::BEING_CLONED}}; auto iter = fileStatusMap.find(fileStatus); if (iter == fileStatusMap.end()) { diff --git a/include/client/libcbd.h b/include/client/libcbd.h index 6f854b4c10..dc3972276b 100644 --- a/include/client/libcbd.h +++ b/include/client/libcbd.h @@ -47,77 +47,77 @@ extern "C" { #define CBD_BACKEND_EXT4 #endif -#define CBD_MAX_FILE_PATH_LEN 1024 -#define CBD_MAX_BUF_LEN 1024 * 1024 * 32 +#define CBD_MAX_FILE_PATH_LEN 1024 +#define CBD_MAX_BUF_LEN 1024 * 1024 * 32 typedef int CurveFd; typedef struct CurveOptions { - bool inited; - char* conf; + bool inited; + char *conf; #ifdef CBD_BACKEND_EXT4 - char* datahome; + char *datahome; #endif } CurveOptions; -int cbd_ext4_init(const CurveOptions* options); +int cbd_ext4_init(const CurveOptions *options); int cbd_ext4_fini(void); -int cbd_ext4_open(const char* filename); +int cbd_ext4_open(const char *filename); int cbd_ext4_close(int fd); -int cbd_ext4_pread(int fd, void* buf, off_t offset, size_t length); -int cbd_ext4_pwrite(int fd, const void* buf, off_t offset, size_t length); +int cbd_ext4_pread(int fd, void *buf, off_t offset, size_t length); +int cbd_ext4_pwrite(int fd, const void *buf, off_t offset, size_t length); int cbd_ext4_pdiscard(int fd, off_t offset, size_t length); -int cbd_ext4_aio_pread(int fd, CurveAioContext* context); -int cbd_ext4_aio_pwrite(int fd, CurveAioContext* context); -int cbd_ext4_aio_pdiscard(int fd, CurveAioContext* context); +int cbd_ext4_aio_pread(int fd, CurveAioContext *context); +int cbd_ext4_aio_pwrite(int fd, CurveAioContext *context); +int cbd_ext4_aio_pdiscard(int fd, CurveAioContext *context); int cbd_ext4_sync(int fd); -int64_t cbd_ext4_filesize(const char* filename); -int cbd_ext4_increase_epoch(const char* filename); +int64_t cbd_ext4_filesize(const char *filename); +int cbd_ext4_increase_epoch(const char *filename); -int cbd_libcurve_init(const CurveOptions* options); +int cbd_libcurve_init(const CurveOptions *options); int cbd_libcurve_fini(void); -int cbd_libcurve_open(const char* filename); +int cbd_libcurve_open(const char *filename); int cbd_libcurve_close(int fd); -int cbd_libcurve_pread(int fd, void* buf, off_t offset, size_t length); -int cbd_libcurve_pwrite(int fd, const void* buf, off_t offset, size_t length); +int cbd_libcurve_pread(int fd, void *buf, off_t offset, size_t length); +int cbd_libcurve_pwrite(int fd, const void *buf, off_t offset, size_t length); int cbd_libcurve_pdiscard(int fd, off_t offset, size_t length); -int cbd_libcurve_aio_pread(int fd, CurveAioContext* context); -int cbd_libcurve_aio_pwrite(int fd, CurveAioContext* context); -int cbd_libcurve_aio_pdiscard(int fd, CurveAioContext* context); +int cbd_libcurve_aio_pread(int fd, CurveAioContext *context); +int cbd_libcurve_aio_pwrite(int fd, CurveAioContext *context); +int cbd_libcurve_aio_pdiscard(int fd, CurveAioContext *context); int cbd_libcurve_sync(int fd); -int64_t cbd_libcurve_filesize(const char* filename); -int cbd_libcurve_resize(const char* filename, int64_t size); -int cbd_libcurve_increase_epoch(const char* filename); +int64_t cbd_libcurve_filesize(const char *filename); +int cbd_libcurve_resize(const char *filename, int64_t size); +int cbd_libcurve_increase_epoch(const char *filename); #ifndef CBD_BACKEND_FAKE -#define cbd_lib_init cbd_libcurve_init -#define cbd_lib_fini cbd_libcurve_fini -#define cbd_lib_open cbd_libcurve_open -#define cbd_lib_close cbd_libcurve_close -#define cbd_lib_pread cbd_libcurve_pread -#define cbd_lib_pwrite cbd_libcurve_pwrite -#define cbd_lib_pdiscard cbd_libcurve_pdiscard -#define cbd_lib_aio_pread cbd_libcurve_aio_pread -#define cbd_lib_aio_pwrite cbd_libcurve_aio_pwrite -#define cbd_lib_aio_pdiscard cbd_libcurve_aio_pdiscard -#define cbd_lib_sync cbd_libcurve_sync -#define cbd_lib_filesize cbd_libcurve_filesize -#define cbd_lib_resize cbd_libcurve_resize -#define cbd_lib_increase_epoch cbd_libcurve_increase_epoch +#define cbd_lib_init cbd_libcurve_init +#define cbd_lib_fini cbd_libcurve_fini +#define cbd_lib_open cbd_libcurve_open +#define cbd_lib_close cbd_libcurve_close +#define cbd_lib_pread cbd_libcurve_pread +#define cbd_lib_pwrite cbd_libcurve_pwrite +#define cbd_lib_pdiscard cbd_libcurve_pdiscard +#define cbd_lib_aio_pread cbd_libcurve_aio_pread +#define cbd_lib_aio_pwrite cbd_libcurve_aio_pwrite +#define cbd_lib_aio_pdiscard cbd_libcurve_aio_pdiscard +#define cbd_lib_sync cbd_libcurve_sync +#define cbd_lib_filesize cbd_libcurve_filesize +#define cbd_lib_resize cbd_libcurve_resize +#define cbd_lib_increase_epoch cbd_libcurve_increase_epoch #else -#define cbd_lib_init cbd_ext4_init -#define cbd_lib_fini cbd_ext4_fini -#define cbd_lib_open cbd_ext4_open -#define cbd_lib_close cbd_ext4_close -#define cbd_lib_pread cbd_ext4_pread -#define cbd_lib_pwrite cbd_ext4_pwrite -#define cbd_lib_pdiscard cbd_ext4_pdiscard -#define cbd_lib_aio_pread cbd_ext4_aio_pread -#define cbd_lib_aio_pwrite cbd_ext4_aio_pwrite -#define cbd_lib_aio_pdiscard cbd_ext4_aio_pdiscard -#define cbd_lib_sync cbd_ext4_sync -#define cbd_lib_filesize cbd_ext4_filesize -#define cbd_lib_increase_epoch cbd_ext4_increase_epoch +#define cbd_lib_init cbd_ext4_init +#define cbd_lib_fini cbd_ext4_fini +#define cbd_lib_open cbd_ext4_open +#define cbd_lib_close cbd_ext4_close +#define cbd_lib_pread cbd_ext4_pread +#define cbd_lib_pwrite cbd_ext4_pwrite +#define cbd_lib_pdiscard cbd_ext4_pdiscard +#define cbd_lib_aio_pread cbd_ext4_aio_pread +#define cbd_lib_aio_pwrite cbd_ext4_aio_pwrite +#define cbd_lib_aio_pdiscard cbd_ext4_aio_pdiscard +#define cbd_lib_sync cbd_ext4_sync +#define cbd_lib_filesize cbd_ext4_filesize +#define cbd_lib_increase_epoch cbd_ext4_increase_epoch #endif #ifdef __cplusplus diff --git a/include/client/libcurve_define.h b/include/client/libcurve_define.h index f92d08f223..223291eaee 100644 --- a/include/client/libcurve_define.h +++ b/include/client/libcurve_define.h @@ -29,61 +29,61 @@ enum LIBCURVE_ERROR { // success - OK = 0, + OK = 0, // volume or dir exists - EXISTS = 1, + EXISTS = 1, // failed - FAILED = 2, + FAILED = 2, // disable IO - DISABLEIO = 3, + DISABLEIO = 3, // authentication failed - AUTHFAIL = 4, + AUTHFAIL = 4, // volume is deleting state - DELETING = 5, + DELETING = 5, // volume not exist - NOTEXIST = 6, + NOTEXIST = 6, // under snapshot - UNDER_SNAPSHOT = 7, + UNDER_SNAPSHOT = 7, // not under snapshot - NOT_UNDERSNAPSHOT = 8, + NOT_UNDERSNAPSHOT = 8, // delete error - DELETE_ERROR = 9, + DELETE_ERROR = 9, // segment not allocated - NOT_ALLOCATE = 10, + NOT_ALLOCATE = 10, // operation not supported - NOT_SUPPORT = 11, + NOT_SUPPORT = 11, // directory not empty - NOT_EMPTY = 12, + NOT_EMPTY = 12, // no shrinkage - NO_SHRINK_BIGGER_FILE = 13, + NO_SHRINK_BIGGER_FILE = 13, // session not exist - SESSION_NOTEXISTS = 14, + SESSION_NOTEXISTS = 14, // volume occupied - FILE_OCCUPIED = 15, + FILE_OCCUPIED = 15, // parameter error - PARAM_ERROR = 16, + PARAM_ERROR = 16, // internal error - INTERNAL_ERROR = 17, + INTERNAL_ERROR = 17, // CRC error - CRC_ERROR = 18, + CRC_ERROR = 18, // parameter invalid - INVALID_REQUEST = 19, + INVALID_REQUEST = 19, // disk fail - DISK_FAIL = 20, + DISK_FAIL = 20, // not enough space - NO_SPACE = 21, + NO_SPACE = 21, // io not aligned - NOT_ALIGNED = 22, + NOT_ALIGNED = 22, // volume file is being closed, fd unavailable - BAD_FD = 23, + BAD_FD = 23, // volume file length is not supported - LENGTH_NOT_SUPPORT = 24, + LENGTH_NOT_SUPPORT = 24, // session not exist - SESSION_NOT_EXIST = 25, + SESSION_NOT_EXIST = 25, // status error - STATUS_NOT_MATCH = 26, + STATUS_NOT_MATCH = 26, // delete the file being cloned - DELETE_BEING_CLONED = 27, + DELETE_BEING_CLONED = 27, // this version of client not support snapshot CLIENT_NOT_SUPPORT_SNAPSHOT = 28, // snapshot is forbid now @@ -94,9 +94,13 @@ enum LIBCURVE_ERROR { EPOCH_TOO_OLD = 31, // unknown error - UNKNOWN = 100 + UNKNOWN = 100 }; + + + + typedef enum LIBCURVE_OP { LIBCURVE_OP_READ, LIBCURVE_OP_WRITE, @@ -105,15 +109,15 @@ typedef enum LIBCURVE_OP { } LIBCURVE_OP; -typedef void (*LibCurveAioCallBack)(struct CurveAioContext* context); +typedef void (*LibCurveAioCallBack)(struct CurveAioContext *context); typedef struct CurveAioContext { - off_t offset; - size_t length; - int ret; - LIBCURVE_OP op; + off_t offset; + size_t length; + int ret; + LIBCURVE_OP op; LibCurveAioCallBack cb; - void* buf; + void *buf; } CurveAioContext; #endif // INCLUDE_CLIENT_LIBCURVE_DEFINE_H_ diff --git a/src/chunkserver/clone_copyer.cpp b/src/chunkserver/clone_copyer.cpp index 858a257939..9f216ff409 100644 --- a/src/chunkserver/clone_copyer.cpp +++ b/src/chunkserver/clone_copyer.cpp @@ -53,14 +53,14 @@ void CurveAioCallback(struct CurveAioContext* context) { brpc::ClosureGuard doneGuard(done); } -void OriginCopyer::DeleteExpiredCurveCache(void* arg) { - OriginCopyer* taskCopyer = static_cast(arg); +void OriginCopyer::DeleteExpiredCurveCache(void *arg) { + OriginCopyer* taskCopyer = static_cast(arg); std::unique_lock lock(taskCopyer->mtx_); std::unique_lock lockTime(taskCopyer->timeMtx_); timespec now = butil::seconds_from_now(0); while (taskCopyer->curveOpenTime_.size() > 0) { - CurveOpenTimestamp oldestCache = *taskCopyer->curveOpenTime_.begin(); + CurveOpenTimestamp oldestCache =* taskCopyer->curveOpenTime_.begin(); if (now.tv_sec - oldestCache.lastUsedSec < taskCopyer->curveFileTimeoutSec_) { break; @@ -72,8 +72,8 @@ void OriginCopyer::DeleteExpiredCurveCache(void* arg) { } if (taskCopyer->curveOpenTime_.size() > 0) { - int64_t nextTimer = taskCopyer->curveFileTimeoutSec_ - now.tv_sec - + taskCopyer->curveOpenTime_.begin()->lastUsedSec; + int64_t nextTimer = taskCopyer->curveFileTimeoutSec_ - now.tv_sec + + taskCopyer->curveOpenTime_.begin()->lastUsedSec; timespec nextTimespec = butil::seconds_from_now(nextTimer); taskCopyer->timerId_ = taskCopyer->timer_.schedule( &DeleteExpiredCurveCache, arg, nextTimespec); @@ -94,7 +94,7 @@ int OriginCopyer::Init(const CopyerOptions& options) { int errorCode = curveClient_->Init(options.curveConf.c_str()); if (errorCode != 0) { LOG(ERROR) << "Init curve client failed." - << "error code: " << errorCode; + << "error code: " << errorCode; return -1; } curveUser_ = options.curveUser; @@ -155,12 +155,10 @@ void OriginCopyer::DownloadAsync(DownloadClosure* done) { return; } DownloadFromCurve(fileName, chunkOffset + context->offset, - context->size, context->buf, - done); + context->size, context->buf, done); doneGuard.release(); } else if (type == OriginType::S3Origin) { - DownloadFromS3(originPath, context->offset, - context->size, context->buf, + DownloadFromS3(originPath, context->offset, context->size, context->buf, done); doneGuard.release(); } else { @@ -170,11 +168,9 @@ void OriginCopyer::DownloadAsync(DownloadClosure* done) { } } -void OriginCopyer::DownloadFromS3(const string& objectName, - off_t off, - size_t size, - char* buf, - DownloadClosure* done) { +void OriginCopyer::DownloadFromS3(const string &objectName, off_t off, + size_t size, char *buf, + DownloadClosure *done) { brpc::ClosureGuard doneGuard(done); if (s3Client_ == nullptr) { LOG(ERROR) << "Failed to get s3 object." @@ -184,8 +180,8 @@ void OriginCopyer::DownloadFromS3(const string& objectName, } GetObjectAsyncCallBack cb = - [=] (const S3Adapter* adapter, - const std::shared_ptr& context) { + [=](const S3Adapter *adapter, + const std::shared_ptr &context) { brpc::ClosureGuard doneGuard(done); if (context->retCode != 0) { done->SetFailed(); @@ -203,11 +199,9 @@ void OriginCopyer::DownloadFromS3(const string& objectName, doneGuard.release(); } -void OriginCopyer::DownloadFromCurve(const string& fileName, - off_t off, - size_t size, - char* buf, - DownloadClosure* done) { +void OriginCopyer::DownloadFromCurve(const string &fileName, off_t off, + size_t size, char *buf, + DownloadClosure *done) { brpc::ClosureGuard doneGuard(done); if (curveClient_ == nullptr) { LOG(ERROR) << "Failed to read curve file." @@ -225,7 +219,7 @@ void OriginCopyer::DownloadFromCurve(const string& fileName, fd = iter->second; auto fdIter = std::find_if( curveOpenTime_.cbegin(), curveOpenTime_.cend(), - [&] (const CurveOpenTimestamp& s) {return s.fd == fd;}); + [&](const CurveOpenTimestamp &s) { return s.fd == fd; }); if (fdIter != curveOpenTime_.cend()) { timespec now = butil::seconds_from_now(0); curveOpenTime_.emplace_back(fd, fileName, now.tv_sec); @@ -237,8 +231,8 @@ void OriginCopyer::DownloadFromCurve(const string& fileName, fd = curveClient_->Open4ReadOnly(fileName, curveUser_, true); if (fd < 0) { LOG(ERROR) << "Open curve file failed." - << "file name: " << fileName - << " ,return code: " << fd; + << "file name: " << fileName + << " ,return code: " << fd; done->SetFailed(); return; } @@ -248,8 +242,8 @@ void OriginCopyer::DownloadFromCurve(const string& fileName, if (timerId_ == bthread::TimerThread::INVALID_TASK_ID) { timespec nextTimespec = butil::seconds_from_now(curveFileTimeoutSec_); - timerId_ = timer_.schedule( - &DeleteExpiredCurveCache, this, nextTimespec); + timerId_ = timer_.schedule(&DeleteExpiredCurveCache, this, + nextTimespec); } } } @@ -262,11 +256,12 @@ void OriginCopyer::DownloadFromCurve(const string& fileName, curveCombineCtx->curveCtx.op = LIBCURVE_OP::LIBCURVE_OP_READ; curveCombineCtx->curveCtx.cb = CurveAioCallback; - int ret = curveClient_->AioRead(fd, &curveCombineCtx->curveCtx); - if (ret != LIBCURVE_ERROR::OK) { + int ret = curveClient_->AioRead(fd, &curveCombineCtx->curveCtx); + if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "Read curve file failed." - << "file name: " << fileName - << " ,error code: " << ret; + << "file name: " << fileName << " ,error code: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); + delete curveCombineCtx; done->SetFailed(); } else { diff --git a/src/client/chunkserver_broadcaster.cpp b/src/client/chunkserver_broadcaster.cpp index 5e6f9fb628..cc83d3f5dd 100644 --- a/src/client/chunkserver_broadcaster.cpp +++ b/src/client/chunkserver_broadcaster.cpp @@ -61,8 +61,8 @@ int ChunkServerBroadCaster::BroadCastFileEpoch( tracker->Wait(); LOG(ERROR) << "BroadCastFileEpoch request failed, ret: " << ret << ", chunkserverid: " << cs.peerID - << ", fileId: " << fileId - << ", epoch: " << epoch; + << ", fileId: " << fileId << ", epoch: " << epoch + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } if (tracker->GetTaskNum() >= option_.broadCastMaxNum) { @@ -73,7 +73,7 @@ int ChunkServerBroadCaster::BroadCastFileEpoch( // already failed, wait all inflight rpc to be done tracker->Wait(); LOG(ERROR) << "BroadCastFileEpoch found some request failed, ret: " - << ret; + << ret << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } } @@ -81,7 +81,7 @@ int ChunkServerBroadCaster::BroadCastFileEpoch( ret = tracker->GetResult(); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "BroadCastFileEpoch found some request failed, ret: " - << ret; + << ret << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } @@ -89,5 +89,5 @@ int ChunkServerBroadCaster::BroadCastFileEpoch( } -} // namespace client -} // namespace curve +} // namespace client +} // namespace curve diff --git a/src/client/chunkserver_client.cpp b/src/client/chunkserver_client.cpp index 77d72a09bd..43e36f10e9 100644 --- a/src/client/chunkserver_client.cpp +++ b/src/client/chunkserver_client.cpp @@ -26,15 +26,15 @@ #include #include -using curve::chunkserver::ChunkService_Stub; using curve::chunkserver::CHUNK_OP_STATUS; +using curve::chunkserver::ChunkService_Stub; namespace curve { namespace client { -int ChunkServerClient::UpdateFileEpoch( - const CopysetPeerInfo &cs, uint64_t fileId, uint64_t epoch, - ChunkServerClientClosure *done) { +int ChunkServerClient::UpdateFileEpoch(const CopysetPeerInfo &cs, + uint64_t fileId, uint64_t epoch, + ChunkServerClientClosure *done) { brpc::ClosureGuard doneGuard(done); std::unique_ptr ctx(new UpdateEpochContext); @@ -43,19 +43,20 @@ int ChunkServerClient::UpdateFileEpoch( ret = ctx->channel.Init(cs.externalAddr.addr_, NULL); if (ret != 0) { LOG(ERROR) << "failed to init channel to chunkserver, " - << "id: " << cs.peerID - << ", "<< cs.externalAddr.addr_.ip - << ":" << cs.externalAddr.addr_.port; + << "id: " << cs.peerID << ", " + << cs.externalAddr.addr_.ip << ":" + << cs.externalAddr.addr_.port; + return -LIBCURVE_ERROR::INTERNAL_ERROR; } } else { ret = ctx->channel.Init(cs.internalAddr.addr_, NULL); if (ret != 0) { LOG(ERROR) << "failed to init channel to chunkserver, " - << "id: " << cs.peerID - << ", "<< cs.internalAddr.addr_.ip - << ":" << cs.internalAddr.addr_.port; - return -LIBCURVE_ERROR::INTERNAL_ERROR; + << "id: " << cs.peerID << ", " + << cs.internalAddr.addr_.ip << ":" + << cs.internalAddr.addr_.port; + return -::INTERNAL_ERROR; } } @@ -68,19 +69,17 @@ int ChunkServerClient::UpdateFileEpoch( ctx->curTry = 1; // 1 for current try ctx->retryOps_ = retryOps_; - google::protobuf::Closure* rpcDone = brpc::NewCallback( - OnUpdateFileEpochReturned, ctx.get()); + google::protobuf::Closure *rpcDone = + brpc::NewCallback(OnUpdateFileEpochReturned, ctx.get()); ChunkService_Stub stub(&ctx->channel); - stub.UpdateEpoch(&ctx->cntl, &ctx->request, - &ctx->response, rpcDone); + stub.UpdateEpoch(&ctx->cntl, &ctx->request, &ctx->response, rpcDone); doneGuard.release(); ctx.release(); return LIBCURVE_ERROR::OK; } -void ChunkServerClient::OnUpdateFileEpochReturned( - UpdateEpochContext *ctx) { +void ChunkServerClient::OnUpdateFileEpochReturned(UpdateEpochContext *ctx) { std::unique_ptr ctx_guard(ctx); brpc::ClosureGuard doneGuard(ctx->done); if (ctx->cntl.Failed()) { @@ -89,7 +88,7 @@ void ChunkServerClient::OnUpdateFileEpochReturned( ctx->cntl.ErrorCode() == ECONNRESET || ctx->cntl.ErrorCode() == ECONNREFUSED) { LOG(INFO) << "UpdateEpoch unable to contact chunkserver."; - ctx->done->SetErrCode(LIBCURVE_ERROR::OK); + ctx->done->SetErrCode(::OK); } else if (ctx->curTry < ctx->retryOps_.rpcMaxTry) { bthread_usleep(ctx->retryOps_.rpcIntervalUs); ctx->cntl.Reset(); @@ -99,46 +98,44 @@ void ChunkServerClient::OnUpdateFileEpochReturned( ctx->cntl.set_timeout_ms(nextTimeOutMs); ctx->curTry++; ctx->response.Clear(); - google::protobuf::Closure* rpcDone = brpc::NewCallback( - OnUpdateFileEpochReturned, ctx_guard.get()); + google::protobuf::Closure *rpcDone = + brpc::NewCallback(OnUpdateFileEpochReturned, ctx_guard.get()); ChunkService_Stub stub(&ctx->channel); - stub.UpdateEpoch(&ctx->cntl, &ctx->request, - &ctx->response, rpcDone); + stub.UpdateEpoch(&ctx->cntl, &ctx->request, &ctx->response, + rpcDone); doneGuard.release(); ctx_guard.release(); } else { LOG(WARNING) << "UpdateEpoch failed, cntl.errotText: " << ctx->cntl.ErrorText(); - ctx->done->SetErrCode(-LIBCURVE_ERROR::FAILED); + ctx->done->SetErrCode(-::FAILED); } } else { switch (ctx->response.status()) { - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_SUCCESS: - LOG(INFO) << "Received UpdateEpoch Response [log_id=" - << ctx->cntl.log_id() - << "] from " << ctx->cntl.remote_side() - << " to " << ctx->cntl.local_side() - << ", Message: " - << ctx->response.DebugString(); - ctx->done->SetErrCode(LIBCURVE_ERROR::OK); - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_EPOCH_TOO_OLD: - LOG(WARNING) << "Received UpdateEpoch Response [log_id=" - << ctx->cntl.log_id() - << "] from " << ctx->cntl.remote_side() - << " to " << ctx->cntl.local_side() - << ", Message: " - << ctx->response.DebugString(); - ctx->done->SetErrCode(-LIBCURVE_ERROR::EPOCH_TOO_OLD); - break; - default: - LOG(ERROR) << "can't reach here!"; - ctx->done->SetErrCode(-LIBCURVE_ERROR::UNKNOWN); - break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_SUCCESS: + LOG(INFO) << "Received UpdateEpoch Response [log_id=" + << ctx->cntl.log_id() << "] from " + << ctx->cntl.remote_side() << " to " + << ctx->cntl.local_side() + << ", Message: " << ctx->response.DebugString(); + ctx->done->SetErrCode(::OK); + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_EPOCH_TOO_OLD: + LOG(WARNING) << "Received UpdateEpoch Response [log_id=" + << ctx->cntl.log_id() << "] from " + << ctx->cntl.remote_side() << " to " + << ctx->cntl.local_side() + << ", Message: " << ctx->response.DebugString(); + ctx->done->SetErrCode(-::EPOCH_TOO_OLD); + break; + default: + LOG(ERROR) << "can't reach here!"; + ctx->done->SetErrCode(-::UNKNOWN); + break; } } } -} // namespace client -} // namespace curve +} // namespace client +} // namespace curve diff --git a/src/client/discard_task.cpp b/src/client/discard_task.cpp index 6ae6c09db7..cbdb33b5be 100644 --- a/src/client/discard_task.cpp +++ b/src/client/discard_task.cpp @@ -33,10 +33,10 @@ namespace curve { namespace client { void DiscardTask::Run() { - const FInfo* fileInfo = metaCache_->GetFileInfo(); + const FInfo *fileInfo = metaCache_->GetFileInfo(); uint64_t offset = static_cast(segmentIndex_) * fileInfo->segmentsize; - FileSegment* fileSegment = metaCache_->GetFileSegment(segmentIndex_); + FileSegment *fileSegment = metaCache_->GetFileSegment(segmentIndex_); fileSegment->AcquireWriteLock(); metric_->pending << -1; @@ -69,18 +69,19 @@ void DiscardTask::Run() { metric_->totalError << 1; LOG(ERROR) << "DiscardTask failed, mds return error = " << errCode << ", filename = " << fileInfo->fullPathName - << ", offset = " << offset << ", taskid = " << timerId_; + << ", offset = " << offset << ", taskid = " << timerId_ + << LibCurveErrorName((LIBCURVE_ERROR)errCode); } fileSegment->ReleaseLock(); taskManager_->OnTaskFinish(timerId_); } -DiscardTaskManager::DiscardTaskManager(DiscardMetric* metric) +DiscardTaskManager::DiscardTaskManager(DiscardMetric *metric) : mtx_(), cond_(), unfinishedTasks_(), metric_(metric) {} -static void RunDiscardTask(void* arg) { - DiscardTask* task = static_cast(arg); +static void RunDiscardTask(void *arg) { + DiscardTask *task = static_cast(arg); task->Run(); } @@ -91,8 +92,8 @@ void DiscardTaskManager::OnTaskFinish(bthread_timer_t timerId) { } bool DiscardTaskManager::ScheduleTask(SegmentIndex segmentIndex, - MetaCache* metaCache, - MDSClient* mdsclient, timespec abstime) { + MetaCache *metaCache, + MDSClient *mdsclient, timespec abstime) { bthread_timer_t timerId; std::unique_ptr task( new DiscardTask(this, segmentIndex, metaCache, mdsclient, metric_)); @@ -117,12 +118,12 @@ void DiscardTaskManager::Stop() { { std::lock_guard lk(mtx_); - for (auto& kv : unfinishedTasks_) { + for (auto &kv : unfinishedTasks_) { currentTasks.emplace(kv.first); } } - for (const auto& timerId : currentTasks) { + for (const auto &timerId : currentTasks) { int ret = bthread_timer_del(timerId); if (ret == 0) { diff --git a/src/client/io_tracker.cpp b/src/client/io_tracker.cpp index 238be74d96..a0faefdc45 100644 --- a/src/client/io_tracker.cpp +++ b/src/client/io_tracker.cpp @@ -44,38 +44,33 @@ using curve::chunkserver::CHUNK_OP_STATUS; std::atomic IOTracker::tracekerID_(1); DiscardOption IOTracker::discardOption_; -IOTracker::IOTracker(IOManager* iomanager, - MetaCache* mc, - RequestScheduler* scheduler, - FileMetric* clientMetric, +IOTracker::IOTracker(IOManager *iomanager, MetaCache *mc, + RequestScheduler *scheduler, FileMetric *clientMetric, bool disableStripe) - : mc_(mc), - iomanager_(iomanager), - scheduler_(scheduler), - fileMetric_(clientMetric), - disableStripe_(disableStripe) { - id_ = tracekerID_.fetch_add(1, std::memory_order_relaxed); - scc_ = nullptr; - aioctx_ = nullptr; - data_ = nullptr; - type_ = OpType::UNKNOWN; - errcode_ = LIBCURVE_ERROR::OK; - offset_ = 0; - length_ = 0; + : mc_(mc), iomanager_(iomanager), scheduler_(scheduler), + fileMetric_(clientMetric), disableStripe_(disableStripe) { + id_ = tracekerID_.fetch_add(1, std::memory_order_relaxed); + scc_ = nullptr; + aioctx_ = nullptr; + data_ = nullptr; + type_ = OpType::UNKNOWN; + errcode_ = LIBCURVE_ERROR::OK; + offset_ = 0; + length_ = 0; reqlist_.clear(); reqcount_.store(0, std::memory_order_release); opStartTimePoint_ = curve::common::TimeUtility::GetTimeofDayUs(); } void IOTracker::ReleaseAllSegmentLocks() { - for (auto& readlock : segmentLocks_) { + for (auto &readlock : segmentLocks_) { readlock->ReleaseLock(); } } -void IOTracker::StartRead(void* buf, off_t offset, size_t length, - MDSClient* mdsclient, const FInfo_t* fileInfo, - Throttle* throttle) { +void IOTracker::StartRead(void *buf, off_t offset, size_t length, + MDSClient *mdsclient, const FInfo_t *fileInfo, + Throttle *throttle) { data_ = buf; offset_ = offset; length_ = length; @@ -86,8 +81,8 @@ void IOTracker::StartRead(void* buf, off_t offset, size_t length, DoRead(mdsclient, fileInfo, throttle); } -void IOTracker::StartAioRead(CurveAioContext* ctx, MDSClient* mdsclient, - const FInfo_t* fileInfo, Throttle* throttle) { +void IOTracker::StartAioRead(CurveAioContext *ctx, MDSClient *mdsclient, + const FInfo_t *fileInfo, Throttle *throttle) { aioctx_ = ctx; data_ = ctx->buf; offset_ = ctx->offset; @@ -100,8 +95,8 @@ void IOTracker::StartAioRead(CurveAioContext* ctx, MDSClient* mdsclient, DoRead(mdsclient, fileInfo, throttle); } -void IOTracker::DoRead(MDSClient* mdsclient, const FInfo_t* fileInfo, - Throttle* throttle) { +void IOTracker::DoRead(MDSClient *mdsclient, const FInfo_t *fileInfo, + Throttle *throttle) { if (throttle) { throttle->Add(true, length_); } @@ -111,9 +106,9 @@ void IOTracker::DoRead(MDSClient* mdsclient, const FInfo_t* fileInfo, if (ret == 0) { PrepareReadIOBuffers(reqlist_.size()); uint32_t subIoIndex = 0; - std::vector originReadVec; + std::vector originReadVec; - std::for_each(reqlist_.begin(), reqlist_.end(), [&](RequestContext* r) { + std::for_each(reqlist_.begin(), reqlist_.end(), [&](RequestContext *r) { // fake subrequest if (!r->idinfo_.chunkExist) { // the clone source is empty @@ -150,9 +145,9 @@ void IOTracker::DoRead(MDSClient* mdsclient, const FInfo_t* fileInfo, } } -int IOTracker::ReadFromSource(const std::vector& reqCtxVec, - const UserInfo_t& userInfo, - MDSClient* mdsClient) { +int IOTracker::ReadFromSource(const std::vector &reqCtxVec, + const UserInfo_t &userInfo, + MDSClient *mdsClient) { if (reqCtxVec.empty()) { return 0; } @@ -160,11 +155,10 @@ int IOTracker::ReadFromSource(const std::vector& reqCtxVec, return SourceReader::GetInstance().Read(reqCtxVec, userInfo, mdsClient); } -void IOTracker::StartWrite(const void* buf, off_t offset, size_t length, - MDSClient* mdsclient, const FInfo_t* fileInfo, - const FileEpoch* fEpoch, - Throttle* throttle) { - data_ = const_cast(buf); +void IOTracker::StartWrite(const void *buf, off_t offset, size_t length, + MDSClient *mdsclient, const FInfo_t *fileInfo, + const FileEpoch *fEpoch, Throttle *throttle) { + data_ = const_cast(buf); offset_ = offset; length_ = length; type_ = OpType::WRITE; @@ -174,9 +168,9 @@ void IOTracker::StartWrite(const void* buf, off_t offset, size_t length, DoWrite(mdsclient, fileInfo, fEpoch, throttle); } -void IOTracker::StartAioWrite(CurveAioContext* ctx, MDSClient* mdsclient, - const FInfo_t* fileInfo, const FileEpoch* fEpoch, - Throttle* throttle) { +void IOTracker::StartAioWrite(CurveAioContext *ctx, MDSClient *mdsclient, + const FInfo_t *fileInfo, const FileEpoch *fEpoch, + Throttle *throttle) { aioctx_ = ctx; data_ = ctx->buf; offset_ = ctx->offset; @@ -189,36 +183,34 @@ void IOTracker::StartAioWrite(CurveAioContext* ctx, MDSClient* mdsclient, DoWrite(mdsclient, fileInfo, fEpoch, throttle); } -void IOTracker::DoWrite(MDSClient* mdsclient, const FInfo_t* fileInfo, - const FileEpoch* fEpoch, - Throttle* throttle) { +void IOTracker::DoWrite(MDSClient *mdsclient, const FInfo_t *fileInfo, + const FileEpoch *fEpoch, Throttle *throttle) { if (nullptr == data_) { ReturnOnFail(); return; } switch (userDataType_) { - case UserDataType::RawBuffer: - writeData_.append_user_data(data_, length_, - TrivialDeleter); - break; - case UserDataType::IOBuffer: - writeData_ = *reinterpret_cast(data_); - break; + case UserDataType::RawBuffer: + writeData_.append_user_data(data_, length_, TrivialDeleter); + break; + case UserDataType::IOBuffer: + writeData_ = *reinterpret_cast(data_); + break; } if (throttle) { throttle->Add(false, length_); } - int ret = Splitor::IO2ChunkRequests(this, mc_, &reqlist_, &writeData_, - offset_, length_, - mdsclient, fileInfo, fEpoch); + int ret = + Splitor::IO2ChunkRequests(this, mc_, &reqlist_, &writeData_, offset_, + length_, mdsclient, fileInfo, fEpoch); if (ret == 0) { uint32_t subIoIndex = 0; reqcount_.store(reqlist_.size(), std::memory_order_release); - std::for_each(reqlist_.begin(), reqlist_.end(), [&](RequestContext* r) { + std::for_each(reqlist_.begin(), reqlist_.end(), [&](RequestContext *r) { r->done_->SetFileMetric(fileMetric_); r->done_->SetIOManager(iomanager_); r->subIoIndex_ = subIoIndex++; @@ -235,9 +227,9 @@ void IOTracker::DoWrite(MDSClient* mdsclient, const FInfo_t* fileInfo, } } -void IOTracker::StartDiscard(off_t offset, size_t length, MDSClient* mdsclient, - const FInfo* fileInfo, - DiscardTaskManager* taskManager) { +void IOTracker::StartDiscard(off_t offset, size_t length, MDSClient *mdsclient, + const FInfo *fileInfo, + DiscardTaskManager *taskManager) { offset_ = offset; length_ = length; type_ = OpType::DISCARD; @@ -245,9 +237,9 @@ void IOTracker::StartDiscard(off_t offset, size_t length, MDSClient* mdsclient, DoDiscard(mdsclient, fileInfo, taskManager); } -void IOTracker::StartAioDiscard(CurveAioContext* ctx, MDSClient* mdsclient, - const FInfo_t* fileInfo, - DiscardTaskManager* taskManager) { +void IOTracker::StartAioDiscard(CurveAioContext *ctx, MDSClient *mdsclient, + const FInfo_t *fileInfo, + DiscardTaskManager *taskManager) { aioctx_ = ctx; offset_ = ctx->offset; length_ = ctx->length; @@ -256,8 +248,8 @@ void IOTracker::StartAioDiscard(CurveAioContext* ctx, MDSClient* mdsclient, DoDiscard(mdsclient, fileInfo, taskManager); } -void IOTracker::DoDiscard(MDSClient* mdsClient, const FInfo* fileInfo, - DiscardTaskManager* taskManager) { +void IOTracker::DoDiscard(MDSClient *mdsClient, const FInfo *fileInfo, + DiscardTaskManager *taskManager) { int ret = Splitor::IO2ChunkRequests(this, mc_, &reqlist_, nullptr, offset_, length_, mdsClient, fileInfo, nullptr); @@ -284,14 +276,14 @@ void IOTracker::DoDiscard(MDSClient* mdsClient, const FInfo* fileInfo, Done(); } -void IOTracker::ReadSnapChunk(const ChunkIDInfo &cinfo, - uint64_t seq, uint64_t offset, uint64_t len, - char *buf, SnapCloneClosure* scc) { - scc_ = scc; - data_ = buf; +void IOTracker::ReadSnapChunk(const ChunkIDInfo &cinfo, uint64_t seq, + uint64_t offset, uint64_t len, char *buf, + SnapCloneClosure *scc) { + scc_ = scc; + data_ = buf; offset_ = offset; length_ = len; - type_ = OpType::READ_SNAP; + type_ = OpType::READ_SNAP; int ret = -1; do { @@ -302,7 +294,7 @@ void IOTracker::ReadSnapChunk(const ChunkIDInfo &cinfo, uint32_t subIoIndex = 0; reqcount_.store(reqlist_.size(), std::memory_order_release); - for (auto& req : reqlist_) { + for (auto &req : reqlist_) { req->subIoIndex_ = subIoIndex++; } @@ -317,12 +309,12 @@ void IOTracker::ReadSnapChunk(const ChunkIDInfo &cinfo, } void IOTracker::DeleteSnapChunkOrCorrectSn(const ChunkIDInfo &cinfo, - uint64_t correctedSeq) { + uint64_t correctedSeq) { type_ = OpType::DELETE_SNAP; int ret = -1; do { - RequestContext* newreqNode = RequestContext::NewInitedRequestContext(); + RequestContext *newreqNode = RequestContext::NewInitedRequestContext(); if (newreqNode == nullptr) { break; } @@ -344,12 +336,12 @@ void IOTracker::DeleteSnapChunkOrCorrectSn(const ChunkIDInfo &cinfo, } void IOTracker::GetChunkInfo(const ChunkIDInfo &cinfo, - ChunkInfoDetail *chunkInfo) { + ChunkInfoDetail *chunkInfo) { type_ = OpType::GET_CHUNK_INFO; int ret = -1; do { - RequestContext* newreqNode = RequestContext::NewInitedRequestContext(); + RequestContext *newreqNode = RequestContext::NewInitedRequestContext(); if (newreqNode == nullptr) { break; } @@ -370,24 +362,24 @@ void IOTracker::GetChunkInfo(const ChunkIDInfo &cinfo, } } -void IOTracker::CreateCloneChunk(const std::string& location, - const ChunkIDInfo& cinfo, uint64_t sn, +void IOTracker::CreateCloneChunk(const std::string &location, + const ChunkIDInfo &cinfo, uint64_t sn, uint64_t correntSn, uint64_t chunkSize, - SnapCloneClosure* scc) { + SnapCloneClosure *scc) { type_ = OpType::CREATE_CLONE; scc_ = scc; int ret = -1; do { - RequestContext* newreqNode = RequestContext::NewInitedRequestContext(); + RequestContext *newreqNode = RequestContext::NewInitedRequestContext(); if (newreqNode == nullptr) { break; } - newreqNode->seq_ = sn; - newreqNode->chunksize_ = chunkSize; - newreqNode->location_ = location; - newreqNode->correctedSeq_ = correntSn; + newreqNode->seq_ = sn; + newreqNode->chunksize_ = chunkSize; + newreqNode->location_ = location; + newreqNode->correctedSeq_ = correntSn; FillCommonFields(cinfo, newreqNode); reqlist_.push_back(newreqNode); @@ -403,20 +395,20 @@ void IOTracker::CreateCloneChunk(const std::string& location, } } -void IOTracker::RecoverChunk(const ChunkIDInfo& cinfo, uint64_t offset, - uint64_t len, SnapCloneClosure* scc) { +void IOTracker::RecoverChunk(const ChunkIDInfo &cinfo, uint64_t offset, + uint64_t len, SnapCloneClosure *scc) { type_ = OpType::RECOVER_CHUNK; scc_ = scc; int ret = -1; do { - RequestContext* newreqNode = RequestContext::NewInitedRequestContext(); + RequestContext *newreqNode = RequestContext::NewInitedRequestContext(); if (newreqNode == nullptr) { break; } - newreqNode->rawlength_ = len; - newreqNode->offset_ = offset; + newreqNode->rawlength_ = len; + newreqNode->offset_ = offset; FillCommonFields(cinfo, newreqNode); reqlist_.push_back(newreqNode); @@ -432,13 +424,13 @@ void IOTracker::RecoverChunk(const ChunkIDInfo& cinfo, uint64_t offset, } } -void IOTracker::FillCommonFields(ChunkIDInfo idinfo, RequestContext* req) { - req->optype_ = type_; - req->idinfo_ = idinfo; +void IOTracker::FillCommonFields(ChunkIDInfo idinfo, RequestContext *req) { + req->optype_ = type_; + req->idinfo_ = idinfo; req->done_->SetIOTracker(this); } -void IOTracker::HandleResponse(RequestContext* reqctx) { +void IOTracker::HandleResponse(RequestContext *reqctx) { int errorcode = reqctx->done_->GetErrorCode(); if (errorcode != 0) { ChunkServerErr2LibcurveErr(static_cast(errorcode), @@ -455,13 +447,11 @@ void IOTracker::HandleResponse(RequestContext* reqctx) { } } -void IOTracker::InitDiscardOption(const DiscardOption& opt) { +void IOTracker::InitDiscardOption(const DiscardOption &opt) { discardOption_ = opt; } -int IOTracker::Wait() { - return iocv_.Wait(); -} +int IOTracker::Wait() { return iocv_.Wait(); } void IOTracker::Done() { if (type_ == OpType::READ || type_ == OpType::WRITE) { @@ -476,27 +466,27 @@ void IOTracker::Done() { // copy read data to user buffer if (OpType::READ == type_ || OpType::READ_SNAP == type_) { butil::IOBuf readData; - for (const auto& buf : readDatas_) { + for (const auto &buf : readDatas_) { readData.append(buf); } switch (userDataType_) { - case UserDataType::RawBuffer: { - size_t nc = readData.copy_to(data_, readData.size()); - if (nc != length_) { - errcode_ = LIBCURVE_ERROR::FAILED; - } - break; + case UserDataType::RawBuffer: { + size_t nc = readData.copy_to(data_, readData.size()); + if (nc != length_) { + errcode_ = LIBCURVE_ERROR::FAILED; } - case UserDataType::IOBuffer: { - butil::IOBuf* userData = - reinterpret_cast(data_); - *userData = readData; - if (userData->size() != length_) { - errcode_ = LIBCURVE_ERROR::FAILED; - } - break; + break; + } + case UserDataType::IOBuffer: { + butil::IOBuf *userData = + reinterpret_cast(data_); + *userData = readData; + if (userData->size() != length_) { + errcode_ = LIBCURVE_ERROR::FAILED; } + break; + } } if (errcode_ != LIBCURVE_ERROR::OK) { @@ -510,15 +500,15 @@ void IOTracker::Done() { MetricHelper::IncremUserEPSCount(fileMetric_, type_); if (type_ == OpType::READ || type_ == OpType::WRITE) { if (LIBCURVE_ERROR::EPOCH_TOO_OLD == errcode_) { - LOG(WARNING) << "file [" << fileMetric_->filename << "]" - << ", epoch too old, OpType = " << OpTypeToString(type_) - << ", offset = " << offset_ - << ", length = " << length_; + LOG(WARNING) + << "file [" << fileMetric_->filename << "]" + << ", epoch too old, OpType = " << OpTypeToString(type_) + << ", offset = " << offset_ << ", length = " << length_; } else { LOG(ERROR) << "file [" << fileMetric_->filename << "]" - << ", IO Error, OpType = " << OpTypeToString(type_) - << ", offset = " << offset_ - << ", length = " << length_; + << ", IO Error, OpType = " << OpTypeToString(type_) + << ", offset = " << offset_ + << ", length = " << length_; } } else { if (OpType::CREATE_CLONE == type_ && @@ -565,39 +555,39 @@ void IOTracker::ReturnOnFail() { } void IOTracker::ChunkServerErr2LibcurveErr(CHUNK_OP_STATUS errcode, - LIBCURVE_ERROR* errout) { + LIBCURVE_ERROR *errout) { switch (errcode) { - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_SUCCESS: - *errout = LIBCURVE_ERROR::OK; - break; - // chunk或者copyset对于用户来说是透明的,所以直接返回错误 - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CHUNK_NOTEXIST: - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_COPYSET_NOTEXIST: - *errout = LIBCURVE_ERROR::NOTEXIST; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CRC_FAIL: - *errout = LIBCURVE_ERROR::CRC_ERROR; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_INVALID_REQUEST: - *errout = LIBCURVE_ERROR::INVALID_REQUEST; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_DISK_FAIL: - *errout = LIBCURVE_ERROR::DISK_FAIL; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_NOSPACE: - *errout = LIBCURVE_ERROR::NO_SPACE; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CHUNK_EXIST: - *errout = LIBCURVE_ERROR::EXISTS; - break; - case CHUNK_OP_STATUS::CHUNK_OP_STATUS_EPOCH_TOO_OLD: - *errout = LIBCURVE_ERROR::EPOCH_TOO_OLD; - break; - default: - *errout = LIBCURVE_ERROR::FAILED; - break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_SUCCESS: + *errout = LIBCURVE_ERROR::OK; + break; + // chunk或者copyset对于用户来说是透明的,所以直接返回错误 + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CHUNK_NOTEXIST: + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_COPYSET_NOTEXIST: + *errout = LIBCURVE_ERROR::NOTEXIST; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CRC_FAIL: + *errout = LIBCURVE_ERROR::CRC_ERROR; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_INVALID_REQUEST: + *errout = LIBCURVE_ERROR::INVALID_REQUEST; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_DISK_FAIL: + *errout = LIBCURVE_ERROR::DISK_FAIL; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_NOSPACE: + *errout = LIBCURVE_ERROR::NO_SPACE; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_CHUNK_EXIST: + *errout = LIBCURVE_ERROR::EXISTS; + break; + case CHUNK_OP_STATUS::CHUNK_OP_STATUS_EPOCH_TOO_OLD: + *errout = LIBCURVE_ERROR::EPOCH_TOO_OLD; + break; + default: + *errout = LIBCURVE_ERROR::FAILED; + break; } } -} // namespace client -} // namespace curve +} // namespace client +} // namespace curve diff --git a/src/client/lease_executor.cpp b/src/client/lease_executor.cpp index c8db8ddd30..19f37fd4de 100644 --- a/src/client/lease_executor.cpp +++ b/src/client/lease_executor.cpp @@ -29,18 +29,12 @@ using curve::common::TimeUtility; namespace curve { namespace client { -LeaseExecutor::LeaseExecutor(const LeaseOption& leaseOpt, - const UserInfo& userinfo, MDSClient* mdsclient, - IOManager4File* iomanager) - : fullFileName_(), - mdsclient_(mdsclient), - userinfo_(userinfo), - iomanager_(iomanager), - leaseoption_(leaseOpt), - leasesession_(), - isleaseAvaliable_(true), - failedrefreshcount_(0), - task_() {} +LeaseExecutor::LeaseExecutor(const LeaseOption &leaseOpt, + const UserInfo &userinfo, MDSClient *mdsclient, + IOManager4File *iomanager) + : fullFileName_(), mdsclient_(mdsclient), userinfo_(userinfo), + iomanager_(iomanager), leaseoption_(leaseOpt), leasesession_(), + isleaseAvaliable_(true), failedrefreshcount_(0), task_() {} LeaseExecutor::~LeaseExecutor() { if (task_) { @@ -49,7 +43,7 @@ LeaseExecutor::~LeaseExecutor() { } } -bool LeaseExecutor::Start(const FInfo_t& fi, const LeaseSession_t& lease) { +bool LeaseExecutor::Start(const FInfo_t &fi, const LeaseSession_t &lease) { fullFileName_ = fi.fullPathName; leasesession_ = lease; @@ -145,9 +139,7 @@ void LeaseExecutor::Stop() { } } -bool LeaseExecutor::LeaseValid() { - return isleaseAvaliable_.load(); -} +bool LeaseExecutor::LeaseValid() { return isleaseAvaliable_.load(); } void LeaseExecutor::IncremRefreshFailed() { failedrefreshcount_.fetch_add(1); @@ -158,8 +150,8 @@ void LeaseExecutor::IncremRefreshFailed() { } } -void LeaseExecutor::CheckNeedUpdateFileInfo(const FInfo& fileInfo) { - MetaCache* metaCache = iomanager_->GetMetaCache(); +void LeaseExecutor::CheckNeedUpdateFileInfo(const FInfo &fileInfo) { + MetaCache *metaCache = iomanager_->GetMetaCache(); uint64_t currentFileSn = metaCache->GetLatestFileSn(); uint64_t newSn = fileInfo.seqnum; @@ -203,5 +195,5 @@ void LeaseExecutor::ResetRefreshSessionTask() { isleaseAvaliable_.store(true); } -} // namespace client -} // namespace curve +} // namespace client +} // namespace curve diff --git a/src/client/libcbd_ext4.cpp b/src/client/libcbd_ext4.cpp index ae48dd530b..d63e6b497a 100644 --- a/src/client/libcbd_ext4.cpp +++ b/src/client/libcbd_ext4.cpp @@ -28,7 +28,7 @@ extern "C" { CurveOptions g_cbd_ext4_options = {false, 0}; -int cbd_ext4_init(const CurveOptions* options) { +int cbd_ext4_init(const CurveOptions *options) { if (g_cbd_ext4_options.inited) { return 0; } @@ -45,47 +45,44 @@ int cbd_ext4_init(const CurveOptions* options) { return 0; } -int cbd_ext4_fini() { - return 0; -} +int cbd_ext4_fini() { return 0; } -int cbd_ext4_open(const char* filename) { +int cbd_ext4_open(const char *filename) { int fd = -1; char path[CBD_MAX_FILE_PATH_LEN] = {0}; #ifdef CBD_BACKEND_EXT4 - strcat(path, g_cbd_ext4_options.datahome); //NOLINT - strcat(path, "/"); //NOLINT + strcat(path, g_cbd_ext4_options.datahome); // NOLINT + strcat(path, "/"); // NOLINT #endif - strcat(path, filename); //NOLINT + strcat(path, filename); // NOLINT fd = open(path, O_RDWR | O_CREAT, 0660); return fd; } -int cbd_ext4_close(int fd) { - return close(fd); -} +int cbd_ext4_close(int fd) { return close(fd); } -int cbd_ext4_pread(int fd, void* buf, off_t offset, size_t length) { +int cbd_ext4_pread(int fd, void *buf, off_t offset, size_t length) { return pread(fd, buf, length, offset); } -int cbd_ext4_pwrite(int fd, const void* buf, off_t offset, size_t length) { +int cbd_ext4_pwrite(int fd, const void *buf, off_t offset, size_t length) { return pwrite(fd, buf, length, offset); } -int cbd_ext4_pdiscard(int fd, off_t offset, size_t length) { +int cbd_ext4_get_LIBCURVE_ERRORpdiscard(int fd, off_t offset, size_t length) { return 0; } void cbd_ext4_aio_callback(union sigval sigev_value) { - CurveAioContext* context = (CurveAioContext *)sigev_value.sival_ptr; //NOLINT + CurveAioContext *context = + (CurveAioContext *)sigev_value.sival_ptr; // NOLINT context->cb(context); } -int cbd_ext4_aio_pread(int fd, CurveAioContext* context) { - struct aiocb* cb; +int cbd_ext4_aio_pread(int fd, CurveAioContext *context) { + struct aiocb *cb; cb = (struct aiocb *)malloc(sizeof(struct aiocb)); if (!cb) { @@ -98,14 +95,14 @@ int cbd_ext4_aio_pread(int fd, CurveAioContext* context) { cb->aio_nbytes = context->length; cb->aio_buf = context->buf; cb->aio_sigevent.sigev_notify = SIGEV_THREAD; - cb->aio_sigevent.sigev_value.sival_ptr = (void*)context; //NOLINT + cb->aio_sigevent.sigev_value.sival_ptr = (void *)context; // NOLINT cb->aio_sigevent.sigev_notify_function = cbd_ext4_aio_callback; return aio_read(cb); } -int cbd_ext4_aio_pwrite(int fd, CurveAioContext* context) { - struct aiocb* cb; +int cbd_ext4_aio_pwrite(int fd, CurveAioContext *context) { + struct aiocb *cb; cb = (struct aiocb *)malloc(sizeof(struct aiocb)); if (!cb) { @@ -118,32 +115,30 @@ int cbd_ext4_aio_pwrite(int fd, CurveAioContext* context) { cb->aio_nbytes = context->length; cb->aio_buf = context->buf; cb->aio_sigevent.sigev_notify = SIGEV_THREAD; - cb->aio_sigevent.sigev_value.sival_ptr = (void*)context; //NOLINT + cb->aio_sigevent.sigev_value.sival_ptr = (void *)context; // NOLINT cb->aio_sigevent.sigev_notify_function = cbd_ext4_aio_callback; return aio_write(cb); } -int cbd_ext4_aio_pdiscard(int fd, CurveAioContext* aioctx) { +int cbd_ext4_aio_pdiscard(int fd, CurveAioContext *aioctx) { aioctx->ret = aioctx->length; aioctx->cb(aioctx); return 0; } -int cbd_ext4_sync(int fd) { - return fsync(fd); -} +int cbd_ext4_sync(int fd) { return fsync(fd); } -int64_t cbd_ext4_filesize(const char* filename) { +int64_t cbd_ext4_filesize(const char *filename) { struct stat st; int ret; char path[CBD_MAX_FILE_PATH_LEN] = {0}; #ifdef CBD_BACKEND_EXT4 - strcat(path, g_cbd_ext4_options.datahome); //NOLINT - strcat(path, "/"); //NOLINT + strcat(path, g_cbd_ext4_options.datahome); // NOLINT + strcat(path, "/"); // NOLINT #endif - strcat(path, filename); //NOLINT + strcat(path, filename); // NOLINT ret = stat(path, &st); if (ret) { @@ -153,9 +148,6 @@ int64_t cbd_ext4_filesize(const char* filename) { } } -int cbd_ext4_increase_epoch(const char* filename) { - return 0; -} +int cbd_ext4_increase_epoch(const char *filename) { return 0; } } // extern "C" - diff --git a/src/client/libcbd_libcurve.cpp b/src/client/libcbd_libcurve.cpp index 62fa3afc7d..95a4351437 100644 --- a/src/client/libcbd_libcurve.cpp +++ b/src/client/libcbd_libcurve.cpp @@ -115,4 +115,5 @@ int cbd_libcurve_increase_epoch(const char* filename) { return IncreaseEpoch(filename); } + } // extern "C" diff --git a/src/client/libcurve_file.cpp b/src/client/libcurve_file.cpp index c03d723a69..94ff8a8aca 100644 --- a/src/client/libcurve_file.cpp +++ b/src/client/libcurve_file.cpp @@ -48,7 +48,7 @@ #include "src/common/fast_align.h" bool globalclientinited_ = false; -curve::client::FileClient* globalclient = nullptr; +curve::client::FileClient *globalclient = nullptr; using curve::client::UserInfo; @@ -72,9 +72,9 @@ char g_processname[kProcessNameMax]; class LoggerGuard { private: - friend void InitLogging(const std::string& confPath); + friend void InitLogging(const std::string &confPath); - explicit LoggerGuard(const std::string& confpath) { + explicit LoggerGuard(const std::string &confpath) { InitInternal(confpath); } @@ -84,13 +84,13 @@ class LoggerGuard { } } - void InitInternal(const std::string& confpath); + void InitInternal(const std::string &confpath); private: bool needShutdown_ = false; }; -void LoggerGuard::InitInternal(const std::string& confPath) { +void LoggerGuard::InitInternal(const std::string &confPath) { curve::common::Configuration conf; conf.SetConfigPath(confPath); @@ -120,26 +120,22 @@ void LoggerGuard::InitInternal(const std::string& confPath) { LOG_IF(WARNING, !conf.GetStringValue("global.logPath", &FLAGS_log_dir)) << "config no logpath info, using default dir '/tmp'"; - std::string processName = std::string("libcurve-").append( - curve::common::UUIDGenerator().GenerateUUID().substr(0, 8)); - snprintf(g_processname, sizeof(g_processname), - "%s", processName.c_str()); + std::string processName = + std::string("libcurve-") + .append(curve::common::UUIDGenerator().GenerateUUID().substr(0, 8)); + snprintf(g_processname, sizeof(g_processname), "%s", processName.c_str()); google::InitGoogleLogging(g_processname); needShutdown_ = true; } -void InitLogging(const std::string& confPath) { +void InitLogging(const std::string &confPath) { static LoggerGuard guard(confPath); } } // namespace FileClient::FileClient() - : rwlock_(), - fdcount_(0), - fileserviceMap_(), - clientconfig_(), - mdsClient_(), + : rwlock_(), fdcount_(0), fileserviceMap_(), clientconfig_(), mdsClient_(), csClient_(std::make_shared()), csBroadCaster_(std::make_shared(csClient_)), inited_(false), @@ -150,7 +146,7 @@ bool FileClient::CheckAligned(off_t offset, size_t length) const { common::is_aligned(length, kMinIOAlignment); } -int FileClient::Init(const std::string& configpath) { +int FileClient::Init(const std::string &configpath) { if (inited_) { LOG(WARNING) << "already inited!"; return 0; @@ -187,8 +183,7 @@ int FileClient::Init(const std::string& configpath) { mdsClient_ = std::move(tmpMdsClient); - int rc2 = csClient_->Init( - clientconfig_.GetFileServiceOption().csClientOpt); + int rc2 = csClient_->Init(clientconfig_.GetFileServiceOption().csClientOpt); if (rc2 != 0) { LOG(ERROR) << "Init ChunkServer Client failed!"; return -LIBCURVE_ERROR::FAILED; @@ -221,11 +216,10 @@ void FileClient::UnInit() { inited_ = false; } -int FileClient::Open(const std::string& filename, - const UserInfo_t& userinfo, - const OpenFlags& openflags) { +int FileClient::Open(const std::string &filename, const UserInfo_t &userinfo, + const OpenFlags &openflags) { LOG(INFO) << "Opening filename: " << filename << ", flags: " << openflags; - FileInstance* fileserv = FileInstance::NewInitedFileInstance( + FileInstance *fileserv = FileInstance::NewInitedFileInstance( clientconfig_.GetFileServiceOption(), mdsClient_, filename, userinfo, openflags, false); if (fileserv == nullptr) { @@ -236,7 +230,8 @@ int FileClient::Open(const std::string& filename, int ret = fileserv->Open(filename, userinfo); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "Open file failed, filename: " << filename - << ", retCode: " << ret; + << ", retCode: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); fileserv->UnInitialize(); delete fileserv; return ret; @@ -256,9 +251,9 @@ int FileClient::Open(const std::string& filename, return fd; } -int FileClient::Open4ReadOnly(const std::string& filename, - const UserInfo_t& userinfo, bool disableStripe) { - FileInstance* instance = FileInstance::Open4Readonly( +int FileClient::Open4ReadOnly(const std::string &filename, + const UserInfo_t &userinfo, bool disableStripe) { + FileInstance *instance = FileInstance::Open4Readonly( clientconfig_.GetFileServiceOption(), mdsClient_, filename, userinfo); if (instance == nullptr) { @@ -283,29 +278,29 @@ int FileClient::Open4ReadOnly(const std::string& filename, return fd; } -int FileClient::IncreaseEpoch(const std::string& filename, - const UserInfo_t& userinfo) { +int FileClient::IncreaseEpoch(const std::string &filename, + const UserInfo_t &userinfo) { LOG(INFO) << "IncreaseEpoch, filename: " << filename; FInfo_t fi; FileEpoch_t fEpoch; std::list> csLocs; LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { - ret = mdsClient_->IncreaseEpoch(filename, userinfo, - &fi, &fEpoch, &csLocs); + ret = mdsClient_->IncreaseEpoch(filename, userinfo, &fi, &fEpoch, + &csLocs); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) << "IncreaseEpoch failed, filename: " << filename - << ", ret: " << ret; + << ", ret: " << ret << LibCurveErrorName((LIBCURVE_ERROR)ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; } - int ret2 = csBroadCaster_->BroadCastFileEpoch( - fEpoch.fileId, fEpoch.epoch, csLocs); + int ret2 = + csBroadCaster_->BroadCastFileEpoch(fEpoch.fileId, fEpoch.epoch, csLocs); LOG_IF(ERROR, ret2 != LIBCURVE_ERROR::OK) - << "BroadCastEpoch failed, filename: " << filename - << ", ret: " << ret2; + << "BroadCastEpoch failed, filename: " << filename << ", ret: " << ret2 + << LibCurveErrorName((LIBCURVE_ERROR)ret2); // update epoch if file is already open auto it = fileserviceFileNameMap_.find(filename); @@ -315,13 +310,14 @@ int FileClient::IncreaseEpoch(const std::string& filename, return ret2; } -int FileClient::Create(const std::string& filename, - const UserInfo_t& userinfo, size_t size) { +int FileClient::Create(const std::string &filename, const UserInfo_t &userinfo, + size_t size) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->CreateFile(filename, userinfo, size); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) - << "Create file failed, filename: " << filename << ", ret: " << ret; + << "Create file failed, filename: " << filename << ", ret: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -329,15 +325,16 @@ int FileClient::Create(const std::string& filename, return -ret; } -int FileClient::Create2(const std::string& filename, - const UserInfo_t& userinfo, size_t size, - uint64_t stripeUnit, uint64_t stripeCount) { +int FileClient::Create2(const std::string &filename, const UserInfo_t &userinfo, + size_t size, uint64_t stripeUnit, + uint64_t stripeCount) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { - ret = mdsClient_->CreateFile(filename, userinfo, size, true, - stripeUnit, stripeCount); + ret = mdsClient_->CreateFile(filename, userinfo, size, true, stripeUnit, + stripeCount); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) - << "Create file failed, filename: " << filename << ", ret: " << ret; + << "Create file failed, filename: " << filename << ", ret: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -345,7 +342,7 @@ int FileClient::Create2(const std::string& filename, return -ret; } -int FileClient::Read(int fd, char* buf, off_t offset, size_t len) { +int FileClient::Read(int fd, char *buf, off_t offset, size_t len) { // 长度为0,直接返回,不做任何操作 if (len == 0) { return -LIBCURVE_ERROR::OK; @@ -366,7 +363,7 @@ int FileClient::Read(int fd, char* buf, off_t offset, size_t len) { return fileserviceMap_[fd]->Read(buf, offset, len); } -int FileClient::Write(int fd, const char* buf, off_t offset, size_t len) { +int FileClient::Write(int fd, const char *buf, off_t offset, size_t len) { // 长度为0,直接返回,不做任何操作 if (len == 0) { return -LIBCURVE_ERROR::OK; @@ -398,7 +395,7 @@ int FileClient::Discard(int fd, off_t offset, size_t length) { return iter->second->Discard(offset, length); } -int FileClient::AioRead(int fd, CurveAioContext* aioctx, +int FileClient::AioRead(int fd, CurveAioContext *aioctx, UserDataType dataType) { // 长度为0,直接返回,不做任何操作 if (aioctx->length == 0) { @@ -423,7 +420,7 @@ int FileClient::AioRead(int fd, CurveAioContext* aioctx, return ret; } -int FileClient::AioWrite(int fd, CurveAioContext* aioctx, +int FileClient::AioWrite(int fd, CurveAioContext *aioctx, UserDataType dataType) { // 长度为0,直接返回,不做任何操作 if (aioctx->length == 0) { @@ -449,7 +446,7 @@ int FileClient::AioWrite(int fd, CurveAioContext* aioctx, return ret; } -int FileClient::AioDiscard(int fd, CurveAioContext* aioctx) { +int FileClient::AioDiscard(int fd, CurveAioContext *aioctx) { ReadLockGuard lk(rwlock_); auto iter = fileserviceMap_.find(fd); if (CURVE_UNLIKELY(iter == fileserviceMap_.end())) { @@ -460,14 +457,13 @@ int FileClient::AioDiscard(int fd, CurveAioContext* aioctx) { } } -int FileClient::Rename(const UserInfo_t& userinfo, - const std::string& oldpath, const std::string& newpath) { +int FileClient::Rename(const UserInfo_t &userinfo, const std::string &oldpath, + const std::string &newpath) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->RenameFile(userinfo, oldpath, newpath); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) - << "Rename failed, OldPath: " << oldpath - << ", NewPath: " << newpath + << "Rename failed, OldPath: " << oldpath << ", NewPath: " << newpath << ", ret: " << ret; } else { LOG(ERROR) << "global mds client not inited!"; @@ -476,15 +472,14 @@ int FileClient::Rename(const UserInfo_t& userinfo, return -ret; } -int FileClient::Extend(const std::string& filename, - const UserInfo_t& userinfo, uint64_t newsize) { +int FileClient::Extend(const std::string &filename, const UserInfo_t &userinfo, + uint64_t newsize) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->Extend(filename, userinfo, newsize); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) << "Extend failed, filename: " << filename - << ", NewSize: " << newsize - << ", ret: " << ret; + << ", NewSize: " << newsize << ", ret: " << ret; } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -492,15 +487,14 @@ int FileClient::Extend(const std::string& filename, return -ret; } -int FileClient::Unlink(const std::string& filename, - const UserInfo_t& userinfo, bool deleteforce) { +int FileClient::Unlink(const std::string &filename, const UserInfo_t &userinfo, + bool deleteforce) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->DeleteFile(filename, userinfo, deleteforce); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) << "Unlink failed, filename: " << filename - << ", force: " << deleteforce - << ", ret: " << ret; + << ", force: " << deleteforce << ", ret: " << ret; } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -508,14 +502,13 @@ int FileClient::Unlink(const std::string& filename, return -ret; } -int FileClient::Recover(const std::string& filename, - const UserInfo_t& userinfo, uint64_t fileId) { +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; + << "Recover failed, filename: " << filename << ", ret: " << ret; } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -523,8 +516,8 @@ int FileClient::Recover(const std::string& filename, return -ret; } -int FileClient::StatFile(const std::string& filename, - const UserInfo_t& userinfo, FileStatInfo* finfo) { +int FileClient::StatFile(const std::string &filename, + const UserInfo_t &userinfo, FileStatInfo *finfo) { FInfo_t fi; FileEpoch_t fEpoch; int ret; @@ -538,18 +531,18 @@ int FileClient::StatFile(const std::string& filename, } if (ret == LIBCURVE_ERROR::OK) { - finfo->id = fi.id; + finfo->id = fi.id; finfo->parentid = fi.parentid; - finfo->ctime = fi.ctime; - finfo->length = fi.length; + finfo->ctime = fi.ctime; + finfo->length = fi.length; finfo->filetype = fi.filetype; finfo->stripeUnit = fi.stripeUnit; finfo->stripeCount = fi.stripeCount; memcpy(finfo->filename, fi.filename.c_str(), - std::min(sizeof(finfo->filename), fi.filename.size() + 1)); + std::min(sizeof(finfo->filename), fi.filename.size() + 1)); memcpy(finfo->owner, fi.owner.c_str(), - std::min(sizeof(finfo->owner), fi.owner.size() + 1)); + std::min(sizeof(finfo->owner), fi.owner.size() + 1)); finfo->fileStatus = static_cast(fi.filestatus); } @@ -557,14 +550,15 @@ int FileClient::StatFile(const std::string& filename, return -ret; } -int FileClient::Listdir(const std::string& dirpath, - const UserInfo_t& userinfo, std::vector* filestatVec) { +int FileClient::Listdir(const std::string &dirpath, const UserInfo_t &userinfo, + std::vector *filestatVec) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->Listdir(dirpath, userinfo, filestatVec); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK && ret != LIBCURVE_ERROR::NOTEXIST) - << "Listdir failed, Path: " << dirpath << ", ret: " << ret; + << "Listdir failed, Path: " << dirpath << ", ret: " << ret + << LibCurveErrorName(ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -572,7 +566,7 @@ int FileClient::Listdir(const std::string& dirpath, return -ret; } -int FileClient::Mkdir(const std::string& dirpath, const UserInfo_t& userinfo) { +int FileClient::Mkdir(const std::string &dirpath, const UserInfo_t &userinfo) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->CreateFile(dirpath, userinfo, 0, false); @@ -583,7 +577,7 @@ int FileClient::Mkdir(const std::string& dirpath, const UserInfo_t& userinfo) { } else { LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) << "Create directory failed, dir: " << dirpath - << ", ret: " << ret; + << ", ret: " << ret << LibCurveErrorName(ret); } } } else { @@ -593,12 +587,13 @@ int FileClient::Mkdir(const std::string& dirpath, const UserInfo_t& userinfo) { return -ret; } -int FileClient::Rmdir(const std::string& dirpath, const UserInfo_t& userinfo) { +int FileClient::Rmdir(const std::string &dirpath, const UserInfo_t &userinfo) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->DeleteFile(dirpath, userinfo); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) - << "Rmdir failed, Path: " << dirpath << ", ret: " << ret; + << "Rmdir failed, Path: " << dirpath << ", ret: " << ret + << LibCurveErrorName(ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -606,13 +601,15 @@ int FileClient::Rmdir(const std::string& dirpath, const UserInfo_t& userinfo) { return -ret; } -int FileClient::ChangeOwner(const std::string& filename, - const std::string& newOwner, const UserInfo_t& userinfo) { +int FileClient::ChangeOwner(const std::string &filename, + const std::string &newOwner, + const UserInfo_t &userinfo) { LIBCURVE_ERROR ret; if (mdsClient_ != nullptr) { ret = mdsClient_->ChangeOwner(filename, newOwner, userinfo); LOG_IF(ERROR, ret != LIBCURVE_ERROR::OK) - << "ChangeOwner failed, filename: " << filename << ", ret: " << ret; + << "ChangeOwner failed, filename: " << filename << ", ret: " << ret + << LibCurveErrorName(ret); } else { LOG(ERROR) << "global mds client not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -655,7 +652,7 @@ int FileClient::Close(int fd) { return -LIBCURVE_ERROR::FAILED; } -int FileClient::GetClusterId(char* buf, int len) { +int FileClient::GetClusterId(char *buf, int len) { std::string result = GetClusterId(); if (result.empty()) { @@ -685,11 +682,12 @@ std::string FileClient::GetClusterId() { return clsctx.clusterId; } - LOG(ERROR) << "GetClusterId failed, ret: " << ret; + LOG(ERROR) << "GetClusterId failed, ret: " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); return {}; } -int FileClient::GetFileInfo(int fd, FInfo* finfo) { +int FileClient::GetFileInfo(int fd, FInfo *finfo) { int ret = -LIBCURVE_ERROR::FAILED; ReadLockGuard lk(rwlock_); @@ -745,23 +743,21 @@ bool FileClient::StartDummyServer() { return true; } -} // namespace client -} // namespace curve +} // namespace client +} // namespace curve // 全局初始化与反初始化 -int GlobalInit(const char* configpath); +int GlobalInit(const char *configpath); void GlobalUnInit(); -int Init(const char* path) { - return GlobalInit(path); -} +int Init(const char *path) { return GlobalInit(path); } -int Open4Qemu(const char* filename) { +int Open4Qemu(const char *filename) { curve::client::UserInfo_t userinfo; std::string realname; - bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename(filename, - &realname, &userinfo.owner); + bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename( + filename, &realname, &userinfo.owner); if (!ret) { LOG(ERROR) << "get user info from filename failed!"; return -LIBCURVE_ERROR::FAILED; @@ -775,11 +771,11 @@ int Open4Qemu(const char* filename) { return globalclient->Open(realname, userinfo); } -int IncreaseEpoch(const char* filename) { +int IncreaseEpoch(const char *filename) { curve::client::UserInfo_t userinfo; std::string realname; - bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename(filename, - &realname, &userinfo.owner); + bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename( + filename, &realname, &userinfo.owner); if (!ret) { LOG(ERROR) << "get user info from filename failed!"; return -LIBCURVE_ERROR::FAILED; @@ -793,11 +789,11 @@ int IncreaseEpoch(const char* filename) { return globalclient->IncreaseEpoch(realname, userinfo); } -int Extend4Qemu(const char* filename, int64_t newsize) { +int Extend4Qemu(const char *filename, int64_t newsize) { curve::client::UserInfo_t userinfo; std::string realname; - bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename(filename, - &realname, &userinfo.owner); + bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename( + filename, &realname, &userinfo.owner); if (!ret) { LOG(ERROR) << "get user info from filename failed!"; return -LIBCURVE_ERROR::FAILED; @@ -812,20 +808,20 @@ int Extend4Qemu(const char* filename, int64_t newsize) { } return globalclient->Extend(realname, userinfo, - static_cast(newsize)); + static_cast(newsize)); } -int Open(const char* filename, const C_UserInfo_t* userinfo) { +int Open(const char *filename, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Open(filename, - UserInfo(userinfo->owner, userinfo->password)); + UserInfo(userinfo->owner, userinfo->password)); } -int Read(int fd, char* buf, off_t offset, size_t length) { +int Read(int fd, char *buf, off_t offset, size_t length) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -834,7 +830,7 @@ int Read(int fd, char* buf, off_t offset, size_t length) { return globalclient->Read(fd, buf, offset, length); } -int Write(int fd, const char* buf, off_t offset, size_t length) { +int Write(int fd, const char *buf, off_t offset, size_t length) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -852,32 +848,30 @@ int Discard(int fd, off_t offset, size_t length) { return globalclient->Discard(fd, offset, length); } -int AioRead(int fd, CurveAioContext* aioctx) { +int AioRead(int fd, CurveAioContext *aioctx) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } - DVLOG(9) << "offset: " << aioctx->offset - << " length: " << aioctx->length - << " op: " << aioctx->op; + DVLOG(9) << "offset: " << aioctx->offset << " length: " << aioctx->length + << " op: " << aioctx->op; return globalclient->AioRead(fd, aioctx); } -int AioWrite(int fd, CurveAioContext* aioctx) { +int AioWrite(int fd, CurveAioContext *aioctx) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } - DVLOG(9) << "offset: " << aioctx->offset - << " length: " << aioctx->length - << " op: " << aioctx->op - << " buf: " << *(unsigned int*)aioctx->buf; + DVLOG(9) << "offset: " << aioctx->offset << " length: " << aioctx->length + << " op: " << aioctx->op + << " buf: " << *(unsigned int *)aioctx->buf; return globalclient->AioWrite(fd, aioctx); } -int AioDiscard(int fd, CurveAioContext* aioctx) { +int AioDiscard(int fd, CurveAioContext *aioctx) { if (globalclient == nullptr) { LOG(ERROR) << "Not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -886,98 +880,96 @@ int AioDiscard(int fd, CurveAioContext* aioctx) { return globalclient->AioDiscard(fd, aioctx); } -int Create(const char* filename, const C_UserInfo_t* userinfo, size_t size) { +int Create(const char *filename, const C_UserInfo_t *userinfo, size_t size) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } - return globalclient->Create(filename, - UserInfo(userinfo->owner, userinfo->password), size); + return globalclient->Create( + filename, UserInfo(userinfo->owner, userinfo->password), size); } -int Create2(const char* filename, const C_UserInfo_t* userinfo, size_t size, - uint64_t stripeUnit, uint64_t stripeCount) { +int Create2(const char *filename, const C_UserInfo_t *userinfo, size_t size, + uint64_t stripeUnit, uint64_t stripeCount) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Create2(filename, - UserInfo(userinfo->owner, userinfo->password), - size, stripeUnit, stripeCount); + UserInfo(userinfo->owner, userinfo->password), + size, stripeUnit, stripeCount); } -int Rename(const C_UserInfo_t* userinfo, - const char* oldpath, const char* newpath) { +int Rename(const C_UserInfo_t *userinfo, const char *oldpath, + const char *newpath) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Rename(UserInfo(userinfo->owner, userinfo->password), - oldpath, newpath); + oldpath, newpath); } -int Extend(const char* filename, - const C_UserInfo_t* userinfo, uint64_t newsize) { +int Extend(const char *filename, const C_UserInfo_t *userinfo, + uint64_t newsize) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } - return globalclient->Extend(filename, - UserInfo(userinfo->owner, userinfo->password), newsize); + return globalclient->Extend( + filename, UserInfo(userinfo->owner, userinfo->password), newsize); } -int Unlink(const char* filename, const C_UserInfo_t* userinfo) { +int Unlink(const char *filename, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Unlink(filename, - UserInfo(userinfo->owner, userinfo->password)); + UserInfo(userinfo->owner, userinfo->password)); } -int DeleteForce(const char* filename, const C_UserInfo_t* userinfo) { +int DeleteForce(const char *filename, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } - return globalclient->Unlink(filename, - UserInfo(userinfo->owner, userinfo->password), - true); + return globalclient->Unlink( + filename, UserInfo(userinfo->owner, userinfo->password), true); } -int Recover(const char* filename, const C_UserInfo_t* userinfo, - uint64_t fileId) { +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); + return globalclient->Recover( + filename, UserInfo(userinfo->owner, userinfo->password), fileId); } -DirInfo_t* OpenDir(const char* dirpath, const C_UserInfo_t* userinfo) { +DirInfo_t *OpenDir(const char *dirpath, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return nullptr; } - DirInfo_t* dirinfo = new (std::nothrow) DirInfo_t; - dirinfo->dirpath = const_cast(dirpath); - dirinfo->userinfo = const_cast(userinfo); + DirInfo_t *dirinfo = new (std::nothrow) DirInfo_t; + dirinfo->dirpath = const_cast(dirpath); + dirinfo->userinfo = const_cast(userinfo); dirinfo->fileStat = nullptr; return dirinfo; } -int Listdir(DirInfo_t* dirinfo) { +int Listdir(DirInfo_t *dirinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -989,9 +981,10 @@ int Listdir(DirInfo_t* dirinfo) { } std::vector fileStat; - int ret = globalclient->Listdir(dirinfo->dirpath, - UserInfo(dirinfo->userinfo->owner, dirinfo->userinfo->password), - &fileStat); + int ret = globalclient->Listdir( + dirinfo->dirpath, + UserInfo(dirinfo->userinfo->owner, dirinfo->userinfo->password), + &fileStat); dirinfo->dirSize = fileStat.size(); dirinfo->fileStat = new (std::nothrow) FileStatInfo_t[dirinfo->dirSize]; @@ -1011,13 +1004,13 @@ int Listdir(DirInfo_t* dirinfo) { memcpy(dirinfo->fileStat[i].owner, fileStat[i].owner, NAME_MAX_SIZE); memset(dirinfo->fileStat[i].filename, 0, NAME_MAX_SIZE); memcpy(dirinfo->fileStat[i].filename, fileStat[i].filename, - NAME_MAX_SIZE); + NAME_MAX_SIZE); } return ret; } -void CloseDir(DirInfo_t* dirinfo) { +void CloseDir(DirInfo_t *dirinfo) { if (dirinfo != nullptr) { if (dirinfo->fileStat != nullptr) { delete[] dirinfo->fileStat; @@ -1027,24 +1020,24 @@ void CloseDir(DirInfo_t* dirinfo) { } } -int Mkdir(const char* dirpath, const C_UserInfo_t* userinfo) { +int Mkdir(const char *dirpath, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Mkdir(dirpath, - UserInfo(userinfo->owner, userinfo->password)); + UserInfo(userinfo->owner, userinfo->password)); } -int Rmdir(const char* dirpath, const C_UserInfo_t* userinfo) { +int Rmdir(const char *dirpath, const C_UserInfo_t *userinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; } return globalclient->Rmdir(dirpath, - UserInfo(userinfo->owner, userinfo->password)); + UserInfo(userinfo->owner, userinfo->password)); } int Close(int fd) { @@ -1056,11 +1049,11 @@ int Close(int fd) { return globalclient->Close(fd); } -int StatFile4Qemu(const char* filename, FileStatInfo* finfo) { +int StatFile4Qemu(const char *filename, FileStatInfo *finfo) { curve::client::UserInfo_t userinfo; std::string realname; - bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename(filename, - &realname, &userinfo.owner); + bool ret = curve::client::ServiceHelper::GetUserInfoFromFilename( + filename, &realname, &userinfo.owner); if (!ret) { LOG(ERROR) << "get user info from filename failed!"; return -LIBCURVE_ERROR::FAILED; @@ -1074,8 +1067,8 @@ int StatFile4Qemu(const char* filename, FileStatInfo* finfo) { return globalclient->StatFile(realname, userinfo, finfo); } -int StatFile(const char* filename, - const C_UserInfo_t* cuserinfo, FileStatInfo* finfo) { +int StatFile(const char *filename, const C_UserInfo_t *cuserinfo, + FileStatInfo *finfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -1085,8 +1078,8 @@ int StatFile(const char* filename, return globalclient->StatFile(filename, userinfo, finfo); } -int ChangeOwner(const char* filename, - const char* newOwner, const C_UserInfo_t* cuserinfo) { +int ChangeOwner(const char *filename, const char *newOwner, + const C_UserInfo_t *cuserinfo) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -1096,11 +1089,9 @@ int ChangeOwner(const char* filename, return globalclient->ChangeOwner(filename, newOwner, userinfo); } -void UnInit() { - GlobalUnInit(); -} +void UnInit() { GlobalUnInit(); } -int GetClusterId(char* buf, int len) { +int GetClusterId(char *buf, int len) { if (globalclient == nullptr) { LOG(ERROR) << "not inited!"; return -LIBCURVE_ERROR::FAILED; @@ -1109,7 +1100,7 @@ int GetClusterId(char* buf, int len) { return globalclient->GetClusterId(buf, len); } -int GlobalInit(const char* path) { +int GlobalInit(const char *path) { int ret = 0; if (globalclientinited_) { LOG(INFO) << "global cient already inited!"; @@ -1146,74 +1137,74 @@ void GlobalUnInit() { } } -const char* LibCurveErrorName(LIBCURVE_ERROR err) { +const char *LibCurveErrorName(LIBCURVE_ERROR err) { switch (err) { - case LIBCURVE_ERROR::OK: - return "OK"; - case LIBCURVE_ERROR::EXISTS: - return "EXISTS"; - case LIBCURVE_ERROR::FAILED: - return "FAILED"; - case LIBCURVE_ERROR::DISABLEIO: - return "DISABLEIO"; - case LIBCURVE_ERROR::AUTHFAIL: - return "AUTHFAIL"; - case LIBCURVE_ERROR::DELETING: - return "DELETING"; - case LIBCURVE_ERROR::NOTEXIST: - return "NOTEXIST"; - case LIBCURVE_ERROR::UNDER_SNAPSHOT: - return "UNDER_SNAPSHOT"; - case LIBCURVE_ERROR::NOT_UNDERSNAPSHOT: - return "NOT_UNDERSNAPSHOT"; - case LIBCURVE_ERROR::DELETE_ERROR: - return "DELETE_ERROR"; - case LIBCURVE_ERROR::NOT_ALLOCATE: - return "NOT_ALLOCATE"; - case LIBCURVE_ERROR::NOT_SUPPORT: - return "NOT_SUPPORT"; - case LIBCURVE_ERROR::NOT_EMPTY: - return "NOT_EMPTY"; - case LIBCURVE_ERROR::NO_SHRINK_BIGGER_FILE: - return "NO_SHRINK_BIGGER_FILE"; - case LIBCURVE_ERROR::SESSION_NOTEXISTS: - return "SESSION_NOTEXISTS"; - case LIBCURVE_ERROR::FILE_OCCUPIED: - return "FILE_OCCUPIED"; - case LIBCURVE_ERROR::PARAM_ERROR: - return "PARAM_ERROR"; - case LIBCURVE_ERROR::INTERNAL_ERROR: - return "INTERNAL_ERROR"; - case LIBCURVE_ERROR::CRC_ERROR: - return "CRC_ERROR"; - case LIBCURVE_ERROR::INVALID_REQUEST: - return "INVALID_REQUEST"; - case LIBCURVE_ERROR::DISK_FAIL: - return "DISK_FAIL"; - case LIBCURVE_ERROR::NO_SPACE: - return "NO_SPACE"; - case LIBCURVE_ERROR::NOT_ALIGNED: - return "NOT_ALIGNED"; - case LIBCURVE_ERROR::BAD_FD: - return "BAD_FD"; - case LIBCURVE_ERROR::LENGTH_NOT_SUPPORT: - return "LENGTH_NOT_SUPPORT"; - case LIBCURVE_ERROR::SESSION_NOT_EXIST: - return "SESSION_NOT_EXIST"; - case LIBCURVE_ERROR::STATUS_NOT_MATCH: - return "STATUS_NOT_MATCH"; - case LIBCURVE_ERROR::DELETE_BEING_CLONED: - return "DELETE_BEING_CLONED"; - case LIBCURVE_ERROR::CLIENT_NOT_SUPPORT_SNAPSHOT: - return "CLIENT_NOT_SUPPORT_SNAPSHOT"; - case LIBCURVE_ERROR::SNAPSTHO_FROZEN: - return "SNAPSTHO_FROZEN"; - case LIBCURVE_ERROR::RETRY_UNTIL_SUCCESS: - return "RETRY_UNTIL_SUCCESS"; - case LIBCURVE_ERROR::EPOCH_TOO_OLD: - return "EPOCH_TOO_OLD"; - case LIBCURVE_ERROR::UNKNOWN: - break; + case LIBCURVE_ERROR::OK: + return " OK"; + case LIBCURVE_ERROR::EXISTS: + return " EXISTS"; + case LIBCURVE_ERROR::FAILED: + return " FAILED"; + case LIBCURVE_ERROR::DISABLEIO: + return " DISABLEIO"; + case LIBCURVE_ERROR::AUTHFAIL: + return " AUTHFAIL"; + case LIBCURVE_ERROR::DELETING: + return " DELETING"; + case LIBCURVE_ERROR::NOTEXIST: + return " NOTEXIST"; + case LIBCURVE_ERROR::UNDER_SNAPSHOT: + return " UNDER_SNAPSHOT"; + case LIBCURVE_ERROR::NOT_UNDERSNAPSHOT: + return " NOT_UNDERSNAPSHOT"; + case LIBCURVE_ERROR::DELETE_ERROR: + return " DELETE_ERROR"; + case LIBCURVE_ERROR::NOT_ALLOCATE: + return " NOT_ALLOCATE"; + case LIBCURVE_ERROR::NOT_SUPPORT: + return " NOT_SUPPORT"; + case LIBCURVE_ERROR::NOT_EMPTY: + return " NOT_EMPTY"; + case LIBCURVE_ERROR::NO_SHRINK_BIGGER_FILE: + return " NO_SHRINK_BIGGER_FILE"; + case LIBCURVE_ERROR::SESSION_NOTEXISTS: + return " SESSION_NOTEXISTS"; + case LIBCURVE_ERROR::FILE_OCCUPIED: + return " FILE_OCCUPIED"; + case LIBCURVE_ERROR::PARAM_ERROR: + return " PARAM_ERROR"; + case LIBCURVE_ERROR::INTERNAL_ERROR: + return " INTERNAL_ERROR"; + case LIBCURVE_ERROR::CRC_ERROR: + return " CRC_ERROR"; + case LIBCURVE_ERROR::INVALID_REQUEST: + return " INVALID_REQUEST"; + case LIBCURVE_ERROR::DISK_FAIL: + return " DISK_FAIL"; + case LIBCURVE_ERROR::NO_SPACE: + return " NO_SPACE"; + case LIBCURVE_ERROR::NOT_ALIGNED: + return " NOT_ALIGNED"; + case LIBCURVE_ERROR::BAD_FD: + return " BAD_FD"; + case LIBCURVE_ERROR::LENGTH_NOT_SUPPORT: + return " LENGTH_NOT_SUPPORT"; + case LIBCURVE_ERROR::SESSION_NOT_EXIST: + return " SESSION_NOT_EXIST"; + case LIBCURVE_ERROR::STATUS_NOT_MATCH: + return " STATUS_NOT_MATCH"; + case LIBCURVE_ERROR::DELETE_BEING_CLONED: + return " DELETE_BEING_CLONED"; + case LIBCURVE_ERROR::CLIENT_NOT_SUPPORT_SNAPSHOT: + return " CLIENT_NOT_SUPPORT_SNAPSHOT"; + case LIBCURVE_ERROR::SNAPSTHO_FROZEN: + return " SNAPSTHO_FROZEN"; + case LIBCURVE_ERROR::RETRY_UNTIL_SUCCESS: + return " RETRY_UNTIL_SUCCESS"; + case LIBCURVE_ERROR::EPOCH_TOO_OLD: + return " EPOCH_TOO_OLD"; + case LIBCURVE_ERROR::UNKNOWN: + break; } static thread_local char message[64]; diff --git a/src/client/libcurve_snapshot.cpp b/src/client/libcurve_snapshot.cpp index 2e76b60411..b5f3fa8320 100644 --- a/src/client/libcurve_snapshot.cpp +++ b/src/client/libcurve_snapshot.cpp @@ -133,7 +133,8 @@ int SnapshotClient::GetSnapshotSegmentInfo(const std::string &filename, segInfo); if (ret != LIBCURVE_ERROR::OK) { - LOG(WARNING) << "GetSnapshotSegmentInfo failed, ret = " << ret; + LOG(WARNING) << "GetSnapshotSegmentInfo failed, ret = " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); return -ret; } @@ -179,19 +180,20 @@ int SnapshotClient::CreateCloneFile(const std::string &source, int SnapshotClient::GetFileInfo(const std::string &filename, const UserInfo_t &userinfo, FInfo *fileInfo) { FileEpoch_t fEpoch; - LIBCURVE_ERROR ret = mdsclient_.GetFileInfo(filename, userinfo, - fileInfo, &fEpoch); + LIBCURVE_ERROR ret = + mdsclient_.GetFileInfo(filename, userinfo, fileInfo, &fEpoch); return -ret; } int SnapshotClient::GetOrAllocateSegmentInfo(bool allocate, uint64_t offset, const FInfo_t *fi, SegmentInfo *segInfo) { - int ret = mdsclient_.GetOrAllocateSegment( - allocate, offset, fi, nullptr, segInfo); + int ret = + mdsclient_.GetOrAllocateSegment(allocate, offset, fi, nullptr, segInfo); if (ret != LIBCURVE_ERROR::OK) { - LOG(INFO) << "GetSnapshotSegmentInfo failed, ret = " << ret; + LOG(INFO) << "GetSnapshotSegmentInfo failed, ret = " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); return -ret; } diff --git a/src/client/mds_client.cpp b/src/client/mds_client.cpp index 87a3b4b767..2a02ebf2b3 100644 --- a/src/client/mds_client.cpp +++ b/src/client/mds_client.cpp @@ -35,6 +35,7 @@ namespace curve { namespace client { +using curve::common::ChunkServerLocation; using curve::common::NetCommon; using curve::common::TimeUtility; using curve::mds::FileInfo; @@ -42,7 +43,6 @@ using curve::mds::PageFileChunkInfo; using curve::mds::PageFileSegment; using curve::mds::ProtoSession; using curve::mds::StatusCode; -using curve::common::ChunkServerLocation; using curve::mds::topology::CopySetServerInfo; // rpc发送和mds地址切换状态机 @@ -236,9 +236,7 @@ LIBCURVE_ERROR MDSClient::Initialize(const MetaServerOption &metaServerOpt) { } -void MDSClient::UnInitialize() { - inited_ = false; -} +void MDSClient::UnInitialize() { inited_ = false; } #define RPCTaskDefine \ [&](int addrindex, uint64_t rpctimeoutMS, brpc::Channel *channel, \ @@ -246,8 +244,7 @@ void MDSClient::UnInitialize() { LIBCURVE_ERROR MDSClient::OpenFile(const std::string &filename, const UserInfo_t &userinfo, FInfo_t *fi, - FileEpoch_t *fEpoch, - LeaseSession *lease) { + FileEpoch_t *fEpoch, LeaseSession *lease) { auto task = RPCTaskDefine { OpenFileResponse response; mdsClientMetric_.openFile.qps.count << 1; @@ -269,7 +266,8 @@ LIBCURVE_ERROR MDSClient::OpenFile(const std::string &filename, << "OpenFile: filename = " << filename << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); bool flag = response.has_protosession() && response.has_fileinfo(); if (flag) { @@ -335,7 +333,8 @@ LIBCURVE_ERROR MDSClient::CreateFile(const std::string &filename, << ", owner = " << userinfo.owner << ", is nomalfile: " << normalFile << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -369,7 +368,8 @@ LIBCURVE_ERROR MDSClient::CloseFile(const std::string &filename, << ", owner = " << userinfo.owner << ", sessionid = " << sessionid << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -403,24 +403,23 @@ LIBCURVE_ERROR MDSClient::GetFileInfo(const std::string &filename, << "GetFileInfo: filename = " << filename << ", owner = " << uinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( rpcExcutor_.DoRPCTask(task, metaServerOpt_.mdsMaxRetryMS)); } -LIBCURVE_ERROR MDSClient::IncreaseEpoch(const std::string& filename, - const UserInfo_t& userinfo, - FInfo_t* fi, - FileEpoch_t *fEpoch, - std::list> *csLocs) { +LIBCURVE_ERROR MDSClient::IncreaseEpoch( + const std::string &filename, const UserInfo_t &userinfo, FInfo_t *fi, + FileEpoch_t *fEpoch, std::list> *csLocs) { auto task = RPCTaskDefine { IncreaseFileEpochResponse response; mdsClientMetric_.increaseEpoch.qps.count << 1; LatencyGuard lg(&mdsClientMetric_.increaseEpoch.latency); - MDSClientBase::IncreaseEpoch( - filename, userinfo, &response, cntl, channel); + MDSClientBase::IncreaseEpoch(filename, userinfo, &response, cntl, + channel); if (cntl->Failed()) { mdsClientMetric_.increaseEpoch.eps.count << 1; @@ -432,10 +431,11 @@ LIBCURVE_ERROR MDSClient::IncreaseEpoch(const std::string& filename, LIBCURVE_ERROR retcode; MDSStatusCode2LibcurveError(stcode, &retcode); LOG(ERROR) << "IncreaseEpoch: filename = " << filename - << ", owner = " << userinfo.owner - << ", errocde = " << retcode - << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", owner = " << userinfo.owner + << ", errocde = " << retcode + << ", error msg = " << StatusCode_Name(stcode) + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; } @@ -453,11 +453,11 @@ LIBCURVE_ERROR MDSClient::IncreaseEpoch(const std::string& filename, csinfo.peerID = response.cslocs(i).chunkserverid(); EndPoint internal; butil::str2endpoint(response.cslocs(i).hostip().c_str(), - response.cslocs(i).port(), &internal); + response.cslocs(i).port(), &internal); EndPoint external; if (response.cslocs(i).has_externalip()) { butil::str2endpoint(response.cslocs(i).externalip().c_str(), - response.cslocs(i).port(), &external); + response.cslocs(i).port(), &external); } csinfo.internalAddr = PeerAddr(internal); csinfo.externalAddr = PeerAddr(external); @@ -470,9 +470,9 @@ LIBCURVE_ERROR MDSClient::IncreaseEpoch(const std::string& filename, rpcExcutor_.DoRPCTask(task, metaServerOpt_.mdsMaxRetryMS)); } -LIBCURVE_ERROR MDSClient::CreateSnapShot(const std::string& filename, - const UserInfo_t& userinfo, - uint64_t* seq) { +LIBCURVE_ERROR MDSClient::CreateSnapShot(const std::string &filename, + const UserInfo_t &userinfo, + uint64_t *seq) { auto task = RPCTaskDefine { CreateSnapShotResponse response; MDSClientBase::CreateSnapShot(filename, userinfo, &response, cntl, @@ -494,8 +494,8 @@ LIBCURVE_ERROR MDSClient::CreateSnapShot(const std::string& filename, hasinfo) { FInfo_t *fi = new (std::nothrow) FInfo_t; FileEpoch_t fEpoch; - ServiceHelper::ProtoFileInfo2Local(response.snapshotfileinfo(), - fi, &fEpoch); + ServiceHelper::ProtoFileInfo2Local(response.snapshotfileinfo(), fi, + &fEpoch); *seq = fi->seqnum; delete fi; if (stcode == StatusCode::kOK) { @@ -511,8 +511,8 @@ LIBCURVE_ERROR MDSClient::CreateSnapShot(const std::string& filename, if (hasinfo) { FInfo_t fi; FileEpoch_t fEpoch; - ServiceHelper::ProtoFileInfo2Local(response.snapshotfileinfo(), - &fi, &fEpoch); // NOLINT + ServiceHelper::ProtoFileInfo2Local(response.snapshotfileinfo(), &fi, + &fEpoch); // NOLINT *seq = fi.seqnum; } @@ -522,7 +522,8 @@ LIBCURVE_ERROR MDSClient::CreateSnapShot(const std::string& filename, << "CreateSnapShot: filename = " << filename << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -553,7 +554,8 @@ LIBCURVE_ERROR MDSClient::DeleteSnapShot(const std::string &filename, << ", owner = " << userinfo.owner << ", seqnum = " << seq << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -583,7 +585,8 @@ LIBCURVE_ERROR MDSClient::ListSnapShot(const std::string &filename, LOG_IF(WARNING, retcode != LIBCURVE_ERROR::OK) << "ListSnapShot: filename = " << filename << ", owner = " << userinfo.owner << ", errocde = " << retcode - << ", error msg = " << StatusCode_Name(stcode); + << ", error msg = " << StatusCode_Name(stcode) + << LibCurveErrorName((LIBCURVE_ERROR)retcode); if (stcode == StatusCode::kOwnerAuthFail) { return LIBCURVE_ERROR::AUTHFAIL; @@ -592,8 +595,8 @@ LIBCURVE_ERROR MDSClient::ListSnapShot(const std::string &filename, for (int i = 0; i < response.fileinfo_size(); i++) { FInfo_t tempInfo; FileEpoch_t fEpoch; - ServiceHelper::ProtoFileInfo2Local(response.fileinfo(i), - &tempInfo, &fEpoch); + ServiceHelper::ProtoFileInfo2Local(response.fileinfo(i), &tempInfo, + &fEpoch); snapif->insert(std::make_pair(tempInfo.seqnum, tempInfo)); } @@ -630,7 +633,8 @@ LIBCURVE_ERROR MDSClient::GetSnapshotSegmentInfo(const std::string &filename, << "GetSnapshotSegmentInfo: filename = " << filename << ", owner = " << userinfo.owner << ", offset = " << offset << ", seqnum = " << seq << ", errocde = " << retcode - << ", error msg = " << StatusCode_Name(stcode); + << ", error msg = " << StatusCode_Name(stcode) + << LibCurveErrorName((LIBCURVE_ERROR)retcode); if (stcode != StatusCode::kOK) { LOG(WARNING) << "GetSnapshotSegmentInfo return error, " @@ -716,8 +720,7 @@ LIBCURVE_ERROR MDSClient::RefreshSession(const std::string &filename, if (response.has_fileinfo()) { FileEpoch_t fEpoch; ServiceHelper::ProtoFileInfo2Local(response.fileinfo(), - &resp->finfo, - &fEpoch); + &resp->finfo, &fEpoch); resp->status = LeaseRefreshResult::Status::OK; } else { LOG(WARNING) << "session response has no fileinfo!"; @@ -773,7 +776,8 @@ LIBCURVE_ERROR MDSClient::CheckSnapShotStatus(const std::string &filename, << "CheckSnapShotStatus: filename = " << filename << ", owner = " << userinfo.owner << ", seqnum = " << seq << ", errocde = " << retcode - << ", error msg = " << StatusCode_Name(stcode); + << ", error msg = " << StatusCode_Name(stcode) + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -896,12 +900,13 @@ LIBCURVE_ERROR MDSClient::CreateCloneFile( << ", size = " << size << ", chunksize = " << chunksize << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); if (stcode == StatusCode::kOK) { FileEpoch_t fEpoch; - ServiceHelper::ProtoFileInfo2Local(response.fileinfo(), - fileinfo, &fEpoch); + ServiceHelper::ProtoFileInfo2Local(response.fileinfo(), fileinfo, + &fEpoch); fileinfo->sourceInfo.name = response.fileinfo().clonesource(); fileinfo->sourceInfo.length = response.fileinfo().clonelength(); } @@ -948,7 +953,8 @@ LIBCURVE_ERROR MDSClient::SetCloneFileStatus(const std::string &filename, << ", filestatus = " << static_cast(filestatus) << ", fileID = " << fileID << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -1086,7 +1092,8 @@ LIBCURVE_ERROR MDSClient::RenameFile(const UserInfo_t &userinfo, << ", destinationId = " << destinationId << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); // MDS does not currently support rename file, retry again if (retcode == LIBCURVE_ERROR::NOT_SUPPORT) { @@ -1124,7 +1131,8 @@ LIBCURVE_ERROR MDSClient::Extend(const std::string &filename, << ", owner = " << userinfo.owner << ", newsize = " << newsize << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -1156,7 +1164,8 @@ LIBCURVE_ERROR MDSClient::DeleteFile(const std::string &filename, << "DeleteFile: filename = " << filename << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); // MDS does not currently support delete file, retry again if (retcode == LIBCURVE_ERROR::NOT_SUPPORT) { @@ -1194,7 +1203,8 @@ LIBCURVE_ERROR MDSClient::RecoverFile(const std::string &filename, << "RecoverFile: filename = " << filename << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); return retcode; }; return ReturnError( @@ -1227,7 +1237,8 @@ LIBCURVE_ERROR MDSClient::ChangeOwner(const std::string &filename, << ", owner = " << userinfo.owner << ", new owner = " << newOwner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); // MDS does not currently support change file owner, retry again if (retcode == LIBCURVE_ERROR::NOT_SUPPORT) { @@ -1265,7 +1276,8 @@ LIBCURVE_ERROR MDSClient::Listdir(const std::string &dirpath, << "Listdir: filename = " << dirpath << ", owner = " << userinfo.owner << ", errocde = " << retcode << ", error msg = " << StatusCode_Name(stcode) - << ", log id = " << cntl->log_id(); + << ", log id = " << cntl->log_id() + << LibCurveErrorName((LIBCURVE_ERROR)retcode); if (retcode == LIBCURVE_ERROR::OK) { int fileinfoNum = response.fileinfo_size(); @@ -1291,8 +1303,9 @@ LIBCURVE_ERROR MDSClient::Listdir(const std::string &dirpath, rpcExcutor_.DoRPCTask(task, metaServerOpt_.mdsMaxRetryMS)); } -LIBCURVE_ERROR MDSClient::GetChunkServerInfo(const PeerAddr &csAddr, - CopysetPeerInfo *chunkserverInfo) { +LIBCURVE_ERROR +MDSClient::GetChunkServerInfo(const PeerAddr &csAddr, + CopysetPeerInfo *chunkserverInfo) { if (!chunkserverInfo) { LOG(ERROR) << "chunkserverInfo pointer is null!"; return LIBCURVE_ERROR::FAILED; @@ -1350,9 +1363,8 @@ LIBCURVE_ERROR MDSClient::GetChunkServerInfo(const PeerAddr &csAddr, butil::str2endpoint(internalIp.c_str(), port, &internal); EndPoint external; butil::str2endpoint(externalIp.c_str(), port, &external); - *chunkserverInfo = - CopysetPeerInfo(csId, PeerAddr(internal), - PeerAddr(external)); + *chunkserverInfo = CopysetPeerInfo( + csId, PeerAddr(internal), PeerAddr(external)); return LIBCURVE_ERROR::OK; } else { return LIBCURVE_ERROR::FAILED; diff --git a/src/client/source_reader.cpp b/src/client/source_reader.cpp index 66af6a922d..d0043ad384 100644 --- a/src/client/source_reader.cpp +++ b/src/client/source_reader.cpp @@ -175,7 +175,8 @@ int SourceReader::Read(const std::vector& reqCtxVec, UserDataType::IOBuffer); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "Read curve failed failed, filename = " << fileName - << ", error = " << ret; + << ", error = " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); delete curveCombineCtx; return -1; } else { diff --git a/src/snapshotcloneserver/clone/clone_core.cpp b/src/snapshotcloneserver/clone/clone_core.cpp index e2843f6cd9..309d19d091 100644 --- a/src/snapshotcloneserver/clone/clone_core.cpp +++ b/src/snapshotcloneserver/clone/clone_core.cpp @@ -32,31 +32,30 @@ #include "src/common/uuid.h" #include "src/common/concurrent/name_lock.h" -using ::curve::common::UUIDGenerator; using ::curve::common::LocationOperator; using ::curve::common::NameLock; using ::curve::common::NameLockGuard; +using ::curve::common::UUIDGenerator; namespace curve { namespace snapshotcloneserver { int CloneCoreImpl::Init() { int ret = client_->Mkdir(cloneTempDir_, mdsRootUser_); - if (ret != LIBCURVE_ERROR::OK && - ret != -LIBCURVE_ERROR::EXISTS) { + if (ret != LIBCURVE_ERROR::OK && ret != -LIBCURVE_ERROR::EXISTS) { LOG(ERROR) << "Mkdir fail, ret = " << ret - << ", dirpath = " << cloneTempDir_; + << ", dirpath = " << cloneTempDir_ + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeServerInitFail; } return kErrCodeSuccess; } int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, - const std::string &user, - const std::string &destination, - bool lazyFlag, - CloneTaskType taskType, - CloneInfo *cloneInfo) { + const std::string &user, + const std::string &destination, + bool lazyFlag, CloneTaskType taskType, + CloneInfo *cloneInfo) { // 查询数据库中是否有任务正在执行 std::vector cloneInfoList; metaStore_->GetCloneInfoByFileName(destination, &cloneInfoList); @@ -64,16 +63,14 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, std::vector existCloneInfos; for (auto &info : cloneInfoList) { LOG(INFO) << "CloneOrRecoverPre find same clone task" - << ", source = " << source - << ", user = " << user + << ", source = " << source << ", user = " << user << ", destination = " << destination << ", Exist CloneInfo : " << info; // is clone if (taskType == CloneTaskType::kClone) { if (info.GetStatus() == CloneStatus::cloning || info.GetStatus() == CloneStatus::retrying) { - if ((info.GetUser() == user) && - (info.GetSrc() == source) && + if ((info.GetUser() == user) && (info.GetSrc() == source) && (info.GetIsLazy() == lazyFlag) && (info.GetTaskType() == taskType)) { // 视为同一个clone @@ -97,8 +94,7 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, } else { // is recover if (info.GetStatus() == CloneStatus::recovering || info.GetStatus() == CloneStatus::retrying) { - if ((info.GetUser() == user) && - (info.GetSrc() == source) && + if ((info.GetUser() == user) && (info.GetSrc() == source) && (info.GetIsLazy() == lazyFlag) && (info.GetTaskType() == taskType)) { // 视为同一个clone,返回任务已存在 @@ -123,58 +119,54 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, FInfo destFInfo; int ret = client_->GetFileInfo(destination, mdsRootUser_, &destFInfo); switch (ret) { - case LIBCURVE_ERROR::OK: - if (CloneTaskType::kClone == taskType) { - if (needJudgeFileExist) { - bool match = false; - // 找出inodeid匹配的cloneInfo - for (auto& existInfo : existCloneInfos) { - if (destFInfo.id == existInfo.GetDestId()) { - *cloneInfo = existInfo; - match = true; - break; - } - } - if (match) { - return kErrCodeTaskExist; - } else { - // 如果没找到,那么dest file都不是这些clone任务创建的, - // 意味着文件重名了 - LOG(ERROR) << "Clone dest file exist, " - << "but task not match! " - << "source = " << source - << ", user = " << user - << ", destination = " << destination; - return kErrCodeFileExist; + case LIBCURVE_ERROR::OK: + if (CloneTaskType::kClone == taskType) { + if (needJudgeFileExist) { + bool match = false; + // 找出inodeid匹配的cloneInfo + for (auto &existInfo : existCloneInfos) { + if (destFInfo.id == existInfo.GetDestId()) { + *cloneInfo = existInfo; + match = true; + break; } + } + if (match) { + return kErrCodeTaskExist; } else { - // 没有对应的cloneInfo,意味着文件重名了 - LOG(ERROR) << "Clone dest file must not exist" - << ", source = " << source - << ", user = " << user + // 如果没找到,那么dest file都不是这些clone任务创建的, + // 意味着文件重名了 + LOG(ERROR) << "Clone dest file exist, " + << "but task not match! " + << "source = " << source << ", user = " << user << ", destination = " << destination; return kErrCodeFileExist; } - } - break; - case -LIBCURVE_ERROR::NOTEXIST: - if (CloneTaskType::kRecover == taskType) { - LOG(ERROR) << "Recover dest file must exist" - << ", source = " << source - << ", user = " << user + } else { + // 没有对应的cloneInfo,意味着文件重名了 + LOG(ERROR) << "Clone dest file must not exist" + << ", source = " << source << ", user = " << user << ", destination = " << destination; - return kErrCodeFileNotExist; + return kErrCodeFileExist; } - break; - default: - LOG(ERROR) << "GetFileInfo encounter an error" - << ", ret = " << ret - << ", source = " << source - << ", user = " << user; - return kErrCodeInternalError; + } + break; + case -LIBCURVE_ERROR::NOTEXIST: + if (CloneTaskType::kRecover == taskType) { + LOG(ERROR) << "Recover dest file must exist" + << ", source = " << source << ", user = " << user + << ", destination = " << destination; + return kErrCodeFileNotExist; + } + break; + default: + LOG(ERROR) << "GetFileInfo encounter an error" + << ", ret = " << ret << ", source = " << source + << ", user = " << user; + return kErrCodeInternalError; } - //是否为快照 + // 是否为快照 SnapshotInfo snapInfo; CloneFileType fileType; @@ -195,8 +187,7 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, } if (snapInfo.GetUser() != user) { LOG(ERROR) << "Clone snapshot by invalid user" - << ", source = " << source - << ", user = " << user + << ", source = " << source << ", user = " << user << ", destination = " << destination << ", snapshot.user = " << snapInfo.GetUser(); return kErrCodeInvalidUser; @@ -209,22 +200,21 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, FInfo fInfo; ret = client_->GetFileInfo(source, mdsRootUser_, &fInfo); switch (ret) { - case LIBCURVE_ERROR::OK: - fileType = CloneFileType::kFile; - break; - case -LIBCURVE_ERROR::NOTEXIST: - case -LIBCURVE_ERROR::PARAM_ERROR: - LOG(ERROR) << "Clone source file not exist" - << ", source = " << source - << ", user = " << user - << ", destination = " << destination; - return kErrCodeFileNotExist; - default: - LOG(ERROR) << "GetFileInfo encounter an error" - << ", ret = " << ret - << ", source = " << source - << ", user = " << user; - return kErrCodeInternalError; + case LIBCURVE_ERROR::OK: + fileType = CloneFileType::kFile; + break; + case -LIBCURVE_ERROR::NOTEXIST: + case -LIBCURVE_ERROR::PARAM_ERROR: + LOG(ERROR) << "Clone source file not exist" + << ", source = " << source << ", user = " << user + << ", destination = " << destination; + return kErrCodeFileNotExist; + default: + LOG(ERROR) << "GetFileInfo encounter an error" + << ", ret = " << ret << ", source = " << source + << ", user = " << user + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeInternalError; } if (fInfo.filestatus != FileStatus::Created && fInfo.filestatus != FileStatus::Cloned && @@ -238,8 +228,8 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, } UUID uuid = UUIDGenerator().GenerateUUID(); - CloneInfo info(uuid, user, taskType, - source, destination, fileType, lazyFlag); + CloneInfo info(uuid, user, taskType, source, destination, fileType, + lazyFlag); if (CloneTaskType::kClone == taskType) { info.SetStatus(CloneStatus::cloning); } else { @@ -251,11 +241,11 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, ret = metaStore_->AddCloneInfo(info); if (ret < 0) { LOG(ERROR) << "AddCloneInfo error" - << ", ret = " << ret - << ", taskId = " << uuid - << ", user = " << user - << ", source = " << source - << ", destination = " << destination; + << ", ret = " << ret << ", taskId = " << uuid + << ", user = " << user << ", source = " << source + << ", destination = " << destination + << LibCurveErrorName((LIBCURVE_ERROR)ret); + if (CloneFileType::kSnapshot == fileType) { snapshotRef_->DecrementSnapshotRef(source); } @@ -263,9 +253,8 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, } if (CloneFileType::kFile == fileType) { NameLockGuard lockGuard(cloneRef_->GetLock(), source); - ret = client_->SetCloneFileStatus(source, - FileStatus::BeingCloned, - mdsRootUser_); + ret = client_->SetCloneFileStatus(source, FileStatus::BeingCloned, + mdsRootUser_); if (ret < 0) { // 这里不处理SetCloneFileStatus的错误, // 因为SetCloneFileStatus失败的所有结果都是可接受的, @@ -275,9 +264,9 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, // 重启服务将造成Clone继续进行, // 跟用户结果返回的结果不一致,造成用户的困惑 LOG(WARNING) << "SetCloneFileStatus encounter an error" - << ", ret = " << ret - << ", source = " << source - << ", user = " << user; + << ", ret = " << ret << ", source = " << source + << ", user = " << user + << LibCurveErrorName((LIBCURVE_ERROR)ret); } cloneRef_->IncrementRef(source); } @@ -286,44 +275,42 @@ int CloneCoreImpl::CloneOrRecoverPre(const UUID &source, return kErrCodeSuccess; } -int CloneCoreImpl::FlattenPre( - const std::string &user, - const TaskIdType &taskId, - CloneInfo *cloneInfo) { +int CloneCoreImpl::FlattenPre(const std::string &user, const TaskIdType &taskId, + CloneInfo *cloneInfo) { int ret = metaStore_->GetCloneInfo(taskId, cloneInfo); if (ret < 0) { return kErrCodeFileNotExist; } switch (cloneInfo->GetStatus()) { - case CloneStatus::done: - case CloneStatus::cloning: - case CloneStatus::recovering: { - // 已经完成的或正在进行中返回task exist, 表示不需要处理 - return kErrCodeTaskExist; - } - case CloneStatus::metaInstalled: { - if (CloneTaskType::kClone == cloneInfo->GetTaskType()) { - cloneInfo->SetStatus(CloneStatus::cloning); - } else { - cloneInfo->SetStatus(CloneStatus::recovering); - } - break; - } - case CloneStatus::cleaning: - case CloneStatus::errorCleaning: - case CloneStatus::error: - default: { - LOG(ERROR) << "FlattenPre find clone task status Invalid" - << ", status = " - << static_cast(cloneInfo->GetStatus()); - return kErrCodeFileStatusInvalid; + case CloneStatus::done: + case CloneStatus::cloning: + case CloneStatus::recovering: { + // 已经完成的或正在进行中返回task exist, 表示不需要处理 + return kErrCodeTaskExist; + } + case CloneStatus::metaInstalled: { + if (CloneTaskType::kClone == cloneInfo->GetTaskType()) { + cloneInfo->SetStatus(CloneStatus::cloning); + } else { + cloneInfo->SetStatus(CloneStatus::recovering); } + break; + } + case CloneStatus::cleaning: + case CloneStatus::errorCleaning: + case CloneStatus::error: + default: { + LOG(ERROR) << "FlattenPre find clone task status Invalid" + << ", status = " << static_cast(cloneInfo->GetStatus()); + return kErrCodeFileStatusInvalid; + } } ret = metaStore_->UpdateCloneInfo(*cloneInfo); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo fail" << ", ret = " << ret - << ", taskId = " << cloneInfo->GetTaskId(); + << ", taskId = " << cloneInfo->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; @@ -361,75 +348,75 @@ void CloneCoreImpl::HandleCloneOrRecoverTask( CloneStep step = task->GetCloneInfo().GetNextStep(); while (step != CloneStep::kEnd) { switch (step) { - case CloneStep::kCreateCloneFile: - ret = CreateCloneFile(task, newFileInfo); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - task->SetProgress(kProgressCreateCloneFile); - break; - case CloneStep::kCreateCloneMeta: - ret = CreateCloneMeta(task, &newFileInfo, &segInfos); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - task->SetProgress(kProgressCreateCloneMeta); - break; - case CloneStep::kCreateCloneChunk: - ret = CreateCloneChunk(task, newFileInfo, &segInfos); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - break; - case CloneStep::kCompleteCloneMeta: - ret = CompleteCloneMeta(task, newFileInfo, segInfos); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - task->SetProgress(kProgressMetaInstalled); - break; - case CloneStep::kRecoverChunk: - ret = RecoverChunk(task, newFileInfo, segInfos); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - break; - case CloneStep::kChangeOwner: - ret = ChangeOwner(task, newFileInfo); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - break; - case CloneStep::kRenameCloneFile: - ret = RenameCloneFile(task, newFileInfo); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - if (IsLazy(task)) { - HandleLazyCloneStage1Finish(task); - doneGuard.release(); - return; - } - break; - case CloneStep::kCompleteCloneFile: - ret = CompleteCloneFile(task, newFileInfo, segInfos); - if (ret < 0) { - HandleCloneError(task, ret); - return; - } - break; - default: - LOG(ERROR) << "can not reach here" - << ", taskid = " << task->GetTaskId(); + case CloneStep::kCreateCloneFile: + ret = CreateCloneFile(task, newFileInfo); + if (ret < 0) { HandleCloneError(task, ret); return; + } + task->SetProgress(kProgressCreateCloneFile); + break; + case CloneStep::kCreateCloneMeta: + ret = CreateCloneMeta(task, &newFileInfo, &segInfos); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + task->SetProgress(kProgressCreateCloneMeta); + break; + case CloneStep::kCreateCloneChunk: + ret = CreateCloneChunk(task, newFileInfo, &segInfos); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + break; + case CloneStep::kCompleteCloneMeta: + ret = CompleteCloneMeta(task, newFileInfo, segInfos); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + task->SetProgress(kProgressMetaInstalled); + break; + case CloneStep::kRecoverChunk: + ret = RecoverChunk(task, newFileInfo, segInfos); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + break; + case CloneStep::kChangeOwner: + ret = ChangeOwner(task, newFileInfo); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + break; + case CloneStep::kRenameCloneFile: + ret = RenameCloneFile(task, newFileInfo); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + if (IsLazy(task)) { + HandleLazyCloneStage1Finish(task); + doneGuard.release(); + return; + } + break; + case CloneStep::kCompleteCloneFile: + ret = CompleteCloneFile(task, newFileInfo, segInfos); + if (ret < 0) { + HandleCloneError(task, ret); + return; + } + break; + default: + LOG(ERROR) << "can not reach here" + << ", taskid = " << task->GetTaskId(); + HandleCloneError(task, ret); + return; } task->UpdateMetric(); step = task->GetCloneInfo().GetNextStep(); @@ -438,8 +425,7 @@ void CloneCoreImpl::HandleCloneOrRecoverTask( } int CloneCoreImpl::BuildFileInfoFromSnapshot( - std::shared_ptr task, - FInfo *newFileInfo, + std::shared_ptr task, FInfo *newFileInfo, CloneSegmentMap *segInfos) { segInfos->clear(); UUID source = task->GetCloneInfo().GetSrc(); @@ -463,23 +449,23 @@ int CloneCoreImpl::BuildFileInfoFromSnapshot( std::string user = task->GetCloneInfo().GetUser(); ret = client_->GetFileInfo(destination, mdsRootUser_, &fInfo); switch (ret) { - case LIBCURVE_ERROR::OK: - break; - case -LIBCURVE_ERROR::NOTEXIST: - LOG(ERROR) << "BuildFileInfoFromSnapshot " - << "find dest file not exist, maybe deleted" - << ", ret = " << ret - << ", destination = " << destination - << ", user = " << user - << ", taskid = " << task->GetTaskId(); - return kErrCodeFileNotExist; - default: - LOG(ERROR) << "GetFileInfo fail" - << ", ret = " << ret - << ", destination = " << destination - << ", user = " << user - << ", taskid = " << task->GetTaskId(); - return kErrCodeInternalError; + case LIBCURVE_ERROR::OK: + break; + case -LIBCURVE_ERROR::NOTEXIST: + LOG(ERROR) << "BuildFileInfoFromSnapshot " + << "find dest file not exist, maybe deleted" + << ", ret = " << ret << ", destination = " << destination + << ", user = " << user + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeFileNotExist; + default: + LOG(ERROR) << "GetFileInfo fail" + << ", ret = " << ret << ", destination = " << destination + << ", user = " << user + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeInternalError; } // 从快照恢复的destinationId为目标文件的id task->GetCloneInfo().SetDestId(fInfo.id); @@ -490,24 +476,22 @@ int CloneCoreImpl::BuildFileInfoFromSnapshot( } newFileInfo->owner = task->GetCloneInfo().GetUser(); - ChunkIndexDataName indexName(snapInfo.GetFileName(), - snapInfo.GetSeqNum()); + ChunkIndexDataName indexName(snapInfo.GetFileName(), snapInfo.GetSeqNum()); ChunkIndexData snapMeta; ret = dataStore_->GetChunkIndexData(indexName, &snapMeta); if (ret < 0) { - LOG(ERROR) << "GetChunkIndexData error" - << ", fileName = " << snapInfo.GetFileName() - << ", seqNum = " << snapInfo.GetSeqNum() - << ", taskid = " << task->GetTaskId(); - return ret; + LOG(ERROR) << "GetChunkIndexData error" + << ", fileName = " << snapInfo.GetFileName() + << ", seqNum = " << snapInfo.GetSeqNum() + << ", taskid = " << task->GetTaskId(); + return ret; } uint64_t segmentSize = snapInfo.GetSegmentSize(); uint64_t chunkSize = snapInfo.GetChunkSize(); uint64_t chunkPerSegment = segmentSize / chunkSize; - std::vector chunkIndexs = - snapMeta.GetAllChunkIndex(); + std::vector chunkIndexs = snapMeta.GetAllChunkIndex(); for (auto &chunkIndex : chunkIndexs) { ChunkDataName chunkDataName; snapMeta.GetChunkDataName(chunkIndex, &chunkDataName); @@ -533,10 +517,9 @@ int CloneCoreImpl::BuildFileInfoFromSnapshot( return kErrCodeSuccess; } -int CloneCoreImpl::BuildFileInfoFromFile( - std::shared_ptr task, - FInfo *newFileInfo, - CloneSegmentMap *segInfos) { +int CloneCoreImpl::BuildFileInfoFromFile(std::shared_ptr task, + FInfo *newFileInfo, + CloneSegmentMap *segInfos) { segInfos->clear(); UUID source = task->GetCloneInfo().GetSrc(); std::string user = task->GetCloneInfo().GetUser(); @@ -545,10 +528,9 @@ int CloneCoreImpl::BuildFileInfoFromFile( int ret = client_->GetFileInfo(source, mdsRootUser_, &fInfo); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "GetFileInfo fail" - << ", ret = " << ret - << ", source = " << source - << ", user = " << user - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", source = " << source + << ", user = " << user << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeFileNotExist; } // GetOrAllocateSegment依赖fullPathName @@ -571,33 +553,32 @@ int CloneCoreImpl::BuildFileInfoFromFile( << ", taskid = " << task->GetTaskId(); return kErrCodeInternalError; } - if (fileLength%segmentSize != 0) { + if (fileLength % segmentSize != 0) { LOG(ERROR) << "GetFileInfo return invalid fileInfo, " << "fileLength is not align to SegmentSize" << ", taskid = " << task->GetTaskId(); return kErrCodeInternalError; } - for (uint64_t i = 0; i< fileLength/segmentSize; i++) { + for (uint64_t i = 0; i < fileLength / segmentSize; i++) { uint64_t offset = i * segmentSize; SegmentInfo segInfoOut; - ret = client_->GetOrAllocateSegmentInfo( - false, offset, &fInfo, mdsRootUser_, &segInfoOut); - if (ret != LIBCURVE_ERROR::OK && - ret != -LIBCURVE_ERROR::NOT_ALLOCATE) { + ret = client_->GetOrAllocateSegmentInfo(false, offset, &fInfo, + mdsRootUser_, &segInfoOut); + if (ret != LIBCURVE_ERROR::OK && ret != -LIBCURVE_ERROR::NOT_ALLOCATE) { LOG(ERROR) << "GetOrAllocateSegmentInfo fail" - << ", ret = " << ret - << ", filename = " << source - << ", user = " << user - << ", offset = " << offset - << ", allocateIfNotExist = " << "false" - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", filename = " << source + << ", user = " << user << ", offset = " << offset + << ", allocateIfNotExist = " + << "false" + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } if (segInfoOut.chunkvec.size() != 0) { CloneSegmentInfo segInfo; for (std::vector::size_type j = 0; - j < segInfoOut.chunkvec.size(); j++) { + j < segInfoOut.chunkvec.size(); j++) { CloneChunkInfo info; info.location = std::to_string(offset + j * chunkSize); info.seqNum = kInitializeSeqNum; @@ -611,9 +592,8 @@ int CloneCoreImpl::BuildFileInfoFromFile( } -int CloneCoreImpl::CreateCloneFile( - std::shared_ptr task, - const FInfo &fInfo) { +int CloneCoreImpl::CreateCloneFile(std::shared_ptr task, + const FInfo &fInfo) { std::string fileName = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); std::string user = fInfo.owner; @@ -630,31 +610,28 @@ int CloneCoreImpl::CreateCloneFile( } FInfo fInfoOut; - int ret = client_->CreateCloneFile(source, fileName, - mdsRootUser_, fileLength, seqNum, chunkSize, - stripeUnit, stripeCount, &fInfoOut); + int ret = client_->CreateCloneFile(source, fileName, mdsRootUser_, + fileLength, seqNum, chunkSize, + stripeUnit, stripeCount, &fInfoOut); if (ret == LIBCURVE_ERROR::OK) { // nothing } else if (ret == -LIBCURVE_ERROR::EXISTS) { - ret = client_->GetFileInfo(fileName, - mdsRootUser_, &fInfoOut); + ret = client_->GetFileInfo(fileName, mdsRootUser_, &fInfoOut); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "GetFileInfo fail" - << ", ret = " << ret - << ", fileName = " << fileName - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", fileName = " << fileName + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } else { LOG(ERROR) << "CreateCloneFile file" - << ", ret = " << ret - << ", destination = " << fileName - << ", user = " << user - << ", fileLength = " << fileLength - << ", seqNum = " << seqNum - << ", chunkSize = " << chunkSize + << ", ret = " << ret << ", destination = " << fileName + << ", user = " << user << ", fileLength = " << fileLength + << ", seqNum = " << seqNum << ", chunkSize = " << chunkSize << ", return fileId = " << fInfoOut.id - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } task->GetCloneInfo().SetOriginId(fInfoOut.id); @@ -674,17 +651,15 @@ int CloneCoreImpl::CreateCloneFile( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after CreateCloneFile error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; } -int CloneCoreImpl::CreateCloneMeta( - std::shared_ptr task, - FInfo *fInfo, - CloneSegmentMap *segInfos) { +int CloneCoreImpl::CreateCloneMeta(std::shared_ptr task, + FInfo *fInfo, CloneSegmentMap *segInfos) { int ret = CreateOrUpdateCloneMeta(task, fInfo, segInfos); if (ret < 0) { return ret; @@ -695,17 +670,16 @@ int CloneCoreImpl::CreateCloneMeta( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after CreateCloneMeta error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; } -int CloneCoreImpl::CreateCloneChunk( - std::shared_ptr task, - const FInfo &fInfo, - CloneSegmentMap *segInfos) { +int CloneCoreImpl::CreateCloneChunk(std::shared_ptr task, + const FInfo &fInfo, + CloneSegmentMap *segInfos) { int ret = kErrCodeSuccess; uint32_t chunkSize = fInfo.chunksize; uint32_t correctSn = 0; @@ -716,8 +690,8 @@ int CloneCoreImpl::CreateCloneChunk( correctSn = fInfo.seqnum; } auto tracker = std::make_shared(); - for (auto & cloneSegmentInfo : *segInfos) { - for (auto & cloneChunkInfo : cloneSegmentInfo.second) { + for (auto &cloneSegmentInfo : *segInfos) { + for (auto &cloneChunkInfo : cloneSegmentInfo.second) { std::string location; if (IsSnapshot(task)) { location = LocationOperator::GenerateS3Location( @@ -780,8 +754,8 @@ int CloneCoreImpl::CreateCloneChunk( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after CreateCloneChunk error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } return kErrCodeSuccess; @@ -791,34 +765,28 @@ int CloneCoreImpl::StartAsyncCreateCloneChunk( std::shared_ptr task, std::shared_ptr tracker, std::shared_ptr context) { - CreateCloneChunkClosure *cb = - new CreateCloneChunkClosure(tracker, context); + CreateCloneChunkClosure *cb = new CreateCloneChunkClosure(tracker, context); tracker->AddOneTrace(); LOG(INFO) << "Doing CreateCloneChunk" << ", location = " << context->location << ", logicalPoolId = " << context->cidInfo.lpid_ << ", copysetId = " << context->cidInfo.cpid_ << ", chunkId = " << context->cidInfo.cid_ - << ", seqNum = " << context->sn - << ", csn = " << context->csn + << ", seqNum = " << context->sn << ", csn = " << context->csn << ", taskid = " << task->GetTaskId(); - int ret = client_->CreateCloneChunk(context->location, - context->cidInfo, - context->sn, - context->csn, - context->chunkSize, - cb); + int ret = client_->CreateCloneChunk(context->location, context->cidInfo, + context->sn, context->csn, + context->chunkSize, cb); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "CreateCloneChunk fail" - << ", ret = " << ret - << ", location = " << context->location + << ", ret = " << ret << ", location = " << context->location << ", logicalPoolId = " << context->cidInfo.lpid_ << ", copysetId = " << context->cidInfo.cpid_ << ", chunkId = " << context->cidInfo.cid_ - << ", seqNum = " << context->sn - << ", csn = " << context->csn - << ", taskid = " << task->GetTaskId(); + << ", seqNum = " << context->sn << ", csn = " << context->csn + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; @@ -845,18 +813,17 @@ int CloneCoreImpl::HandleCreateCloneChunkResultsAndRetry( if (nowTime - context->startTime < context->clientAsyncMethodRetryTimeSec) { // retry - std::this_thread::sleep_for( - std::chrono::milliseconds( - clientAsyncMethodRetryIntervalMs_)); - ret = StartAsyncCreateCloneChunk( - task, tracker, context); + std::this_thread::sleep_for(std::chrono::milliseconds( + clientAsyncMethodRetryIntervalMs_)); + ret = StartAsyncCreateCloneChunk(task, tracker, context); if (ret < 0) { return kErrCodeInternalError; } } else { LOG(ERROR) << "CreateCloneChunk tracker GetResult fail" << ", ret = " << ret - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } @@ -864,43 +831,37 @@ int CloneCoreImpl::HandleCreateCloneChunkResultsAndRetry( return ret; } -int CloneCoreImpl::CompleteCloneMeta( - std::shared_ptr task, - const FInfo &fInfo, - const CloneSegmentMap &segInfos) { - std::string origin = - cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); +int CloneCoreImpl::CompleteCloneMeta(std::shared_ptr task, + const FInfo &fInfo, + const CloneSegmentMap &segInfos) { + std::string origin = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); std::string user = task->GetCloneInfo().GetUser(); int ret = client_->CompleteCloneMeta(origin, mdsRootUser_); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "CompleteCloneMeta fail" - << ", ret = " << ret - << ", filename = " << origin - << ", user = " << user - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", filename = " << origin + << ", user = " << user << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } if (IsLazy(task)) { - task->GetCloneInfo().SetNextStep( - CloneStep::kChangeOwner); + task->GetCloneInfo().SetNextStep(CloneStep::kChangeOwner); } else { - task->GetCloneInfo().SetNextStep( - CloneStep::kRecoverChunk); + task->GetCloneInfo().SetNextStep(CloneStep::kRecoverChunk); } ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after CompleteCloneMeta error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; } -int CloneCoreImpl::RecoverChunk( - std::shared_ptr task, - const FInfo &fInfo, - const CloneSegmentMap &segInfos) { +int CloneCoreImpl::RecoverChunk(std::shared_ptr task, + const FInfo &fInfo, + const CloneSegmentMap &segInfos) { int ret = kErrCodeSuccess; uint32_t chunkSize = fInfo.chunksize; @@ -910,8 +871,7 @@ int CloneCoreImpl::RecoverChunk( double progressPerData = static_cast(totalProgress) / segNum; uint32_t index = 0; - if (0 == cloneChunkSplitSize_ || - chunkSize % cloneChunkSplitSize_ != 0) { + if (0 == cloneChunkSplitSize_ || chunkSize % cloneChunkSplitSize_ != 0) { LOG(ERROR) << "chunk is not align to cloneChunkSplitSize" << ", taskid = " << task->GetTaskId(); return kErrCodeChunkSizeNotAligned; @@ -920,17 +880,16 @@ int CloneCoreImpl::RecoverChunk( auto tracker = std::make_shared(); uint64_t workingChunkNum = 0; // 为避免发往同一个chunk碰撞,异步请求不同的chunk - for (auto & cloneSegmentInfo : segInfos) { - for (auto & cloneChunkInfo : cloneSegmentInfo.second) { + for (auto &cloneSegmentInfo : segInfos) { + for (auto &cloneChunkInfo : cloneSegmentInfo.second) { if (!cloneChunkInfo.second.needRecover) { continue; } // 当前并发工作的chunk数已大于要求的并发数时,先消化一部分 while (workingChunkNum >= recoverChunkConcurrency_) { uint64_t completeChunkNum = 0; - ret = ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd(task, - tracker, - &completeChunkNum); + ret = ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd( + task, tracker, &completeChunkNum); if (ret < 0) { return kErrCodeInternalError; } @@ -949,29 +908,27 @@ int CloneCoreImpl::RecoverChunk( clientAsyncMethodRetryTimeSec_; LOG(INFO) << "RecoverChunk start" - << ", logicalPoolId = " - << context->cidInfo.lpid_ - << ", copysetId = " << context->cidInfo.cpid_ - << ", chunkId = " << context->cidInfo.cid_ - << ", len = " << context->partSize - << ", taskid = " << task->GetTaskId(); + << ", logicalPoolId = " << context->cidInfo.lpid_ + << ", copysetId = " << context->cidInfo.cpid_ + << ", chunkId = " << context->cidInfo.cid_ + << ", len = " << context->partSize + << ", taskid = " << task->GetTaskId(); ret = StartAsyncRecoverChunkPart(task, tracker, context); if (ret < 0) { return kErrCodeInternalError; } } - task->SetProgress(static_cast( - kProgressRecoverChunkBegin + index * progressPerData)); + task->SetProgress(static_cast(kProgressRecoverChunkBegin + + index * progressPerData)); task->UpdateMetric(); index++; } while (workingChunkNum > 0) { uint64_t completeChunkNum = 0; - ret = ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd(task, - tracker, - &completeChunkNum); + ret = ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd( + task, tracker, &completeChunkNum); if (ret < 0) { return kErrCodeInternalError; } @@ -982,8 +939,8 @@ int CloneCoreImpl::RecoverChunk( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after RecoverChunk error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } return kErrCodeSuccess; @@ -997,27 +954,23 @@ int CloneCoreImpl::StartAsyncRecoverChunkPart( tracker->AddOneTrace(); uint64_t offset = context->partIndex * context->partSize; LOG_EVERY_SECOND(INFO) << "Doing RecoverChunk" - << ", logicalPoolId = " - << context->cidInfo.lpid_ - << ", copysetId = " << context->cidInfo.cpid_ - << ", chunkId = " << context->cidInfo.cid_ - << ", offset = " << offset - << ", len = " << context->partSize - << ", taskid = " << task->GetTaskId(); - int ret = client_->RecoverChunk(context->cidInfo, - offset, - context->partSize, - cb); + << ", logicalPoolId = " << context->cidInfo.lpid_ + << ", copysetId = " << context->cidInfo.cpid_ + << ", chunkId = " << context->cidInfo.cid_ + << ", offset = " << offset + << ", len = " << context->partSize + << ", taskid = " << task->GetTaskId(); + int ret = + client_->RecoverChunk(context->cidInfo, offset, context->partSize, cb); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "RecoverChunk fail" << ", ret = " << ret - << ", logicalPoolId = " - << context->cidInfo.lpid_ + << ", logicalPoolId = " << context->cidInfo.lpid_ << ", copysetId = " << context->cidInfo.cpid_ << ", chunkId = " << context->cidInfo.cid_ - << ", offset = " << offset - << ", len = " << context->partSize - << ", taskid = " << task->GetTaskId(); + << ", offset = " << offset << ", len = " << context->partSize + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; @@ -1029,17 +982,15 @@ int CloneCoreImpl::ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd( uint64_t *completeChunkNum) { *completeChunkNum = 0; tracker->WaitSome(1); - std::list results = - tracker->PopResultContexts(); + std::list results = tracker->PopResultContexts(); for (auto context : results) { if (context->retCode != LIBCURVE_ERROR::OK) { uint64_t nowTime = TimeUtility::GetTimeofDaySec(); if (nowTime - context->startTime < context->clientAsyncMethodRetryTimeSec) { // retry - std::this_thread::sleep_for( - std::chrono::milliseconds( - clientAsyncMethodRetryIntervalMs_)); + std::this_thread::sleep_for(std::chrono::milliseconds( + clientAsyncMethodRetryIntervalMs_)); int ret = StartAsyncRecoverChunkPart(task, tracker, context); if (ret < 0) { return ret; @@ -1061,12 +1012,11 @@ int CloneCoreImpl::ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd( } } else { LOG(INFO) << "RecoverChunk Complete" - << ", logicalPoolId = " - << context->cidInfo.lpid_ - << ", copysetId = " << context->cidInfo.cpid_ - << ", chunkId = " << context->cidInfo.cid_ - << ", len = " << context->partSize - << ", taskid = " << task->GetTaskId(); + << ", logicalPoolId = " << context->cidInfo.lpid_ + << ", copysetId = " << context->cidInfo.cpid_ + << ", chunkId = " << context->cidInfo.cid_ + << ", len = " << context->partSize + << ", taskid = " << task->GetTaskId(); (*completeChunkNum)++; } } @@ -1074,18 +1024,15 @@ int CloneCoreImpl::ContinueAsyncRecoverChunkPartAndWaitSomeChunkEnd( return kErrCodeSuccess; } -int CloneCoreImpl::ChangeOwner( - std::shared_ptr task, - const FInfo &fInfo) { +int CloneCoreImpl::ChangeOwner(std::shared_ptr task, + const FInfo &fInfo) { std::string user = task->GetCloneInfo().GetUser(); - std::string origin = - cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); + std::string origin = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); int ret = client_->ChangeOwner(origin, user); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "ChangeOwner fail, ret = " << ret - << ", fileName = " << origin - << ", newOwner = " << user + << ", fileName = " << origin << ", newOwner = " << user << ", taskid = " << task->GetTaskId(); return kErrCodeInternalError; } @@ -1094,29 +1041,24 @@ int CloneCoreImpl::ChangeOwner( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after ChangeOwner error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } return kErrCodeSuccess; } -int CloneCoreImpl::RenameCloneFile( - std::shared_ptr task, - const FInfo &fInfo) { +int CloneCoreImpl::RenameCloneFile(std::shared_ptr task, + const FInfo &fInfo) { std::string user = fInfo.owner; uint64_t originId = task->GetCloneInfo().GetOriginId(); uint64_t destinationId = task->GetCloneInfo().GetDestId(); - std::string origin = - cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); + std::string origin = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); std::string destination = task->GetCloneInfo().GetDest(); // 先rename - int ret = client_->RenameCloneFile(mdsRootUser_, - originId, - destinationId, - origin, - destination); + int ret = client_->RenameCloneFile(mdsRootUser_, originId, destinationId, + origin, destination); if (-LIBCURVE_ERROR::NOTEXIST == ret) { // 有可能是已经rename过了 FInfo destFInfo; @@ -1125,7 +1067,8 @@ int CloneCoreImpl::RenameCloneFile( LOG(ERROR) << "RenameCloneFile return NOTEXIST," << "And get dest fileInfo fail, ret = " << ret << ", destination filename = " << destination - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } if (destFInfo.id != originId) { @@ -1133,17 +1076,17 @@ int CloneCoreImpl::RenameCloneFile( << "And get dest file id not equal, ret = " << ret << "originId = " << originId << "destFInfo.id = " << destFInfo.id - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } else if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "RenameCloneFile fail" - << ", ret = " << ret - << ", user = " << user - << ", originId = " << originId - << ", origin = " << origin + << ", ret = " << ret << ", user = " << user + << ", originId = " << originId << ", origin = " << origin << ", destination = " << destination - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } @@ -1160,44 +1103,40 @@ int CloneCoreImpl::RenameCloneFile( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after RenameCloneFile error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; } -int CloneCoreImpl::CompleteCloneFile( - std::shared_ptr task, - const FInfo &fInfo, - const CloneSegmentMap &segInfos) { +int CloneCoreImpl::CompleteCloneFile(std::shared_ptr task, + const FInfo &fInfo, + const CloneSegmentMap &segInfos) { std::string fileName; if (IsLazy(task)) { fileName = task->GetCloneInfo().GetDest(); } else { - fileName = - cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); + fileName = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); } std::string user = task->GetCloneInfo().GetUser(); int ret = client_->CompleteCloneFile(fileName, mdsRootUser_); switch (ret) { - case LIBCURVE_ERROR::OK: - break; - case -LIBCURVE_ERROR::NOTEXIST: - LOG(ERROR) << "CompleteCloneFile " - << "find dest file not exist, maybe deleted" - << ", ret = " << ret - << ", destination = " << fileName - << ", user = " << user - << ", taskid = " << task->GetTaskId(); - return kErrCodeFileNotExist; - default: - LOG(ERROR) << "CompleteCloneFile fail" - << ", ret = " << ret - << ", fileName = " << fileName - << ", user = " << user - << ", taskid = " << task->GetTaskId(); - return kErrCodeInternalError; + case LIBCURVE_ERROR::OK: + break; + case -LIBCURVE_ERROR::NOTEXIST: + LOG(ERROR) << "CompleteCloneFile " + << "find dest file not exist, maybe deleted" + << ", ret = " << ret << ", destination = " << fileName + << ", user = " << user << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeFileNotExist; + default: + LOG(ERROR) << "CompleteCloneFile fail" + << ", ret = " << ret << ", fileName = " << fileName + << ", user = " << user << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeInternalError; } if (IsLazy(task)) { task->GetCloneInfo().SetNextStep(CloneStep::kEnd); @@ -1207,8 +1146,8 @@ int CloneCoreImpl::CompleteCloneFile( ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo after CompleteCloneFile error." - << " ret = " << ret - << ", taskid = " << task->GetTaskId(); + << " ret = " << ret << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return kErrCodeSuccess; @@ -1233,8 +1172,8 @@ void CloneCoreImpl::HandleCloneSuccess(std::shared_ptr task) { cloneRef_->DecrementRef(source); NameLockGuard lockGuard(cloneRef_->GetLock(), source); if (cloneRef_->GetRef(source) == 0) { - int ret = client_->SetCloneFileStatus(source, - FileStatus::Created, mdsRootUser_); + int ret = client_->SetCloneFileStatus(source, FileStatus::Created, + mdsRootUser_); if (ret < 0) { task->GetCloneInfo().SetStatus(CloneStatus::error); int ret2 = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); @@ -1244,8 +1183,7 @@ void CloneCoreImpl::HandleCloneSuccess(std::shared_ptr task) { << ", uuid = " << task->GetTaskId(); } LOG(ERROR) << "Task Fail cause by SetCloneFileStatus fail" - << ", ret = " << ret - << ", TaskInfo : " << *task; + << ", ret = " << ret << ", TaskInfo : " << *task; task->Finish(); return; } @@ -1255,8 +1193,7 @@ void CloneCoreImpl::HandleCloneSuccess(std::shared_ptr task) { ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo Task Success Fail!" - << " ret = " << ret - << ", uuid = " << task->GetTaskId(); + << " ret = " << ret << ", uuid = " << task->GetTaskId(); } task->SetProgress(kProgressCloneComplete); @@ -1267,7 +1204,7 @@ void CloneCoreImpl::HandleCloneSuccess(std::shared_ptr task) { } void CloneCoreImpl::HandleCloneError(std::shared_ptr task, - int retCode) { + int retCode) { int ret = kErrCodeSuccess; if (NeedRetry(task, retCode)) { HandleCloneToRetry(task); @@ -1284,8 +1221,8 @@ void CloneCoreImpl::HandleCloneError(std::shared_ptr task, cloneRef_->DecrementRef(source); NameLockGuard lockGuard(cloneRef_->GetLock(), source); if (cloneRef_->GetRef(source) == 0) { - ret = client_->SetCloneFileStatus(source, - FileStatus::Created, mdsRootUser_); + ret = client_->SetCloneFileStatus(source, FileStatus::Created, + mdsRootUser_); if (ret < 0) { LOG(ERROR) << "SetCloneFileStatus fail, ret = " << ret << ", taskid = " << task->GetTaskId(); @@ -1296,8 +1233,7 @@ void CloneCoreImpl::HandleCloneError(std::shared_ptr task, ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo Task error Fail!" - << " ret = " << ret - << ", uuid = " << task->GetTaskId(); + << " ret = " << ret << ", uuid = " << task->GetTaskId(); } LOG(ERROR) << "Task Fail" << ", TaskInfo : " << *task; @@ -1310,8 +1246,7 @@ void CloneCoreImpl::HandleCloneToRetry(std::shared_ptr task) { int ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo Task retrying Fail!" - << " ret = " << ret - << ", uuid = " << task->GetTaskId(); + << " ret = " << ret << ", uuid = " << task->GetTaskId(); } LOG(WARNING) << "Task Fail, Retrying" << ", TaskInfo : " << *task; @@ -1324,8 +1259,7 @@ void CloneCoreImpl::HandleCleanSuccess(std::shared_ptr task) { int ret = metaStore_->DeleteCloneInfo(taskId); if (ret < 0) { LOG(ERROR) << "DeleteCloneInfo failed" - << ", ret = " << ret - << ", taskId = " << taskId; + << ", ret = " << ret << ", taskId = " << taskId; } else { LOG(INFO) << "Clean Task Success" << ", TaskInfo : " << *task; @@ -1342,8 +1276,7 @@ void CloneCoreImpl::HandleCleanError(std::shared_ptr task) { int ret = metaStore_->UpdateCloneInfo(task->GetCloneInfo()); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo Task error Fail!" - << " ret = " << ret - << ", uuid = " << task->GetTaskId(); + << " ret = " << ret << ", uuid = " << task->GetTaskId(); } LOG(ERROR) << "Clean Task Fail" << ", TaskInfo : " << *task; @@ -1360,8 +1293,8 @@ int CloneCoreImpl::GetCloneInfo(TaskIdType taskId, CloneInfo *cloneInfo) { return metaStore_->GetCloneInfo(taskId, cloneInfo); } -int CloneCoreImpl::GetCloneInfoByFileName( - const std::string &fileName, std::vector *list) { +int CloneCoreImpl::GetCloneInfoByFileName(const std::string &fileName, + std::vector *list) { return metaStore_->GetCloneInfoByFileName(fileName, list); } @@ -1385,25 +1318,22 @@ inline bool CloneCoreImpl::IsClone(std::shared_ptr task) { return CloneTaskType::kClone == task->GetCloneInfo().GetTaskType(); } -bool CloneCoreImpl::NeedUpdateCloneMeta( - std::shared_ptr task) { +bool CloneCoreImpl::NeedUpdateCloneMeta(std::shared_ptr task) { bool ret = true; CloneStep step = task->GetCloneInfo().GetNextStep(); if (CloneStep::kCreateCloneFile == step || - CloneStep::kCreateCloneMeta == step || - CloneStep::kEnd == step) { + CloneStep::kCreateCloneMeta == step || CloneStep::kEnd == step) { ret = false; } return ret; } bool CloneCoreImpl::NeedRetry(std::shared_ptr task, - int retCode) { + int retCode) { if (IsLazy(task)) { CloneStep step = task->GetCloneInfo().GetNextStep(); if (CloneStep::kRecoverChunk == step || - CloneStep::kCompleteCloneFile == step || - CloneStep::kEnd == step) { + CloneStep::kCompleteCloneFile == step || CloneStep::kEnd == step) { // 文件不存在的场景下不需要再重试,因为可能已经被删除了 if (retCode != kErrCodeFileNotExist) { return true; @@ -1413,10 +1343,9 @@ bool CloneCoreImpl::NeedRetry(std::shared_ptr task, return false; } -int CloneCoreImpl::CreateOrUpdateCloneMeta( - std::shared_ptr task, - FInfo *fInfo, - CloneSegmentMap *segInfos) { +int CloneCoreImpl::CreateOrUpdateCloneMeta(std::shared_ptr task, + FInfo *fInfo, + CloneSegmentMap *segInfos) { std::string newFileName = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); std::string user = fInfo->owner; @@ -1433,7 +1362,8 @@ int CloneCoreImpl::CreateOrUpdateCloneMeta( << "when CreateOrUpdateCloneMeta, " << "GetFileInfo fail, ret = " << ret << ", filename = " << newFileName - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeFileNotExist; } // 如果是已经rename过,那么id应该一致 @@ -1449,10 +1379,9 @@ int CloneCoreImpl::CreateOrUpdateCloneMeta( } } else { LOG(ERROR) << "GetFileInfo fail" - << ", ret = " << ret - << ", filename = " << newFileName - << ", user = " << user - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", filename = " << newFileName + << ", user = " << user << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } // 更新fInfo @@ -1464,14 +1393,14 @@ int CloneCoreImpl::CreateOrUpdateCloneMeta( for (auto &segInfo : *segInfos) { SegmentInfo segInfoOut; uint64_t offset = segInfo.first * segmentSize; - ret = client_->GetOrAllocateSegmentInfo( - true, offset, fInfo, mdsRootUser_, &segInfoOut); + ret = client_->GetOrAllocateSegmentInfo(true, offset, fInfo, + mdsRootUser_, &segInfoOut); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "GetOrAllocateSegmentInfo fail" << ", newFileName = " << newFileName - << ", user = " << user - << ", offset = " << offset - << ", allocateIfNotExist = " << "true" + << ", user = " << user << ", offset = " << offset + << ", allocateIfNotExist = " + << "true" << ", taskid = " << task->GetTaskId(); return kErrCodeInternalError; } @@ -1498,8 +1427,8 @@ int CloneCoreImpl::CreateOrUpdateCloneMeta( } int CloneCoreImpl::CleanCloneOrRecoverTaskPre(const std::string &user, - const TaskIdType &taskId, - CloneInfo *cloneInfo) { + const TaskIdType &taskId, + CloneInfo *cloneInfo) { int ret = metaStore_->GetCloneInfo(taskId, cloneInfo); if (ret < 0) { // 不存在时直接返回成功,使接口幂等 @@ -1510,27 +1439,26 @@ int CloneCoreImpl::CleanCloneOrRecoverTaskPre(const std::string &user, return kErrCodeInvalidUser; } switch (cloneInfo->GetStatus()) { - case CloneStatus::done: - cloneInfo->SetStatus(CloneStatus::cleaning); - break; - case CloneStatus::error: - cloneInfo->SetStatus(CloneStatus::errorCleaning); - break; - case CloneStatus::cleaning: - case CloneStatus::errorCleaning: - return kErrCodeTaskExist; - break; - default: - LOG(ERROR) << "Can not clean clone/recover task unfinished."; - return kErrCodeCannotCleanCloneUnfinished; - break; + case CloneStatus::done: + cloneInfo->SetStatus(CloneStatus::cleaning); + break; + case CloneStatus::error: + cloneInfo->SetStatus(CloneStatus::errorCleaning); + break; + case CloneStatus::cleaning: + case CloneStatus::errorCleaning: + return kErrCodeTaskExist; + break; + default: + LOG(ERROR) << "Can not clean clone/recover task unfinished."; + return kErrCodeCannotCleanCloneUnfinished; + break; } ret = metaStore_->UpdateCloneInfo(*cloneInfo); if (ret < 0) { LOG(ERROR) << "UpdateCloneInfo fail" - << ", ret = " << ret - << ", taskId = " << taskId; + << ", ret = " << ret << ", taskId = " << taskId; return ret; } return kErrCodeSuccess; @@ -1542,16 +1470,17 @@ void CloneCoreImpl::HandleCleanCloneOrRecoverTask( if (CloneStatus::errorCleaning == task->GetCloneInfo().GetStatus()) { // 错误情况下可能未清除镜像被克隆标志 if (IsFile(task)) { - //重新发送 + // 重新发送 std::string source = task->GetCloneInfo().GetSrc(); NameLockGuard lockGuard(cloneRef_->GetLock(), source); if (cloneRef_->GetRef(source) == 0) { - int ret = client_->SetCloneFileStatus(source, - FileStatus::Created, mdsRootUser_); + int ret = client_->SetCloneFileStatus( + source, FileStatus::Created, mdsRootUser_); if (ret != LIBCURVE_ERROR::OK && ret != -LIBCURVE_ERROR::NOTEXIST) { LOG(ERROR) << "SetCloneFileStatus fail, ret = " << ret - << ", taskid = " << task->GetTaskId(); + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCleanError(task); return; } @@ -1560,17 +1489,14 @@ void CloneCoreImpl::HandleCleanCloneOrRecoverTask( std::string tempFileName = cloneTempDir_ + "/" + task->GetCloneInfo().GetTaskId(); uint64_t fileId = task->GetCloneInfo().GetOriginId(); - std::string user = - task->GetCloneInfo().GetUser(); + std::string user = task->GetCloneInfo().GetUser(); int ret = client_->DeleteFile(tempFileName, mdsRootUser_, fileId); - if (ret != LIBCURVE_ERROR::OK && - ret != -LIBCURVE_ERROR::NOTEXIST) { + if (ret != LIBCURVE_ERROR::OK && ret != -LIBCURVE_ERROR::NOTEXIST) { LOG(ERROR) << "DeleteFile failed" - << ", ret = " << ret - << ", fileName = " << tempFileName - << ", user = " << user - << ", fileId = " << fileId - << ", taskid = " << task->GetTaskId(); + << ", ret = " << ret << ", fileName = " << tempFileName + << ", user = " << user << ", fileId = " << fileId + << ", taskid = " << task->GetTaskId() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCleanError(task); return; } @@ -1585,8 +1511,8 @@ int CloneCoreImpl::HandleRemoveCloneOrRecoverTask( int ret = metaStore_->DeleteCloneInfo(taskId); if (ret < 0) { LOG(ERROR) << "DeleteCloneInfo failed" - << ", ret = " << ret - << ", taskId = " << taskId; + << ", ret = " << ret << ", taskId = " << taskId + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } @@ -1597,12 +1523,11 @@ int CloneCoreImpl::HandleRemoveCloneOrRecoverTask( cloneRef_->DecrementRef(source); NameLockGuard lockGuard(cloneRef_->GetLock(), source); if (cloneRef_->GetRef(source) == 0) { - int ret = client_->SetCloneFileStatus(source, - FileStatus::Created, mdsRootUser_); + int ret = client_->SetCloneFileStatus(source, FileStatus::Created, + mdsRootUser_); if (ret < 0) { LOG(ERROR) << "Task Fail cause by SetCloneFileStatus fail" - << ", ret = " << ret - << ", TaskInfo : " << *task; + << ", ret = " << ret << ", TaskInfo : " << *task; return kErrCodeInternalError; } } @@ -1612,7 +1537,7 @@ int CloneCoreImpl::HandleRemoveCloneOrRecoverTask( } int CloneCoreImpl::CheckFileExists(const std::string &filename, - uint64_t inodeId) { + uint64_t inodeId) { FInfo destFInfo; int ret = client_->GetFileInfo(filename, mdsRootUser_, &destFInfo); if (ret == LIBCURVE_ERROR::OK) { @@ -1641,16 +1566,16 @@ int CloneCoreImpl::HandleDeleteCloneInfo(const CloneInfo &cloneInfo) { cloneRef_->DecrementRef(source); NameLockGuard lockGuard(cloneRef_->GetLock(), source); if (cloneRef_->GetRef(source) == 0) { - int ret = client_->SetCloneFileStatus(source, - FileStatus::Created, mdsRootUser_); + int ret = client_->SetCloneFileStatus(source, FileStatus::Created, + mdsRootUser_); if (ret == -LIBCURVE_ERROR::NOTEXIST) { LOG(WARNING) << "SetCloneFileStatus, file not exist, filename: " << source; - } else if (ret != LIBCURVE_ERROR::OK) { + } else if (ret != LIBCURVE_ERROR::OK) { cloneRef_->IncrementRef(source); LOG(ERROR) << "SetCloneFileStatus fail" - << ", ret = " << ret - << ", cloneInfo : " << cloneInfo; + << ", ret = " << ret << ", cloneInfo : " << cloneInfo + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } @@ -1668,8 +1593,7 @@ int CloneCoreImpl::HandleDeleteCloneInfo(const CloneInfo &cloneInfo) { cloneRef_->IncrementRef(source); } LOG(ERROR) << "DeleteCloneInfo failed" - << ", ret = " << ret - << ", CloneInfo = " << cloneInfo; + << ", ret = " << ret << ", CloneInfo = " << cloneInfo; return kErrCodeInternalError; } @@ -1681,4 +1605,3 @@ int CloneCoreImpl::HandleDeleteCloneInfo(const CloneInfo &cloneInfo) { } // namespace snapshotcloneserver } // namespace curve - diff --git a/src/snapshotcloneserver/snapshot/snapshot_core.cpp b/src/snapshotcloneserver/snapshot/snapshot_core.cpp index 9cac841b11..7e81396d63 100644 --- a/src/snapshotcloneserver/snapshot/snapshot_core.cpp +++ b/src/snapshotcloneserver/snapshot/snapshot_core.cpp @@ -31,9 +31,9 @@ #include "src/common/uuid.h" -using ::curve::common::UUIDGenerator; -using ::curve::common::NameLockGuard; using ::curve::common::LockGuard; +using ::curve::common::NameLockGuard; +using ::curve::common::UUIDGenerator; namespace curve { namespace snapshotcloneserver { @@ -48,20 +48,19 @@ int SnapshotCoreImpl::Init() { } int SnapshotCoreImpl::CreateSnapshotPre(const std::string &file, - const std::string &user, - const std::string &snapshotName, - SnapshotInfo *snapInfo) { + const std::string &user, + const std::string &snapshotName, + SnapshotInfo *snapInfo) { NameLockGuard lockGuard(snapshotNameLock_, file); std::vector fileInfo; metaStore_->GetSnapshotList(file, &fileInfo); int snapshotNum = fileInfo.size(); - for (auto& snap : fileInfo) { + for (auto &snap : fileInfo) { if (Status::pending == snap.GetStatus()) { if ((snap.GetUser() == user) && (snap.GetSnapshotName() == snapshotName)) { LOG(INFO) << "CreateSnapshotPre find same snap task" - << ", file = " << file - << ", user = " << user + << ", file = " << file << ", user = " << user << ", snapshotName = " << snapshotName << ", Exist SnapInfo : " << snap; // 视为同一个快照,返回任务已存在 @@ -81,26 +80,24 @@ int SnapshotCoreImpl::CreateSnapshotPre(const std::string &file, FInfo fInfo; int ret = client_->GetFileInfo(file, user, &fInfo); switch (ret) { - case LIBCURVE_ERROR::OK: - break; - case -LIBCURVE_ERROR::NOTEXIST: - LOG(ERROR) << "create snapshot file not exist" - << ", file = " << file - << ", user = " << user - << ", snapshotName = " << snapshotName; - return kErrCodeFileNotExist; - case -LIBCURVE_ERROR::AUTHFAIL: - LOG(ERROR) << "create snapshot by invalid user" - << ", file = " << file - << ", user = " << user - << ", snapshotName = " << snapshotName; - return kErrCodeInvalidUser; - default: - LOG(ERROR) << "GetFileInfo encounter an error" - << ", ret = " << ret - << ", file = " << file - << ", user = " << user; - return kErrCodeInternalError; + case LIBCURVE_ERROR::OK: + break; + case -LIBCURVE_ERROR::NOTEXIST: + LOG(ERROR) << "create snapshot file not exist" + << ", file = " << file << ", user = " << user + << ", snapshotName = " << snapshotName; + return kErrCodeFileNotExist; + case -LIBCURVE_ERROR::AUTHFAIL: + LOG(ERROR) << "create snapshot by invalid user" + << ", file = " << file << ", user = " << user + << ", snapshotName = " << snapshotName; + return kErrCodeInvalidUser; + default: + LOG(ERROR) << "GetFileInfo encounter an error" + << ", ret = " << ret << ", file = " << file + << ", user = " << user + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeInternalError; } if (fInfo.filestatus != FileStatus::Created && @@ -116,10 +113,10 @@ int SnapshotCoreImpl::CreateSnapshotPre(const std::string &file, ret = metaStore_->AddSnapshot(info); if (ret < 0) { LOG(ERROR) << "AddSnapshot error," - << " ret = " << ret - << ", uuid = " << uuid + << " ret = " << ret << ", uuid = " << uuid << ", fileName = " << file - << ", snapshotName = " << snapshotName; + << ", snapshotName = " << snapshotName + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } *snapInfo = info; @@ -130,7 +127,7 @@ constexpr uint32_t kProgressCreateSnapshotOnCurvefsComplete = 5; constexpr uint32_t kProgressBuildChunkIndexDataComplete = 6; constexpr uint32_t kProgressBuildSnapshotMapComplete = 10; constexpr uint32_t kProgressTransferSnapshotDataStart = - kProgressBuildSnapshotMapComplete; + kProgressBuildSnapshotMapComplete; constexpr uint32_t kProgressTransferSnapshotDataComplete = 99; constexpr uint32_t kProgressComplete = 100; @@ -139,8 +136,9 @@ constexpr uint32_t kProgressComplete = 100; * * 快照进度规划如下: * - * |CreateSnapshotOnCurvefs| BuildChunkIndexData | BuildSnapshotMap | TransferSnapshotData | UpdateSnapshot | //NOLINT - * | 5% | 6% | 10% | 10%~99% | 100% | //NOLINT + * |CreateSnapshotOnCurvefs| BuildChunkIndexData | BuildSnapshotMap | + * TransferSnapshotData | UpdateSnapshot | //NOLINT | 5% | 6% + * | 10% | 10%~99% | 100% | //NOLINT * * * 异步执行期间发生error与cancel情况说明: @@ -177,8 +175,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( ret = CreateSnapshotOnCurvefs(fileName, info, task); if (ret < 0) { LOG(ERROR) << "CreateSnapshotOnCurvefs error, " - << " ret = " << ret - << ", fileName = " << fileName + << " ret = " << ret << ", fileName = " << fileName << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return; @@ -187,9 +184,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( existIndexData = false; } else { FInfo snapInfo; - ret = client_->GetSnapshot(fileName, - info->GetUser(), - seqNum, &snapInfo); + ret = + client_->GetSnapshot(fileName, info->GetUser(), seqNum, &snapInfo); if (-LIBCURVE_ERROR::NOTEXIST == ret) { HandleCreateSnapshotSuccess(task); return; @@ -199,11 +195,11 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( existIndexData = dataStore_->ChunkIndexDataExist(name); } else { LOG(ERROR) << "GetSnapShot on curvefs fail, " - << " ret = " << ret - << ", fileName = " << fileName + << " ret = " << ret << ", fileName = " << fileName << ", user = " << info->GetUser() << ", seqNum = " << seqNum - << ", uuid = " << task->GetUuid(); + << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCreateSnapshotError(task); return; } @@ -223,8 +219,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( ret = dataStore_->GetChunkIndexData(name, &indexData); if (ret < 0) { LOG(ERROR) << "GetChunkIndexData error, " - << " ret = " << ret - << ", fileName = " << fileName + << " ret = " << ret << ", fileName = " << fileName << ", seqNum = " << seqNum << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); @@ -237,8 +232,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( ret = BuildSegmentInfo(*info, &segInfos); if (ret < 0) { LOG(ERROR) << "BuildSegmentInfo error," - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCreateSnapshotError(task); return; } @@ -246,8 +241,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( ret = BuildChunkIndexData(*info, &indexData, &segInfos, task); if (ret < 0) { LOG(ERROR) << "BuildChunkIndexData error, " - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCreateSnapshotError(task); return; } @@ -255,8 +250,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( ret = dataStore_->PutChunkIndexData(name, indexData); if (ret < 0) { LOG(ERROR) << "PutChunkIndexData error, " - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); HandleCreateSnapshotError(task); return; } @@ -270,14 +265,11 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( } FileSnapMap fileSnapshotMap; - ret = BuildSnapshotMap(fileName, - seqNum, - &fileSnapshotMap); + ret = BuildSnapshotMap(fileName, seqNum, &fileSnapshotMap); if (ret < 0) { LOG(ERROR) << "BuildSnapshotMap error, " << " fileName = " << task->GetFileName() - << ", seqNum = " << seqNum - << ", uuid = " << task->GetUuid(); + << ", seqNum = " << seqNum << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return; } @@ -285,26 +277,23 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( task->UpdateMetric(); if (existIndexData) { - ret = TransferSnapshotData(indexData, - *info, - segInfos, - [this] (const ChunkDataName &chunkDataName) { + ret = TransferSnapshotData( + indexData, *info, segInfos, + [this](const ChunkDataName &chunkDataName) { return dataStore_->ChunkDataExist(chunkDataName); }, task); } else { - ret = TransferSnapshotData(indexData, - *info, - segInfos, - [&fileSnapshotMap] (const ChunkDataName &chunkDataName) { + ret = TransferSnapshotData( + indexData, *info, segInfos, + [&fileSnapshotMap](const ChunkDataName &chunkDataName) { return fileSnapshotMap.IsExistChunk(chunkDataName); }, task); } if (ret < 0) { LOG(ERROR) << "TransferSnapshotData error, " - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return; } @@ -312,8 +301,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( task->UpdateMetric(); if (task->IsCanceled()) { - return CancelAfterTransferSnapshotData( - task, indexData, fileSnapshotMap); + return CancelAfterTransferSnapshotData(task, indexData, + fileSnapshotMap); } ret = DeleteSnapshotOnCurvefs(*info); @@ -326,8 +315,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask( LockGuard lockGuard(task->GetLockRef()); if (task->IsCanceled()) { - return CancelAfterTransferSnapshotData( - task, indexData, fileSnapshotMap); + return CancelAfterTransferSnapshotData(task, indexData, + fileSnapshotMap); } HandleCreateSnapshotSuccess(task); @@ -338,7 +327,7 @@ int SnapshotCoreImpl::ClearErrorSnapBeforeCreateSnapshot( std::shared_ptr task) { std::vector snapVec; metaStore_->GetSnapshotList(task->GetFileName(), &snapVec); - for (auto& snap : snapVec) { + for (auto &snap : snapVec) { if (Status::error == snap.GetStatus()) { auto snapInfoMetric = std::make_shared(snap.GetUuid()); @@ -361,15 +350,13 @@ int SnapshotCoreImpl::ClearErrorSnapBeforeCreateSnapshot( return kErrCodeSuccess; } -int SnapshotCoreImpl::StartCancel( - std::shared_ptr task) { +int SnapshotCoreImpl::StartCancel(std::shared_ptr task) { auto &snapInfo = task->GetSnapshotInfo(); snapInfo.SetStatus(Status::canceling); int ret = metaStore_->UpdateSnapshot(snapInfo); if (ret < 0) { LOG(ERROR) << "UpdateSnapshot Task Cancel Fail!" - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return kErrCodeInternalError; } @@ -377,8 +364,7 @@ int SnapshotCoreImpl::StartCancel( } void SnapshotCoreImpl::CancelAfterTransferSnapshotData( - std::shared_ptr task, - const ChunkIndexData &indexData, + std::shared_ptr task, const ChunkIndexData &indexData, const FileSnapMap &fileSnapshotMap) { LOG(INFO) << "Cancel After TransferSnapshotData" << ", uuid = " << task->GetUuid(); @@ -388,7 +374,7 @@ void SnapshotCoreImpl::CancelAfterTransferSnapshotData( indexData.GetChunkDataName(chunkIndex, &chunkDataName); if ((!fileSnapshotMap.IsExistChunk(chunkDataName)) && (dataStore_->ChunkDataExist(chunkDataName))) { - int ret = dataStore_->DeleteChunkData(chunkDataName); + int ret = dataStore_->DeleteChunkData(chunkDataName); if (ret < 0) { LOG(ERROR) << "DeleteChunkData error" << "while canceling CreateSnapshot, " @@ -412,16 +398,13 @@ void SnapshotCoreImpl::CancelAfterCreateChunkIndexData( SnapshotInfo &info = task->GetSnapshotInfo(); UUID uuid = task->GetUuid(); uint64_t seqNum = info.GetSeqNum(); - ChunkIndexDataName name(task->GetFileName(), - seqNum); + ChunkIndexDataName name(task->GetFileName(), seqNum); int ret = dataStore_->DeleteChunkIndexData(name); if (ret < 0) { LOG(ERROR) << "DeleteChunkIndexData error " << "while canceling CreateSnapshot, " - << " ret = " << ret - << ", fileName = " << task->GetFileName() - << ", seqNum = " << seqNum - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", fileName = " << task->GetFileName() + << ", seqNum = " << seqNum << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return; } @@ -451,8 +434,7 @@ void SnapshotCoreImpl::HandleClearSnapshotOnMateStore( if (ret < 0) { LOG(ERROR) << "MetaStore DeleteSnapshot error " << "while cancel CreateSnapshot, " - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); HandleCreateSnapshotError(task); return; } @@ -476,8 +458,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotSuccess( int ret = metaStore_->UpdateSnapshot(snapInfo); if (ret < 0) { LOG(ERROR) << "UpdateSnapshot Task Success Fail!" - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); } task->SetProgress(kProgressComplete); @@ -498,8 +479,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotError( int ret = metaStore_->UpdateSnapshot(snapInfo); if (ret < 0) { LOG(ERROR) << "UpdateSnapshot Task Error Fail!" - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); } LOG(INFO) << "CreateSnapshot Task Fail" @@ -513,14 +493,11 @@ void SnapshotCoreImpl::HandleCreateSnapshotError( } int SnapshotCoreImpl::CreateSnapshotOnCurvefs( - const std::string &fileName, - SnapshotInfo *info, + const std::string &fileName, SnapshotInfo *info, std::shared_ptr task) { uint64_t seqNum = 0; - int ret = - client_->CreateSnapshot(fileName, info->GetUser(), &seqNum); - if (LIBCURVE_ERROR::OK == ret || - -LIBCURVE_ERROR::UNDER_SNAPSHOT == ret) { + int ret = client_->CreateSnapshot(fileName, info->GetUser(), &seqNum); + if (LIBCURVE_ERROR::OK == ret || -LIBCURVE_ERROR::UNDER_SNAPSHOT == ret) { // ok } else if (-LIBCURVE_ERROR::CLIENT_NOT_SUPPORT_SNAPSHOT == ret) { LOG(ERROR) << "CreateSnapshot on curvefs fail, " @@ -529,23 +506,18 @@ int SnapshotCoreImpl::CreateSnapshotOnCurvefs( return kErrCodeNotSupport; } else { LOG(ERROR) << "CreateSnapshot on curvefs fail, " - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); return kErrCodeInternalError; } LOG(INFO) << "CreateSnapshot on curvefs success, seq = " << seqNum << ", uuid = " << task->GetUuid(); FInfo snapInfo; - ret = client_->GetSnapshot(fileName, - info->GetUser(), - seqNum, &snapInfo); + ret = client_->GetSnapshot(fileName, info->GetUser(), seqNum, &snapInfo); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "GetSnapShot on curvefs fail, " - << " ret = " << ret - << ", fileName = " << fileName - << ", user = " << info->GetUser() - << ", seqNum = " << seqNum + << " ret = " << ret << ", fileName = " << fileName + << ", user = " << info->GetUser() << ", seqNum = " << seqNum << ", uuid = " << task->GetUuid(); return kErrCodeInternalError; } @@ -557,7 +529,7 @@ int SnapshotCoreImpl::CreateSnapshotOnCurvefs( info->SetStripeCount(snapInfo.stripeCount); info->SetCreateTime(snapInfo.ctime); - auto compareAndSet = [&](SnapshotInfo* snapinfo) { + auto compareAndSet = [&](SnapshotInfo *snapinfo) { if (nullptr != snapinfo) { auto status = snapinfo->GetStatus(); if (info->GetStatus() != status) { @@ -571,9 +543,9 @@ int SnapshotCoreImpl::CreateSnapshotOnCurvefs( ret = metaStore_->CASSnapshot(uuid, compareAndSet); if (ret < 0) { LOG(ERROR) << "CASSnapshot error, " - << " ret = " << ret - << ", fileName = " << fileName - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", fileName = " << fileName + << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } @@ -588,29 +560,22 @@ int SnapshotCoreImpl::DeleteSnapshotOnCurvefs(const SnapshotInfo &info) { std::string fileName = info.GetFileName(); std::string user = info.GetUser(); uint64_t seqNum = info.GetSeqNum(); - int ret = client_->DeleteSnapshot(fileName, - user, - seqNum); - if (ret != LIBCURVE_ERROR::OK && - ret != -LIBCURVE_ERROR::NOTEXIST && + int ret = client_->DeleteSnapshot(fileName, user, seqNum); + if (ret != LIBCURVE_ERROR::OK && ret != -LIBCURVE_ERROR::NOTEXIST && ret != -LIBCURVE_ERROR::DELETING) { LOG(ERROR) << "DeleteSnapshot error, " - << " ret = " << ret - << ", fileName = " << fileName - << ", user = " << user - << ", seqNum = " << seqNum - << ", uuid = " << info.GetUuid(); + << " ret = " << ret << ", fileName = " << fileName + << ", user = " << user << ", seqNum = " << seqNum + << ", uuid = " << info.GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } do { FileStatus status; - ret = client_->CheckSnapShotStatus(info.GetFileName(), - info.GetUser(), - seqNum, - &status); + ret = client_->CheckSnapShotStatus(info.GetFileName(), info.GetUser(), + seqNum, &status); LOG(INFO) << "Doing CheckSnapShotStatus, fileName = " - << info.GetFileName() - << ", user = " << info.GetUser() + << info.GetFileName() << ", user = " << info.GetUser() << ", seqNum = " << seqNum << ", status = " << static_cast(status) << ", uuid = " << info.GetUuid(); @@ -624,13 +589,14 @@ int SnapshotCoreImpl::DeleteSnapshotOnCurvefs(const SnapshotInfo &info) { LOG(ERROR) << "CheckSnapShotStatus fail" << ", ret = " << ret << ", status = " << static_cast(status) - << ", uuid = " << info.GetUuid(); + << ", uuid = " << info.GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } else { LOG(ERROR) << "CheckSnapShotStatus fail" - << ", ret = " << ret - << ", uuid = " << info.GetUuid(); + << ", ret = " << ret << ", uuid = " << info.GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } std::this_thread::sleep_for( @@ -640,8 +606,7 @@ int SnapshotCoreImpl::DeleteSnapshotOnCurvefs(const SnapshotInfo &info) { } int SnapshotCoreImpl::BuildChunkIndexData( - const SnapshotInfo &info, - ChunkIndexData *indexData, + const SnapshotInfo &info, ChunkIndexData *indexData, std::map *segInfos, std::shared_ptr task) { std::string fileName = info.GetFileName(); @@ -654,32 +619,27 @@ int SnapshotCoreImpl::BuildChunkIndexData( indexData->SetFileName(fileName); uint64_t chunkIndex = 0; - for (uint64_t i = 0; i < fileLength/segmentSize; i++) { + for (uint64_t i = 0; i < fileLength / segmentSize; i++) { uint64_t offset = i * segmentSize; SegmentInfo segInfo; - int ret = client_->GetSnapshotSegmentInfo( - fileName, - user, - seqNum, - offset, - &segInfo); + int ret = client_->GetSnapshotSegmentInfo(fileName, user, seqNum, + offset, &segInfo); if (LIBCURVE_ERROR::OK == ret) { segInfos->emplace(i, segInfo); for (std::vector::size_type j = 0; - j < segInfo.chunkvec.size(); - j++) { + j < segInfo.chunkvec.size(); j++) { ChunkInfoDetail chunkInfo; ChunkIDInfo cidInfo = segInfo.chunkvec[j]; - ret = client_->GetChunkInfo(cidInfo, - &chunkInfo); + ret = client_->GetChunkInfo(cidInfo, &chunkInfo); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "GetChunkInfo error, " << " ret = " << ret << ", logicalPoolId = " << cidInfo.lpid_ << ", copysetId = " << cidInfo.cpid_ << ", chunkId = " << cidInfo.cid_ - << ", uuid = " << task->GetUuid(); + << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } // 2个sn,小的是snap sn,大的是快照之后的写 @@ -690,8 +650,7 @@ int SnapshotCoreImpl::BuildChunkIndexData( // 大于2个sn,错误,报错 if (chunkInfo.chunkSn.size() == 2) { uint64_t seq = - std::min(chunkInfo.chunkSn[0], - chunkInfo.chunkSn[1]); + std::min(chunkInfo.chunkSn[0], chunkInfo.chunkSn[1]); chunkIndex = i * (segmentSize / chunkSize) + j; ChunkDataName chunkDataName(fileName, seq, chunkIndex); indexData->PutChunkDataName(chunkDataName); @@ -706,10 +665,10 @@ int SnapshotCoreImpl::BuildChunkIndexData( // nothing } else { // should not reach here - LOG(ERROR) << "GetChunkInfo return chunkInfo.chunkSn.size()" - << " invalid, size = " - << chunkInfo.chunkSn.size() - << ", uuid = " << task->GetUuid(); + LOG(ERROR) + << "GetChunkInfo return chunkInfo.chunkSn.size()" + << " invalid, size = " << chunkInfo.chunkSn.size() + << ", uuid = " << task->GetUuid(); return kErrCodeInternalError; } if (task->IsCanceled()) { @@ -720,12 +679,11 @@ int SnapshotCoreImpl::BuildChunkIndexData( // nothing } else { LOG(ERROR) << "GetSnapshotSegmentInfo error," - << " ret = " << ret - << ", fileName = " << fileName - << ", user = " << user - << ", seq = " << seqNum + << " ret = " << ret << ", fileName = " << fileName + << ", user = " << user << ", seq = " << seqNum << ", offset = " << offset - << ", uuid = " << task->GetUuid(); + << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return kErrCodeInternalError; } } @@ -734,25 +692,18 @@ int SnapshotCoreImpl::BuildChunkIndexData( } int SnapshotCoreImpl::BuildSegmentInfo( - const SnapshotInfo &info, - std::map *segInfos) { + const SnapshotInfo &info, std::map *segInfos) { int ret = kErrCodeSuccess; std::string fileName = info.GetFileName(); std::string user = info.GetUser(); uint64_t seq = info.GetSeqNum(); uint64_t fileLength = info.GetFileLength(); uint64_t segmentSize = info.GetSegmentSize(); - for (uint64_t i = 0; - i < fileLength/segmentSize; - i++) { + for (uint64_t i = 0; i < fileLength / segmentSize; i++) { uint64_t offset = i * segmentSize; SegmentInfo segInfo; - ret = client_->GetSnapshotSegmentInfo( - fileName, - user, - seq, - offset, - &segInfo); + ret = client_->GetSnapshotSegmentInfo(fileName, user, seq, offset, + &segInfo); if (LIBCURVE_ERROR::OK == ret) { segInfos->emplace(i, std::move(segInfo)); @@ -760,12 +711,12 @@ int SnapshotCoreImpl::BuildSegmentInfo( // nothing } else { LOG(ERROR) << "GetSnapshotSegmentInfo error," - << " ret = " << ret - << ", fileName = " << fileName - << ", user = " << user - << ", seq = " << seq + << " ret = " << ret << ", fileName = " << fileName + << ", user = " << user << ", seq = " << seq << ", offset = " << offset - << ", uuid = " << info.GetUuid(); + << ", uuid = " << info.GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); + return kErrCodeInternalError; } } @@ -773,15 +724,14 @@ int SnapshotCoreImpl::BuildSegmentInfo( } int SnapshotCoreImpl::TransferSnapshotData( - const ChunkIndexData indexData, - const SnapshotInfo &info, + const ChunkIndexData indexData, const SnapshotInfo &info, const std::map &segInfos, const ChunkDataExistFilter &filter, std::shared_ptr task) { int ret = 0; uint64_t segmentSize = info.GetSegmentSize(); uint64_t chunkSize = info.GetChunkSize(); - uint64_t chunkPerSegment = segmentSize/chunkSize; + uint64_t chunkPerSegment = segmentSize / chunkSize; if (0 == chunkSplitSize_ || chunkSize % chunkSplitSize_ != 0) { LOG(ERROR) << "error!, ChunkSize is not align to chunkSplitSize" @@ -792,7 +742,7 @@ int SnapshotCoreImpl::TransferSnapshotData( std::vector chunkIndexVec = indexData.GetAllChunkIndex(); uint32_t totalProgress = kProgressTransferSnapshotDataComplete - - kProgressTransferSnapshotDataStart; + kProgressTransferSnapshotDataStart; uint32_t transferDataNum = chunkIndexVec.size(); double progressPerData = static_cast(totalProgress) / transferDataNum; @@ -816,10 +766,8 @@ int SnapshotCoreImpl::TransferSnapshotData( LOG(ERROR) << "TransferSnapshotData, " << "chunkIndexInSegment >= " << "segInfos[segNum].chunkvec.size()" - << ", chunkIndexInSegment = " - << chunkIndexInSegment - << ", size = " - << it->second.chunkvec.size() + << ", chunkIndexInSegment = " << chunkIndexInSegment + << ", size = " << it->second.chunkvec.size() << ", uuid = " << task->GetUuid(); return kErrCodeInternalError; } @@ -834,8 +782,7 @@ int SnapshotCoreImpl::TransferSnapshotData( auto it = segInfos.find(segNum); if (it != segInfos.end()) { - ChunkIDInfo cidInfo = - it->second.chunkvec[chunkIndexInSegment]; + ChunkIDInfo cidInfo = it->second.chunkvec[chunkIndexInSegment]; if (!filter(chunkDataName)) { auto taskInfo = std::make_shared( @@ -845,10 +792,7 @@ int SnapshotCoreImpl::TransferSnapshotData( readChunkSnapshotConcurrency_); UUID taskId = UUIDGenerator().GenerateUUID(); auto task = new TransferSnapshotDataChunkTask( - taskId, - taskInfo, - client_, - dataStore_); + taskId, taskInfo, client_, dataStore_); task->SetTracker(tracker); tracker->AddOneTrace(); threadPool_->PushTask(task); @@ -863,13 +807,13 @@ int SnapshotCoreImpl::TransferSnapshotData( ret = tracker->GetResult(); if (ret < 0) { LOG(ERROR) << "TransferSnapshotDataChunk tracker GetResult fail" - << ", ret = " << ret - << ", uuid = " << task->GetUuid(); + << ", ret = " << ret << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } task->SetProgress(static_cast( - kProgressTransferSnapshotDataStart + index * progressPerData)); + kProgressTransferSnapshotDataStart + index * progressPerData)); task->UpdateMetric(); index++; if (task->IsCanceled()) { @@ -881,8 +825,8 @@ int SnapshotCoreImpl::TransferSnapshotData( ret = tracker->GetResult(); if (ret < 0) { LOG(ERROR) << "TransferSnapshotDataChunk tracker GetResult fail" - << ", ret = " << ret - << ", uuid = " << task->GetUuid(); + << ", ret = " << ret << ", uuid = " << task->GetUuid() + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } @@ -890,11 +834,9 @@ int SnapshotCoreImpl::TransferSnapshotData( } -int SnapshotCoreImpl::DeleteSnapshotPre( - UUID uuid, - const std::string &user, - const std::string &fileName, - SnapshotInfo *snapInfo) { +int SnapshotCoreImpl::DeleteSnapshotPre(UUID uuid, const std::string &user, + const std::string &fileName, + SnapshotInfo *snapInfo) { NameLockGuard lockSnapGuard(snapshotRef_->GetSnapshotLock(), uuid); int ret = metaStore_->GetSnapshotInfo(uuid, snapInfo); if (ret < 0) { @@ -905,28 +847,27 @@ int SnapshotCoreImpl::DeleteSnapshotPre( LOG(ERROR) << "Can not delete snapshot by different user."; return kErrCodeInvalidUser; } - if ((!fileName.empty()) && - (fileName != snapInfo->GetFileName())) { + if ((!fileName.empty()) && (fileName != snapInfo->GetFileName())) { LOG(ERROR) << "Can not delete, fileName is not matched."; return kErrCodeFileNameNotMatch; } switch (snapInfo->GetStatus()) { - case Status::done: - snapInfo->SetStatus(Status::deleting); - break; - case Status::error: - snapInfo->SetStatus(Status::errorDeleting); - break; - case Status::canceling: - case Status::deleting: - case Status::errorDeleting: - return kErrCodeTaskExist; - case Status::pending: - return kErrCodeSnapshotCannotDeleteUnfinished; - default: - LOG(ERROR) << "Can not reach here!"; - return kErrCodeInternalError; + case Status::done: + snapInfo->SetStatus(Status::deleting); + break; + case Status::error: + snapInfo->SetStatus(Status::errorDeleting); + break; + case Status::canceling: + case Status::deleting: + case Status::errorDeleting: + return kErrCodeTaskExist; + case Status::pending: + return kErrCodeSnapshotCannotDeleteUnfinished; + default: + LOG(ERROR) << "Can not reach here!"; + return kErrCodeInternalError; } if (snapshotRef_->GetSnapshotRef(uuid) > 0) { @@ -936,8 +877,7 @@ int SnapshotCoreImpl::DeleteSnapshotPre( ret = metaStore_->UpdateSnapshot(*snapInfo); if (ret < 0) { LOG(ERROR) << "UpdateSnapshot error," - << " ret = " << ret - << ", uuid = " << uuid; + << " ret = " << ret << ", uuid = " << uuid; return ret; } return kErrCodeSuccess; @@ -945,7 +885,7 @@ int SnapshotCoreImpl::DeleteSnapshotPre( constexpr uint32_t kDelProgressBuildSnapshotMapComplete = 10; constexpr uint32_t kDelProgressDeleteChunkDataStart = - kDelProgressBuildSnapshotMapComplete; + kDelProgressBuildSnapshotMapComplete; constexpr uint32_t kDelProgressDeleteChunkDataComplete = 80; constexpr uint32_t kDelProgressDeleteChunkIndexDataComplete = 90; @@ -969,15 +909,13 @@ void SnapshotCoreImpl::HandleDeleteSnapshotTask( if (ret < 0) { LOG(ERROR) << "BuildSnapshotMap error, " << " fileName = " << task->GetFileName() - << ", seqNum = " << seqNum - << ", uuid = " << task->GetUuid(); + << ", seqNum = " << seqNum << ", uuid = " << task->GetUuid(); HandleDeleteSnapshotError(task); return; } task->SetProgress(kDelProgressBuildSnapshotMapComplete); task->UpdateMetric(); - ChunkIndexDataName name(task->GetFileName(), - seqNum); + ChunkIndexDataName name(task->GetFileName(), seqNum); ChunkIndexData indexData; if (dataStore_->ChunkIndexDataExist(name)) { ret = dataStore_->GetChunkIndexData(name, &indexData); @@ -993,10 +931,10 @@ void SnapshotCoreImpl::HandleDeleteSnapshotTask( auto chunkIndexVec = indexData.GetAllChunkIndex(); uint32_t totalProgress = kDelProgressDeleteChunkDataComplete - - kDelProgressDeleteChunkDataStart; + kDelProgressDeleteChunkDataStart; uint32_t chunkDataNum = chunkIndexVec.size(); - double progressPerData = static_cast (totalProgress) / - chunkDataNum; + double progressPerData = + static_cast(totalProgress) / chunkDataNum; uint32_t index = 0; LOG(INFO) << "HandleDeleteSnapshotTask GetChunkIndexData success, " @@ -1008,14 +946,13 @@ void SnapshotCoreImpl::HandleDeleteSnapshotTask( indexData.GetChunkDataName(chunkIndex, &chunkDataName); if ((!fileSnapshotMap.IsExistChunk(chunkDataName)) && (dataStore_->ChunkDataExist(chunkDataName))) { - ret = dataStore_->DeleteChunkData(chunkDataName); + ret = dataStore_->DeleteChunkData(chunkDataName); if (ret < 0) { LOG(ERROR) << "DeleteChunkData error, " << " ret = " << ret << ", fileName = " << task->GetFileName() << ", seqNum = " << seqNum - << ", chunkIndex = " - << chunkDataName.chunkIndex_ + << ", chunkIndex = " << chunkDataName.chunkIndex_ << ", uuid = " << task->GetUuid(); HandleDeleteSnapshotError(task); return; @@ -1057,8 +994,7 @@ void SnapshotCoreImpl::HandleDeleteSnapshotTask( ret = metaStore_->DeleteSnapshot(uuid); if (ret < 0) { LOG(ERROR) << "DeleteSnapshot error, " - << " ret = " << ret - << ", uuid = " << uuid; + << " ret = " << ret << ", uuid = " << uuid; HandleDeleteSnapshotError(task); return; } @@ -1085,8 +1021,7 @@ void SnapshotCoreImpl::HandleDeleteSnapshotError( int ret = metaStore_->UpdateSnapshot(info); if (ret < 0) { LOG(ERROR) << "UpdateSnapshot Task Error Fail!" - << " ret = " << ret - << ", uuid = " << task->GetUuid(); + << " ret = " << ret << ", uuid = " << task->GetUuid(); } auto &snapInfo = task->GetSnapshotInfo(); @@ -1101,19 +1036,18 @@ void SnapshotCoreImpl::HandleDeleteSnapshotError( } int SnapshotCoreImpl::GetFileSnapshotInfo(const std::string &file, - std::vector *info) { + std::vector *info) { metaStore_->GetSnapshotList(file, info); return kErrCodeSuccess; } -int SnapshotCoreImpl::GetSnapshotInfo(const UUID uuid, - SnapshotInfo *info) { +int SnapshotCoreImpl::GetSnapshotInfo(const UUID uuid, SnapshotInfo *info) { return metaStore_->GetSnapshotInfo(uuid, info); } int SnapshotCoreImpl::BuildSnapshotMap(const std::string &fileName, - uint64_t seqNum, - FileSnapMap *fileSnapshotMap) { + uint64_t seqNum, + FileSnapMap *fileSnapshotMap) { std::vector snapInfos; int ret = metaStore_->GetSnapshotList(fileName, &snapInfos); for (auto &snap : snapInfos) { @@ -1125,7 +1059,7 @@ int SnapshotCoreImpl::BuildSnapshotMap(const std::string &fileName, if (ret < 0) { LOG(ERROR) << "GetChunkIndexData error, " << " ret = " << ret - << ", fileName = " << snap.GetFileName() + << ", fileName = " << snap.GetFileName() << ", seqNum = " << snap.GetSeqNum(); // 此处不能返回错误, // 否则一旦某个失败的快照没有indexdata,所有快照都无法删除 @@ -1148,8 +1082,7 @@ int SnapshotCoreImpl::HandleCancelUnSchduledSnapshotTask( int ret = metaStore_->DeleteSnapshot(snapInfo.GetUuid()); if (ret < 0) { LOG(ERROR) << "HandleCancelUnSchduledSnapshotTask fail, " - << " ret = " << ret - << ", uuid = " << snapInfo.GetUuid() + << " ret = " << ret << ", uuid = " << snapInfo.GetUuid() << ", fileName = " << snapInfo.GetFileName() << ", snapshotName = " << snapInfo.GetSnapshotName() << ", seqNum = " << snapInfo.GetSeqNum() @@ -1172,10 +1105,9 @@ int SnapshotCoreImpl::HandleCancelScheduledSnapshotTask( if (kErrCodeSuccess == ret) { task->Cancel(); } else { - auto& snapInfo = task->GetSnapshotInfo(); + auto &snapInfo = task->GetSnapshotInfo(); LOG(ERROR) << "HandleCancelSchduledSnapshotTask failed: " - << ", ret = " << ret - << ", uuid = " << snapInfo.GetUuid() + << ", ret = " << ret << ", uuid = " << snapInfo.GetUuid() << ", fileName = " << snapInfo.GetFileName() << ", snapshotName = " << snapInfo.GetSnapshotName() << ", seqNum = " << snapInfo.GetSeqNum() @@ -1187,4 +1119,3 @@ int SnapshotCoreImpl::HandleCancelScheduledSnapshotTask( } // namespace snapshotcloneserver } // namespace curve - diff --git a/test/integration/snapshotcloneserver/snapshotcloneserver_recover_test.cpp b/test/integration/snapshotcloneserver/snapshotcloneserver_recover_test.cpp index 4001b23995..5928f16cb3 100644 --- a/test/integration/snapshotcloneserver/snapshotcloneserver_recover_test.cpp +++ b/test/integration/snapshotcloneserver/snapshotcloneserver_recover_test.cpp @@ -674,7 +674,8 @@ class SnapshotCloneServerTest : public ::testing::Test { int ret = tracker->GetResult(); if (ret != LIBCURVE_ERROR::OK) { LOG(ERROR) << "RecoverChunk tracker GetResult fail" - << ", ret = " << ret; + << ", ret = " << ret + << LibCurveErrorName((LIBCURVE_ERROR)ret); return ret; } return LIBCURVE_ERROR::OK; diff --git a/test/snapshotcloneserver/test_snapshot_core.cpp b/test/snapshotcloneserver/test_snapshot_core.cpp index 014f776d5d..be72d39077 100644 --- a/test/snapshotcloneserver/test_snapshot_core.cpp +++ b/test/snapshotcloneserver/test_snapshot_core.cpp @@ -33,13 +33,13 @@ namespace curve { namespace snapshotcloneserver { -using ::testing::Return; using ::testing::_; -using ::testing::AnyOf; using ::testing::AllOf; -using ::testing::SetArgPointee; -using ::testing::Invoke; +using ::testing::AnyOf; using ::testing::DoAll; +using ::testing::Invoke; +using ::testing::Return; +using ::testing::SetArgPointee; class TestSnapshotCoreImpl : public ::testing::Test { public: @@ -47,8 +47,7 @@ class TestSnapshotCoreImpl : public ::testing::Test { virtual ~TestSnapshotCoreImpl() {} virtual void SetUp() { - snapshotRef_ = - std::make_shared(); + snapshotRef_ = std::make_shared(); client_ = std::make_shared(); metaStore_ = std::make_shared(); dataStore_ = std::make_shared(); @@ -60,11 +59,8 @@ class TestSnapshotCoreImpl : public ::testing::Test { option.snapshotCoreThreadNum = 1; option.clientAsyncMethodRetryTimeSec = 1; option.clientAsyncMethodRetryIntervalMs = 500; - core_ = std::make_shared(client_, - metaStore_, - dataStore_, - snapshotRef_, - option); + core_ = std::make_shared( + client_, metaStore_, dataStore_, snapshotRef_, option); ASSERT_EQ(core_->Init(), 0); } @@ -96,18 +92,13 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreSuccess) { sinfo.SetStatus(Status::done); list.push_back(sinfo); EXPECT_CALL(*metaStore_, GetSnapshotList(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(list), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(list), Return(kErrCodeSuccess))); FInfo fInfo; fInfo.filestatus = FileStatus::Created; fInfo.owner = user; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(LIBCURVE_ERROR::OK))); - EXPECT_CALL(*metaStore_, AddSnapshot(_)) - .WillOnce(Return(kErrCodeSuccess)); + .WillOnce(DoAll(SetArgPointee<2>(fInfo), Return(LIBCURVE_ERROR::OK))); + EXPECT_CALL(*metaStore_, AddSnapshot(_)).WillOnce(Return(kErrCodeSuccess)); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeSuccess, ret); } @@ -119,16 +110,11 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreTaskExist) { SnapshotInfo info; std::vector list; - SnapshotInfo sinfo("snapid1", - user, - file, - desc); + SnapshotInfo sinfo("snapid1", user, file, desc); sinfo.SetStatus(Status::pending); list.push_back(sinfo); EXPECT_CALL(*metaStore_, GetSnapshotList(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(list), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(list), Return(kErrCodeSuccess))); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeTaskExist, ret); } @@ -144,9 +130,7 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreAddSnapshotFail) { fInfo.filestatus = FileStatus::Created; fInfo.owner = user; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(fInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, AddSnapshot(_)) .WillOnce(Return(kErrCodeInternalError)); int ret = core_->CreateSnapshotPre(file, user, desc, &info); @@ -163,9 +147,8 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreFileNotExist) { FInfo fInfo; fInfo.filestatus = FileStatus::Created; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(-LIBCURVE_ERROR::NOTEXIST))); + .WillOnce( + DoAll(SetArgPointee<2>(fInfo), Return(-LIBCURVE_ERROR::NOTEXIST))); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeFileNotExist, ret); } @@ -181,9 +164,8 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreInvalidUser) { fInfo.filestatus = FileStatus::Created; fInfo.owner = "user2"; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(-LIBCURVE_ERROR::AUTHFAIL))); + .WillOnce( + DoAll(SetArgPointee<2>(fInfo), Return(-LIBCURVE_ERROR::AUTHFAIL))); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeInvalidUser, ret); } @@ -198,9 +180,8 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreInternalError) { FInfo fInfo; fInfo.filestatus = FileStatus::Created; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(-LIBCURVE_ERROR::FAILED))); + .WillOnce( + DoAll(SetArgPointee<2>(fInfo), Return(-LIBCURVE_ERROR::FAILED))); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeInternalError, ret); } @@ -216,9 +197,7 @@ TEST_F(TestSnapshotCoreImpl, TestCreateSnapshotPreFailStatusInvalid) { fInfo.filestatus = FileStatus::Cloning; fInfo.owner = user; EXPECT_CALL(*client_, GetFileInfo(_, _, _)) - .WillOnce(DoAll( - SetArgPointee<2>(fInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(fInfo), Return(LIBCURVE_ERROR::OK))); int ret = core_->CreateSnapshotPre(file, user, desc, &info); ASSERT_EQ(kErrCodeFileStatusInvalid, ret); } @@ -232,8 +211,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPreSuccess) { SnapshotInfo info(uuid, user, fileName, desc); info.SetStatus(Status::done); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .WillOnce(Return(kErrCodeSuccess)); @@ -252,8 +230,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_GetSnapshotInfoNotExist) { SnapshotInfo info(uuid, user, fileName, desc); info.SetStatus(Status::done); EXPECT_CALL(*metaStore_, GetSnapshotInfo(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeInternalError))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeInternalError))); SnapshotInfo infoOut; int ret = core_->DeleteSnapshotPre(uuid, user, fileName, &infoOut); @@ -269,8 +246,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_UpdateSnapshotFail) { SnapshotInfo info(uuid, user, fileName, desc); info.SetStatus(Status::done); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .WillOnce(Return(kErrCodeInternalError)); @@ -290,8 +266,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_InvalidUser) { SnapshotInfo info(uuid, user2, fileName, desc); info.SetStatus(Status::done); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); SnapshotInfo infoOut; int ret = core_->DeleteSnapshotPre(uuid, user, fileName, &infoOut); @@ -307,8 +282,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_DeleteSnapshotUnfinished) { SnapshotInfo info(uuid, user, fileName, desc); info.SetStatus(Status::pending); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); SnapshotInfo infoOut; int ret = core_->DeleteSnapshotPre(uuid, user, fileName, &infoOut); @@ -325,8 +299,7 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_FileNameNotMatch) { SnapshotInfo info(uuid, user, fileName2, desc); info.SetStatus(Status::done); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); SnapshotInfo infoOut; int ret = core_->DeleteSnapshotPre(uuid, user, fileName, &infoOut); @@ -342,16 +315,14 @@ TEST_F(TestSnapshotCoreImpl, TestDeleteSnapshotPre_TaskExit) { SnapshotInfo info(uuid, user, fileName, desc); info.SetStatus(Status::deleting); EXPECT_CALL(*metaStore_, GetSnapshotInfo(uuid, _)) - .WillOnce(DoAll(SetArgPointee<1>(info), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(info), Return(kErrCodeSuccess))); SnapshotInfo infoOut; int ret = core_->DeleteSnapshotPre(uuid, user, fileName, &infoOut); ASSERT_EQ(kErrCodeTaskExist, ret); } -TEST_F(TestSnapshotCoreImpl, - TestGetFileSnapshotInfoSuccess) { +TEST_F(TestSnapshotCoreImpl, TestGetFileSnapshotInfoSuccess) { std::string file = "file1"; std::vector info; @@ -362,8 +333,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(kErrCodeSuccess, ret); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskSuccess) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskSuccess) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -378,9 +348,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -389,9 +357,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -407,10 +374,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -420,29 +385,21 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce(DoAll(SetArgPointee<4>(segInfo2), Return(kErrCodeSuccess))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -464,16 +421,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -481,17 +435,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -518,8 +468,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::done, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_CreateSnapshotFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTask_CreateSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -533,9 +482,8 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(-LIBCURVE_ERROR::FAILED))); + .WillOnce( + DoAll(SetArgPointee<2>(seqNum), Return(-LIBCURVE_ERROR::FAILED))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) @@ -547,8 +495,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_GetSnapshotFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTask_GetSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -562,9 +509,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -574,9 +519,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(-LIBCURVE_ERROR::FAILED))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(-LIBCURVE_ERROR::FAILED))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .WillOnce(Return(kErrCodeSuccess)); @@ -587,8 +531,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_UpdateSnapshotFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTask_UpdateSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -601,9 +544,7 @@ TEST_F(TestSnapshotCoreImpl, std::shared_ptr task = std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -613,9 +554,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -630,7 +570,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_SecondTimeUpdateSnapshotFail) { + TestHandleCreateSnapshotTask_SecondTimeUpdateSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -643,9 +583,7 @@ TEST_F(TestSnapshotCoreImpl, std::shared_ptr task = std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -655,9 +593,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -672,7 +609,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_GetSnapshotSegmentInfoFail) { + TestHandleCreateSnapshotTask_GetSnapshotSegmentInfoFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -687,9 +624,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -699,9 +634,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -709,11 +643,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .WillOnce(Return(kErrCodeSuccess)); - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .WillRepeatedly(Return(-LIBCURVE_ERROR::FAILED)); core_->HandleCreateSnapshotTask(task); @@ -722,8 +652,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_GetChunkInfoFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTask_GetChunkInfoFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -737,9 +666,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -749,9 +676,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -767,10 +693,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -780,25 +704,19 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .WillOnce(DoAll(SetArgPointee<1>(chunkInfo), - Return(-LIBCURVE_ERROR::FAILED))); + Return(-LIBCURVE_ERROR::FAILED))); core_->HandleCreateSnapshotTask(task); @@ -807,7 +725,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_PutChunkIndexDataFail) { + TestHandleCreateSnapshotTask_PutChunkIndexDataFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -822,9 +740,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; @@ -834,9 +750,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -852,10 +767,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -865,29 +778,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeInternalError)); @@ -899,7 +805,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_DataChunkTranferInitFail) { + TestHandleCreateSnapshotTask_DataChunkTranferInitFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -914,9 +820,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -925,9 +829,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -943,10 +846,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -956,29 +857,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -989,23 +883,20 @@ TEST_F(TestSnapshotCoreImpl, std::vector snapInfos; SnapshotInfo info2(uuid2, user, fileName, desc2); info.SetSeqNum(seqNum); - info2.SetSeqNum(seqNum - 1); //上一个快照 + info2.SetSeqNum(seqNum - 1); // 上一个快照 info2.SetStatus(Status::done); snapInfos.push_back(info); snapInfos.push_back(info2); EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .WillOnce(Return(kErrCodeInternalError)); @@ -1017,7 +908,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_ReadChunkSnapshotFail) { + TestHandleCreateSnapshotTask_ReadChunkSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1031,9 +922,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1042,9 +931,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1060,10 +948,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1073,29 +959,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1111,35 +990,28 @@ TEST_F(TestSnapshotCoreImpl, snapInfos.push_back(info); snapInfos.push_back(info2); - EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) + EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(1) .WillRepeatedly(Return(kErrCodeSuccess)); EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) - .WillOnce(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(-LIBCURVE_ERROR::FAILED))); + .WillOnce( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(-LIBCURVE_ERROR::FAILED))); core_->HandleCreateSnapshotTask(task); @@ -1148,7 +1020,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_DataChunkTranferAddPartFail) { + TestHandleCreateSnapshotTask_DataChunkTranferAddPartFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1163,9 +1035,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1174,9 +1044,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1192,10 +1061,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1205,29 +1072,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1245,16 +1105,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(1) @@ -1262,17 +1119,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .WillRepeatedly(Return(kErrCodeInternalError)); @@ -1287,7 +1140,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_DataChunkTranferCompleteFail) { + TestHandleCreateSnapshotTask_DataChunkTranferCompleteFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1302,9 +1155,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1313,9 +1164,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1331,10 +1181,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1344,29 +1192,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1384,16 +1225,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(1) @@ -1402,17 +1240,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(2) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(2) @@ -1430,8 +1264,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_DeleteSnapshotFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTask_DeleteSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1446,9 +1279,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1457,9 +1288,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1475,10 +1305,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1488,29 +1316,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1528,16 +1349,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -1546,17 +1364,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -1577,7 +1391,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnReturnFail) { + TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnReturnFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1592,9 +1406,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1603,9 +1415,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1621,10 +1432,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1634,29 +1443,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1674,16 +1476,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -1692,17 +1491,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -1726,7 +1521,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnDeleteError) { + TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnDeleteError) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1741,9 +1536,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1752,9 +1545,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1770,10 +1562,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1783,29 +1573,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1823,16 +1606,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -1841,17 +1621,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -1875,7 +1651,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnFileStatusError) { + TestHandleCreateSnapshotTask_CheckSnapShotStatusFailOnFileStatusError) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -1890,9 +1666,7 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -1901,9 +1675,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -1919,10 +1692,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -1932,29 +1703,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -1972,16 +1736,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -1990,17 +1751,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -2025,7 +1782,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskExistIndexDataSuccess) { + TestHandleCreateSnapshotTaskExistIndexDataSuccess) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2043,8 +1800,7 @@ TEST_F(TestSnapshotCoreImpl, std::shared_ptr task = std::make_shared(info, snapshotInfoMetric); - EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)) - .WillOnce(Return(true)); + EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)).WillOnce(Return(true)); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2057,12 +1813,8 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); LogicPoolID lpid1 = 1; CopysetID cpid1 = 1; @@ -2072,10 +1824,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -2085,21 +1835,14 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); UUID uuid2 = "uuid2"; std::string desc2 = "desc2"; @@ -2114,9 +1857,8 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) @@ -2126,17 +1868,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -2163,7 +1901,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskChunkSizeNotAlignTokChunkSplitSize) { + TestHandleCreateSnapshotTaskChunkSizeNotAlignTokChunkSplitSize) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2180,8 +1918,7 @@ TEST_F(TestSnapshotCoreImpl, std::shared_ptr task = std::make_shared(info, snapshotInfoMetric); - EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)) - .WillOnce(Return(true)); + EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)).WillOnce(Return(true)); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2194,12 +1931,8 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); LogicPoolID lpid1 = 1; @@ -2210,10 +1943,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -2223,21 +1954,14 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); UUID uuid2 = "uuid2"; std::string desc2 = "desc2"; @@ -2252,9 +1976,8 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .Times(1) @@ -2266,8 +1989,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskChunkVecInfoMiss) { +TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskChunkVecInfoMiss) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2284,8 +2006,7 @@ TEST_F(TestSnapshotCoreImpl, std::shared_ptr task = std::make_shared(info, snapshotInfoMetric); - EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)) - .WillOnce(Return(true)); + EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)).WillOnce(Return(true)); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2298,28 +2019,19 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); SegmentInfo segInfo1; SegmentInfo segInfo2; - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); UUID uuid2 = "uuid2"; std::string desc2 = "desc2"; @@ -2334,9 +2046,8 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) .Times(1) @@ -2348,8 +2059,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleDeleteSnapshotTaskSuccess) { +TEST_F(TestSnapshotCoreImpl, TestHandleDeleteSnapshotTaskSuccess) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2374,9 +2084,7 @@ TEST_F(TestSnapshotCoreImpl, snapInfos.push_back(info2); EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) - .WillOnce(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData1; indexData1.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2384,15 +2092,10 @@ TEST_F(TestSnapshotCoreImpl, indexData2.PutChunkDataName(ChunkDataName(fileName, 1, 1)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData1), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData1), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); - EXPECT_CALL(*dataStore_, ChunkDataExist(_)) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*dataStore_, ChunkDataExist(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*dataStore_, DeleteChunkData(_)) .WillRepeatedly(Return(kErrCodeSuccess)); @@ -2412,7 +2115,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleDeleteSnapshotTask_GetChunkIndexDataSecondTimeFail) { + TestHandleDeleteSnapshotTask_GetChunkIndexDataSecondTimeFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2437,9 +2140,7 @@ TEST_F(TestSnapshotCoreImpl, snapInfos.push_back(info2); EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) - .WillOnce(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData1; indexData1.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2447,12 +2148,9 @@ TEST_F(TestSnapshotCoreImpl, indexData2.PutChunkDataName(ChunkDataName(fileName, 1, 1)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData1), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeInternalError))); + .WillOnce(DoAll(SetArgPointee<1>(indexData1), Return(kErrCodeSuccess))) + .WillOnce( + DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeInternalError))); EXPECT_CALL(*dataStore_, ChunkIndexDataExist(_)) .WillRepeatedly(Return(true)); @@ -2466,7 +2164,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleDeleteSnapshotTask_DeleteChunkIndexDataFail) { + TestHandleDeleteSnapshotTask_DeleteChunkIndexDataFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2491,9 +2189,7 @@ TEST_F(TestSnapshotCoreImpl, snapInfos.push_back(info2); EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) - .WillOnce(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData1; indexData1.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2501,15 +2197,10 @@ TEST_F(TestSnapshotCoreImpl, indexData2.PutChunkDataName(ChunkDataName(fileName, 1, 1)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData1), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData1), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); - EXPECT_CALL(*dataStore_, ChunkDataExist(_)) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*dataStore_, ChunkDataExist(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*dataStore_, DeleteChunkData(_)) .WillRepeatedly(Return(kErrCodeSuccess)); @@ -2528,8 +2219,7 @@ TEST_F(TestSnapshotCoreImpl, ASSERT_EQ(Status::error, task->GetSnapshotInfo().GetStatus()); } -TEST_F(TestSnapshotCoreImpl, - TestHandleDeleteSnapshotTaskDeleteSnapshotFail) { +TEST_F(TestSnapshotCoreImpl, TestHandleDeleteSnapshotTaskDeleteSnapshotFail) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2554,9 +2244,7 @@ TEST_F(TestSnapshotCoreImpl, snapInfos.push_back(info2); EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) - .WillOnce(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData1; indexData1.PutChunkDataName(ChunkDataName(fileName, seqNum, 0)); @@ -2564,15 +2252,10 @@ TEST_F(TestSnapshotCoreImpl, indexData2.PutChunkDataName(ChunkDataName(fileName, 1, 1)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) .Times(2) - .WillOnce(DoAll( - SetArgPointee<1>(indexData1), - Return(kErrCodeSuccess))) - .WillOnce(DoAll( - SetArgPointee<1>(indexData2), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData1), Return(kErrCodeSuccess))) + .WillOnce(DoAll(SetArgPointee<1>(indexData2), Return(kErrCodeSuccess))); - EXPECT_CALL(*dataStore_, ChunkDataExist(_)) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*dataStore_, ChunkDataExist(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*dataStore_, DeleteChunkData(_)) .WillRepeatedly(Return(kErrCodeSuccess)); @@ -2609,9 +2292,7 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -2620,9 +2301,8 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -2636,10 +2316,8 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -2649,29 +2327,22 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -2689,16 +2360,13 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -2707,17 +2375,13 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -2732,11 +2396,10 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { EXPECT_CALL(*client_, DeleteSnapshot(fileName, user, seqNum)) .Times(2) .WillOnce(Invoke([task](const std::string &filename, - const std::string &user, - uint64_t seq) -> int { - task->Cancel(); - return kErrCodeSuccess; - })) + const std::string &user, uint64_t seq) -> int { + task->Cancel(); + return kErrCodeSuccess; + })) .WillOnce(Return(LIBCURVE_ERROR::OK)); EXPECT_CALL(*client_, CheckSnapShotStatus(_, _, _, _)) @@ -2764,7 +2427,7 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) { } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskCancelAfterCreateSnapshotOnCurvefs) { + TestHandleCreateSnapshotTaskCancelAfterCreateSnapshotOnCurvefs) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2778,9 +2441,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -2789,14 +2450,13 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); // 此处捕获task,设置cancel EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) - .WillOnce(Invoke([task](const UUID& uuid, CASFunc cas) { + .WillOnce(Invoke([task](const UUID &uuid, CASFunc cas) { task->Cancel(); return kErrCodeSuccess; })); @@ -2818,7 +2478,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskCancelAfterCreateChunkIndexData) { + TestHandleCreateSnapshotTaskCancelAfterCreateChunkIndexData) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2832,9 +2492,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -2843,9 +2501,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -2859,10 +2516,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -2872,37 +2527,30 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); // 此处捕获task,设置cancel EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) - .WillOnce(Invoke([task](const ChunkIndexDataName &name, - const ChunkIndexData &meta) { - task->Cancel(); - return kErrCodeSuccess; - })); + .WillOnce(Invoke( + [task](const ChunkIndexDataName &name, const ChunkIndexData &meta) { + task->Cancel(); + return kErrCodeSuccess; + })); // 进入cancel @@ -2925,7 +2573,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskCancelFailOnDeleteChunkData) { + TestHandleCreateSnapshotTaskCancelFailOnDeleteChunkData) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -2939,9 +2587,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -2950,9 +2596,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, CASSnapshot(_, _)) @@ -2968,10 +2613,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -2981,29 +2624,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -3021,16 +2657,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -3039,17 +2672,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -3063,18 +2692,16 @@ TEST_F(TestSnapshotCoreImpl, // 此处捕获task,设置cancel EXPECT_CALL(*client_, DeleteSnapshot(fileName, user, seqNum)) .WillOnce(Invoke([task](const std::string &filename, - const std::string &user, - uint64_t seq) -> int { - task->Cancel(); - return kErrCodeSuccess; - })); + const std::string &user, uint64_t seq) -> int { + task->Cancel(); + return kErrCodeSuccess; + })); EXPECT_CALL(*client_, CheckSnapShotStatus(_, _, _, _)) .WillRepeatedly(Return(-LIBCURVE_ERROR::NOTEXIST)); // 进入cancel - EXPECT_CALL(*dataStore_, ChunkDataExist(_)) - .WillRepeatedly(Return(true)); + EXPECT_CALL(*dataStore_, ChunkDataExist(_)).WillRepeatedly(Return(true)); EXPECT_CALL(*dataStore_, DeleteChunkData(_)) .WillRepeatedly(Return(kErrCodeInternalError)); @@ -3086,7 +2713,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskCancelFailOnDeleteChunkIndexData) { + TestHandleCreateSnapshotTaskCancelFailOnDeleteChunkIndexData) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -3100,9 +2727,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -3111,9 +2736,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) @@ -3127,10 +2751,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -3140,29 +2762,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -3180,16 +2795,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -3198,17 +2810,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -3222,11 +2830,10 @@ TEST_F(TestSnapshotCoreImpl, // 此处捕获task,设置cancel EXPECT_CALL(*client_, DeleteSnapshot(fileName, user, seqNum)) .WillOnce(Invoke([task](const std::string &filename, - const std::string &user, - uint64_t seq) -> int { - task->Cancel(); - return kErrCodeSuccess; - })); + const std::string &user, uint64_t seq) -> int { + task->Cancel(); + return kErrCodeSuccess; + })); EXPECT_CALL(*client_, CheckSnapShotStatus(_, _, _, _)) .WillRepeatedly(Return(-LIBCURVE_ERROR::NOTEXIST)); @@ -3250,7 +2857,7 @@ TEST_F(TestSnapshotCoreImpl, } TEST_F(TestSnapshotCoreImpl, - TestHandleCreateSnapshotTaskCancelFailOnDeleteSnapshot) { + TestHandleCreateSnapshotTaskCancelFailOnDeleteSnapshot) { UUID uuid = "uuid1"; std::string user = "user1"; std::string fileName = "file1"; @@ -3264,9 +2871,7 @@ TEST_F(TestSnapshotCoreImpl, std::make_shared(info, snapshotInfoMetric); EXPECT_CALL(*client_, CreateSnapshot(fileName, user, _)) - .WillOnce(DoAll( - SetArgPointee<2>(seqNum), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<2>(seqNum), Return(LIBCURVE_ERROR::OK))); FInfo snapInfo; snapInfo.seqnum = 100; @@ -3275,9 +2880,8 @@ TEST_F(TestSnapshotCoreImpl, snapInfo.length = 2 * snapInfo.segmentsize; snapInfo.ctime = 10; EXPECT_CALL(*client_, GetSnapshot(fileName, user, seqNum, _)) - .WillOnce(DoAll( - SetArgPointee<3>(snapInfo), - Return(LIBCURVE_ERROR::OK))); + .WillOnce( + DoAll(SetArgPointee<3>(snapInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*metaStore_, UpdateSnapshot(_)) @@ -3291,10 +2895,8 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId2 = 2; SegmentInfo segInfo1; - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId1, lpid1, cpid1)); - segInfo1.chunkvec.push_back( - ChunkIDInfo(chunkId2, lpid2, cpid2)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId1, lpid1, cpid1)); + segInfo1.chunkvec.push_back(ChunkIDInfo(chunkId2, lpid2, cpid2)); LogicPoolID lpid3 = 3; CopysetID cpid3 = 3; @@ -3304,29 +2906,22 @@ TEST_F(TestSnapshotCoreImpl, ChunkID chunkId4 = 4; SegmentInfo segInfo2; - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId3, lpid3, cpid3)); - segInfo2.chunkvec.push_back( - ChunkIDInfo(chunkId4, lpid4, cpid4)); - - EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, - user, - seqNum, - _, - _)) + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId3, lpid3, cpid3)); + segInfo2.chunkvec.push_back(ChunkIDInfo(chunkId4, lpid4, cpid4)); + + EXPECT_CALL(*client_, GetSnapshotSegmentInfo(fileName, user, seqNum, _, _)) .Times(2) - .WillOnce(DoAll(SetArgPointee<4>(segInfo1), - Return(LIBCURVE_ERROR::OK))) - .WillOnce(DoAll(SetArgPointee<4>(segInfo2), - Return(LIBCURVE_ERROR::OK))); + .WillOnce(DoAll(SetArgPointee<4>(segInfo1), Return(LIBCURVE_ERROR::OK))) + .WillOnce( + DoAll(SetArgPointee<4>(segInfo2), Return(LIBCURVE_ERROR::OK))); uint64_t chunkSn = 100; ChunkInfoDetail chunkInfo; chunkInfo.chunkSn.push_back(chunkSn); EXPECT_CALL(*client_, GetChunkInfo(_, _)) .Times(4) - .WillRepeatedly(DoAll(SetArgPointee<1>(chunkInfo), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(chunkInfo), Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, PutChunkIndexData(_, _)) .WillOnce(Return(kErrCodeSuccess)); @@ -3344,16 +2939,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*metaStore_, GetSnapshotList(fileName, _)) .Times(2) - .WillRepeatedly(DoAll( - SetArgPointee<1>(snapInfos), - Return(kErrCodeSuccess))); + .WillRepeatedly( + DoAll(SetArgPointee<1>(snapInfos), Return(kErrCodeSuccess))); ChunkIndexData indexData; indexData.PutChunkDataName(ChunkDataName(fileName, 1, 0)); EXPECT_CALL(*dataStore_, GetChunkIndexData(_, _)) - .WillOnce(DoAll( - SetArgPointee<1>(indexData), - Return(kErrCodeSuccess))); + .WillOnce(DoAll(SetArgPointee<1>(indexData), Return(kErrCodeSuccess))); EXPECT_CALL(*dataStore_, DataChunkTranferInit(_, _)) .Times(4) @@ -3362,17 +2954,13 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, ReadChunkSnapshot(_, _, _, _, _, _)) .Times(8) - .WillRepeatedly(DoAll( - Invoke([](ChunkIDInfo cidinfo, - uint64_t seq, - uint64_t offset, - uint64_t len, - char *buf, - SnapCloneClosure* scc){ - scc->SetRetCode(LIBCURVE_ERROR::OK); - scc->Run(); - }), - Return(LIBCURVE_ERROR::OK))); + .WillRepeatedly( + DoAll(Invoke([](ChunkIDInfo cidinfo, uint64_t seq, uint64_t offset, + uint64_t len, char *buf, SnapCloneClosure *scc) { + scc->SetRetCode(LIBCURVE_ERROR::OK); + scc->Run(); + }), + Return(LIBCURVE_ERROR::OK))); EXPECT_CALL(*dataStore_, DataChunkTranferAddPart(_, _, _, _, _)) .Times(8) @@ -3387,11 +2975,10 @@ TEST_F(TestSnapshotCoreImpl, EXPECT_CALL(*client_, DeleteSnapshot(fileName, user, seqNum)) .Times(2) .WillOnce(Invoke([task](const std::string &filename, - const std::string &user, - uint64_t seq) -> int { - task->Cancel(); - return kErrCodeSuccess; - })) + const std::string &user, uint64_t seq) -> int { + task->Cancel(); + return kErrCodeSuccess; + })) .WillOnce(Return(LIBCURVE_ERROR::OK)); EXPECT_CALL(*client_, CheckSnapShotStatus(_, _, _, _)) @@ -3420,4 +3007,3 @@ TEST_F(TestSnapshotCoreImpl, } // namespace snapshotcloneserver } // namespace curve -