Skip to content

Commit

Permalink
fix review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cw123 committed Dec 10, 2020
1 parent 7971096 commit 8aa01e1
Show file tree
Hide file tree
Showing 59 changed files with 367 additions and 163 deletions.
6 changes: 4 additions & 2 deletions conf/snapshot_clone_server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ server.cloneTempDir=/clone
server.createCloneChunkConcurrency=64
# RecoverChunk同时进行的异步请求数量
server.recoverChunkConcurrency=64
# CloneServiceManager引用计数后台扫描间隔
server.backEndReferenceScanIntervalMs=20
# CloneServiceManager引用计数后台扫描每条记录间隔
server.backEndReferenceRecordScanIntervalMs=500
# CloneServiceManager引用计数后台扫描每轮记录间隔
server.backEndReferenceFuncScanIntervalMs=3600000

#
# etcd相关配置
Expand Down
6 changes: 3 additions & 3 deletions src/chunkserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cc_library(
"//src/chunkserver/raftsnapshot:chunkserver-raft-snapshot",
"//src/chunkserver/raftlog:chunkserver-raft-log",
"//src/common:curve_common",
"//src/common:curve_s3_adapter",
"//src/common/s3_adapter:curve_s3_adapter",
"//src/fs:lfs",
"//src/client:curve_client",
"//include/client:include_client",
Expand Down Expand Up @@ -114,7 +114,7 @@ cc_library(
"//src/chunkserver/raftsnapshot:chunkserver-raft-snapshot",
"//src/chunkserver/raftlog:chunkserver-raft-log",
"//src/common:curve_common",
"//src/common:curve_s3_adapter",
"//src/common/s3_adapter:curve_s3_adapter",
"//src/fs:lfs",
"//src/client:curve_client",
],
Expand Down Expand Up @@ -152,7 +152,7 @@ cc_binary(
"//src/chunkserver/raftsnapshot:chunkserver-raft-snapshot",
"//src/chunkserver/raftlog:chunkserver-raft-log",
"//src/common:curve_common",
"//src/common:curve_s3_adapter",
"//src/common/s3_adapter:curve_s3_adapter",
"//src/fs:lfs",
],
)
2 changes: 1 addition & 1 deletion src/chunkserver/clone_copyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "src/client/libcurve_file.h"
#include "src/client/client_common.h"
#include "include/client/libcurve.h"
#include "src/common/s3_adapter.h"
#include "src/common/s3_adapter/s3_adapter.h"

namespace curve {
namespace chunkserver {
Expand Down
50 changes: 50 additions & 0 deletions src/common/s3_adapter/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright (c) 2020 NetEase Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

COPTS = [
"-DGFLAGS=gflags",
"-DOS_LINUX",
"-DSNAPPY",
"-DHAVE_SSE42",
"-DNDEBUG",
"-fno-omit-frame-pointer",
"-momit-leaf-frame-pointer",
"-msse4.2",
"-pthread",
"-Wsign-compare",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++11",
]

cc_library(
name = "curve_s3_adapter",
srcs = glob([
"s3_adapter.h",
"s3_adapter.cpp",
]),
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"//external:glog",
"//src/common:curve_common",
"@aws",
],
)

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
> Author:
> Created Time: Wed Dec 19 15:19:40 2018
************************************************************************/
#include "src/common/s3_adapter.h"
#include "src/common/s3_adapter/s3_adapter.h"
#include <glog/logging.h>
#include <memory>
#include <sstream>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
> Created Time: Mon Dec 10 14:30:12 2018
************************************************************************/

#ifndef SRC_COMMON_S3_ADAPTER_H_
#define SRC_COMMON_S3_ADAPTER_H_
#ifndef SRC_COMMON_S3_ADAPTER_S3_ADAPTER_H_
#define SRC_COMMON_S3_ADAPTER_S3_ADAPTER_H_
#include <map>
#include <string>
#include <memory>
Expand Down Expand Up @@ -215,4 +215,4 @@ class S3Adapter {
};
} // namespace common
} // namespace curve
#endif // SRC_COMMON_S3_ADAPTER_H_
#endif // SRC_COMMON_S3_ADAPTER_S3_ADAPTER_H_
46 changes: 46 additions & 0 deletions src/common/snapshotclone/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright (c) 2020 NetEase Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

COPTS = [
"-DGFLAGS=gflags",
"-DOS_LINUX",
"-DSNAPPY",
"-DHAVE_SSE42",
"-DNDEBUG",
"-fno-omit-frame-pointer",
"-momit-leaf-frame-pointer",
"-msse4.2",
"-pthread",
"-Wsign-compare",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++11",
]

