Skip to content

Commit e39b156

Browse files
author
lixiaocui1
committed
将chunk回收到chunkpool中
Change-Id: I752418f4ba3976d082a68eb645f0d1eb1e71283c
1 parent 4944459 commit e39b156

14 files changed

+895
-12
lines changed

conf/chunkserver.conf.example

+6
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ chunkfilepool.chunk_file_pool_dir=./0/
8686
#chunkfilepool.meta_path=./chunkfilepool.meta
8787
chunkfilepool.cpmeta_file_size=4096
8888
chunkfilepool.retry_times=5
89+
90+
#
91+
# trash settings
92+
#
93+
trash.expire_afterSec=86400
94+
trash.scan_periodSec=3600

deploy/local/chunkserver/conf/chunkserver.conf.0

+6
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ chunkfilepool.chunk_file_pool_dir=./0/chunkfilepool/
8686
chunkfilepool.meta_path=./0/chunkfilepool.meta
8787
chunkfilepool.cpmeta_file_size=4096
8888
chunkfilepool.retry_times=5
89+
90+
#
91+
# trash settings
92+
#
93+
trash.expire_afterSec=120
94+
trash.scan_periodSec=60

deploy/local/chunkserver/conf/chunkserver.conf.1

+6
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ chunkfilepool.chunk_file_pool_dir=./1/chunkfilepool/
8686
chunkfilepool.meta_path=./1/chunkfilepool.meta
8787
chunkfilepool.cpmeta_file_size=4096
8888
chunkfilepool.retry_times=5
89+
90+
#
91+
# trash settings
92+
#
93+
trash.expire_afterSec=120
94+
trash.scan_periodSec=60

deploy/local/chunkserver/conf/chunkserver.conf.2

+5
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ chunkfilepool.meta_path=./2/chunkfilepool.meta
8787
chunkfilepool.cpmeta_file_size=4096
8888
chunkfilepool.retry_times=5
8989

90+
#
91+
# trash settings
92+
#
93+
trash.expire_afterSec=120
94+
trash.scan_periodSec=60

src/chunkserver/chunkserver.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#define SRC_CHUNKSERVER_CHUNKSERVER_H_
1010

1111
#include <string>
12+
#include <memory>
1213
#include "src/common/configuration.h"
1314
#include "src/chunkserver/copyset_node_manager.h"
1415
#include "src/chunkserver/heartbeat.h"
1516
#include "src/chunkserver/clone_manager.h"
1617
#include "src/chunkserver/register.h"
18+
#include "src/chunkserver/trash.h"
1719

1820
namespace curve {
1921
namespace chunkserver {
@@ -53,6 +55,9 @@ class ChunkServer {
5355
void InitRegisterOptions(common::Configuration *conf,
5456
RegisterOptions *registerOptions);
5557

58+
void InitTrashOptions(common::Configuration *conf,
59+
TrashOptions *trashOptions);
60+
5661
int GetChunkServerMetaFromLocal(const std::string &storeUri,
5762
const std::string &metaUri,
5863
const std::shared_ptr<LocalFileSystem> &fs,
@@ -65,10 +70,17 @@ class ChunkServer {
6570
// false-停止运行
6671
volatile bool toStop_;
6772

68-
// chunkserver包含的模块
73+
// copysetNodeManager_ 管理chunkserver上所有copysetNode
6974
CopysetNodeManager copysetNodeManager_;
75+
76+
// cloneManager_ 管理克隆任务
7077
CloneManager cloneManager_;
78+
79+
// heartbeat_ 负责向mds定期发送心跳,并下发心跳中任务
7180
Heartbeat heartbeat_;
81+
82+
// trash_ 定期回收垃圾站中的物理空间
83+
std::shared_ptr<Trash> trash_;
7284
};
7385

7486
} // namespace chunkserver

src/chunkserver/config_info.h

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <string>
1212

1313
#include "src/fs/local_filesystem.h"
14+
#include "src/chunkserver/trash.h"
1415

1516
namespace curve {
1617
namespace chunkserver {
@@ -75,6 +76,10 @@ struct CopysetNodeOptions {
7576
std::shared_ptr<ChunkfilePool> chunkfilePool;
7677
// 文件系统适配层
7778
std::shared_ptr<LocalFileSystem> localFileSystem;
79+
// 回收站, 心跳模块判断该chunkserver不在copyset配置组时,
80+
// 通知copysetManager将copyset目录移动至回收站
81+
// 一段时间后实际回收物理空间
82+
std::shared_ptr<Trash> trash;
7883

7984
CopysetNodeOptions();
8085
};

src/chunkserver/copyset_node.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ class CopysetNode : public braft::StateMachine,
127127
*/
128128
CopysetID GetCopysetId() const;
129129

130+
/**
131+
* 返回复制组数据目录
132+
* @return
133+
*/
134+
std::string GetCopysetDir() const;
135+
130136
/**
131137
* 返回当前副本是否在leader任期
132138
* @return
@@ -225,12 +231,6 @@ class CopysetNode : public braft::StateMachine,
225231
*/
226232
virtual void Propose(const braft::Task &task);
227233

228-
/**
229-
* 删除复制组持久化数据
230-
* @return
231-
*/
232-
int RemoveCopysetData();
233-
234234
/**
235235
* 获取复制组成员
236236
* @param peers:返回的成员列表(输出参数)
@@ -386,6 +386,8 @@ class CopysetNode : public braft::StateMachine,
386386
std::string chunkDataApath_;
387387
// chunk file的相对目录
388388
std::string chunkDataRpath_;
389+
// copyset绝对路径
390+
std::string copysetDirPath_;
389391
// 文件系统适配器
390392
std::shared_ptr<LocalFileSystem> fs_;
391393
// Chunk持久化操作接口

src/chunkserver/copyset_node_manager.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -244,23 +244,24 @@ bool CopysetNodeManager::DeleteCopysetNode(const LogicPoolID &logicPoolId,
244244

245245
bool CopysetNodeManager::PurgeCopysetNodeData(const LogicPoolID &logicPoolId,
246246
const CopysetID &copysetId) {
247-
bool ret = false;
248247
/* 加写锁 */
249248
WriteLockGuard writeLockGuard(rwLock_);
250249
GroupId groupId = ToGroupId(logicPoolId, copysetId);
251250
auto it = copysetNodeMap_.find(groupId);
252251
if (copysetNodeMap_.end() != it) {
253252
it->second->Fini();
254-
if (0 != it->second->RemoveCopysetData()) {
253+
if (0 != copysetNodeOptions_.trash->RecycleCopySet(
254+
it->second->GetCopysetDir())) {
255255
LOG(ERROR) << "Failed to remove copyset <" << logicPoolId
256256
<< ", " << copysetId << "> persistently";
257-
ret = false;
257+
return false;
258258
}
259259
copysetNodeMap_.erase(it);
260-
ret = true;
260+
LOG(INFO) << "Success to remove copyset <" << logicPoolId
261+
<< ", " << copysetId << "> to trash";
261262
}
262263

263-
return ret;
264+
return true;
264265
}
265266

266267
bool CopysetNodeManager::IsExist(const LogicPoolID &logicPoolId,

0 commit comments

Comments
 (0)