cc_library(
name = "curve_snapshotclone",
srcs = glob([
"snapshotclone_define.*",
]),
copts = COPTS,
visibility = ["//visibility:public"],
deps = [
"//external:json"
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <json/json.h>

#include "src/common/snapshotclone_define.h"
#include "src/common/snapshotclone/snapshotclone_define.h"

namespace curve {
namespace snapshotcloneserver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
* Author: xuchaojie
*/

#ifndef SRC_COMMON_SNAPSHOTCLONE_DEFINE_H_
#define SRC_COMMON_SNAPSHOTCLONE_DEFINE_H_
#ifndef SRC_COMMON_SNAPSHOTCLONE_SNAPSHOTCLONE_DEFINE_H_
#define SRC_COMMON_SNAPSHOTCLONE_SNAPSHOTCLONE_DEFINE_H_

#include <string>
#include <map>
Expand Down Expand Up @@ -157,4 +157,4 @@ constexpr uint32_t kProgressCloneComplete = 100;
} // namespace snapshotcloneserver
} // namespace curve

#endif // SRC_COMMON_SNAPSHOTCLONE_DEFINE_H_
#endif // SRC_COMMON_SNAPSHOTCLONE_SNAPSHOTCLONE_DEFINE_H_
95 changes: 56 additions & 39 deletions src/mds/nameserver2/curvefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,51 +571,21 @@ StatusCode CurveFS::DeleteFile(const std::string & filename, uint64_t fileId,
} else if (fileInfo.filetype() == FileType::INODE_PAGEFILE) {
StatusCode ret = CheckFileCanChange(filename, fileInfo);
if (ret == StatusCode::kDeleteFileBeingCloned) {
CloneRefStatus refStatus;
std::vector<snapshotcloneclient::DestFileInfo> fileCheckList;
StatusCode ret1 = snapshotCloneClient_->GetCloneRefStatus(filename,
fileInfo.owner(),
&refStatus, &fileCheckList);
bool isHasCloneRely;
StatusCode ret1 = CheckHasCloneRely(filename,
fileInfo.owner(),
&isHasCloneRely);
if (ret1 != StatusCode::kOK) {
LOG(ERROR) << "delete file, check file clone ref fail,"
<< "filename = " << filename
<< ", ret = " << ret1;
return ret1;
}
bool hasCloneRef = false;
if (refStatus == CloneRefStatus::kHasRef) {
hasCloneRef = true;
} else if (refStatus == CloneRefStatus::kNoRef) {
hasCloneRef = false;
} else {
int recordNum = fileCheckList.size();
for (int i = 0; i < recordNum; i++) {
FileInfo destFileInfo;
StatusCode ret2 = GetFileInfo(fileCheckList[i].filename,
&destFileInfo);
if (ret2 == StatusCode::kFileNotExists) {
continue;
}
if (ret2 == StatusCode::kOK) {
if (destFileInfo.id() == fileCheckList[i].inodeid) {
hasCloneRef = true;
break;
} else {
continue;
}
}
LOG(ERROR) << "delete file, check clonefile exist fail"
<< ", filename = " << filename
<< ", clonefile = " << fileCheckList[i].filename
<< ", ret = " << ret2;
return ret2;
}
}
if (hasCloneRef == true) {
LOG(WARNING) << "delete file, can not delete file"
<< ", filename = " << filename
<< ", ret = " << ret;
return ret;

if (isHasCloneRely) {
LOG(WARNING) << "delete file, can not delete file, "
<< "file has clone rely, filename = " << filename;
return StatusCode::kDeleteFileBeingCloned;
}
} else if (ret != StatusCode::kOK) {
LOG(ERROR) << "delete file, can not delete file"
Expand Down Expand Up @@ -1863,6 +1833,53 @@ StatusCode CurveFS::ListClient(bool listAllClient,
return StatusCode::kOK;
}

StatusCode CurveFS::CheckHasCloneRely(const std::string & filename,
const std::string &owner,
bool *isHasCloneRely) {
CloneRefStatus refStatus;
std::vector<snapshotcloneclient::DestFileInfo> fileCheckList;
StatusCode ret = snapshotCloneClient_->GetCloneRefStatus(filename,
owner, &refStatus, &fileCheckList);
if (ret != StatusCode::kOK) {
LOG(ERROR) << "delete file, check file clone ref fail,"
<< "filename = " << filename
<< ", ret = " << ret;
return ret;
}
bool hasCloneRef = false;
if (refStatus == CloneRefStatus::kHasRef) {
hasCloneRef = true;
} else if (refStatus == CloneRefStatus::kNoRef) {
hasCloneRef = false;
} else {
int recordNum = fileCheckList.size();
for (int i = 0; i < recordNum; i++) {
FileInfo destFileInfo;
StatusCode ret2 = GetFileInfo(fileCheckList[i].filename,
&destFileInfo);
if (ret2 == StatusCode::kFileNotExists) {
continue;
}
if (ret2 == StatusCode::kOK) {
if (destFileInfo.id() == fileCheckList[i].inodeid) {
hasCloneRef = true;
break;
} else {
continue;
}
}
LOG(ERROR) << "delete file, check clonefile exist fail"
<< ", filename = " << filename
<< ", clonefile = " << fileCheckList[i].filename
<< ", ret = " << ret2;
return ret2;
}
}

*isHasCloneRely = hasCloneRef;
return StatusCode::kOK;
}

StatusCode CurveFS::FindFileMountPoint(
const std::string& fileName,
ClientInfo* clientInfo) {
Expand Down
11 changes: 11 additions & 0 deletions src/mds/nameserver2/curvefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,17 @@ class CurveFS {
const FileInfo& fileInfo,
uint64_t* fileSize);

/**
* @brief check file has rely dest file
* @param: fileName
* @param: owner
* @param[out]: isCloneHasRely: is clone has rely
* @return StatusCode::kOK if succeeded
*/
StatusCode CheckHasCloneRely(const std::string & filename,
const std::string &owner,
bool *isHasCloneRely);

private:
FileInfo rootFileInfo_;
std::shared_ptr<NameServerStorage> storage_;
Expand Down
2 changes: 1 addition & 1 deletion src/mds/snapshotcloneclient/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cc_library(
"//external:brpc",
"//external:glog",
"//external:json",
"//src/common:curve_snapshotclone",
"//src/common/snapshotclone:curve_snapshotclone",
"//proto:nameserver2_cc_proto",
],
)
2 changes: 1 addition & 1 deletion src/mds/snapshotcloneclient/snapshotclone_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <string>
#include <vector>
#include "src/common/snapshotclone_define.h"
#include "src/common/snapshotclone/snapshotclone_define.h"
#include "proto/nameserver2.pb.h" // for retcode StatusCode

using curve::mds::StatusCode;
Expand Down
8 changes: 4 additions & 4 deletions src/snapshotcloneserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ cc_library(
"//external:json",
"//proto:snapshotcloneserver_cc_proto",
"//src/common:curve_common",
"//src/common:curve_s3_adapter",
"//src/common:curve_snapshotclone",
"//src/common/s3_adapter:curve_s3_adapter",
"//src/common/snapshotclone:curve_snapshotclone",
"//proto:nameserver2_cc_proto",
"//proto:chunkserver-cc-protos",
"//src/client:curve_client",
Expand Down Expand Up @@ -111,8 +111,8 @@ cc_binary(
"//external:json",
"//proto:snapshotcloneserver_cc_proto",
"//src/common:curve_common",
"//src/common:curve_s3_adapter",
"//src/common:curve_snapshotclone",
"//src/common/s3_adapter:curve_s3_adapter",
"//src/common/snapshotclone:curve_snapshotclone",
"//proto:nameserver2_cc_proto",
"//proto:chunkserver-cc-protos",
"//src/client:curve_client",
Expand Down
2 changes: 1 addition & 1 deletion src/snapshotcloneserver/clone/clone_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <memory>

#include "proto/snapshotcloneserver.pb.h"
#include "src/common/snapshotclone_define.h"
#include "src/common/snapshotclone/snapshotclone_define.h"
#include "json/json.h"
#include "src/common/concurrent/name_lock.h"

Expand Down
2 changes: 1 addition & 1 deletion src/snapshotcloneserver/clone/clone_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <list>

#include "src/snapshotcloneserver/common/curvefs_client.h"
#include "src/common/snapshotclone_define.h"
#include "src/common/snapshotclone/snapshotclone_define.h"
#include "src/snapshotcloneserver/common/snapshotclone_meta_store.h"
#include "src/snapshotcloneserver/snapshot/snapshot_data_store.h"
#include "src/snapshotcloneserver/common/snapshot_reference.h"
Expand Down
2 changes: 1 addition & 1 deletion src/snapshotcloneserver/clone/clone_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <map>
#include <string>

#include "src/common/snapshotclone_define.h"
#include "src/common/snapshotclone/snapshotclone_define.h"
#include "src/common/concurrent/concurrent.h"
#include "src/common/concurrent/rw_lock.h"
#include "src/common/concurrent/name_lock.h"
Expand Down
Loading

0 comments on commit 8aa01e1

Please sign in to comment.