Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(disk_balance): close origin replica and update replica dir #668

Merged
merged 104 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
09f8d1e
add status and check
foreverneverer Nov 5, 2020
184cd01
add status and check
foreverneverer Nov 5, 2020
8b3c5de
add status and check
foreverneverer Nov 5, 2020
bdbe60c
init
foreverneverer Nov 5, 2020
4cae974
init
foreverneverer Nov 5, 2020
ceaa229
init
foreverneverer Nov 5, 2020
9c991db
init
foreverneverer Nov 5, 2020
7e1a32a
init
foreverneverer Nov 5, 2020
9919654
init
foreverneverer Nov 6, 2020
d11af56
init
foreverneverer Nov 9, 2020
8a20639
init
foreverneverer Nov 9, 2020
e20dabd
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 9, 2020
4d9c466
init
foreverneverer Nov 9, 2020
e0ad25d
init
foreverneverer Nov 9, 2020
7ebcbdb
upate test
foreverneverer Nov 9, 2020
ac23e6e
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 9, 2020
517f612
refactor
foreverneverer Nov 9, 2020
1c9f422
refactor
foreverneverer Nov 9, 2020
4bc3912
refactor
foreverneverer Nov 9, 2020
8bed904
refactor
foreverneverer Nov 9, 2020
c0acb54
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 9, 2020
57ccf5c
refactor
foreverneverer Nov 9, 2020
2d856c4
refactor
foreverneverer Nov 9, 2020
aa52004
refactor
foreverneverer Nov 9, 2020
08d1668
refactor
foreverneverer Nov 9, 2020
cf2d251
refactor
foreverneverer Nov 9, 2020
4427f30
refactor
foreverneverer Nov 9, 2020
84d0048
refactor
foreverneverer Nov 9, 2020
1b4c499
refactor
foreverneverer Nov 9, 2020
98e191e
refactor
foreverneverer Nov 9, 2020
44a6ff9
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 9, 2020
57a7040
refactor
foreverneverer Nov 9, 2020
8b1016b
refactor
foreverneverer Nov 9, 2020
faac05c
refactor
foreverneverer Nov 9, 2020
864a778
refactor
foreverneverer Nov 9, 2020
8b612f9
refactor
foreverneverer Nov 10, 2020
494b79c
refactor
foreverneverer Nov 10, 2020
628ee2f
refactor
foreverneverer Nov 10, 2020
a2b149e
refactor
foreverneverer Nov 10, 2020
1624659
refactor
foreverneverer Nov 10, 2020
640e990
refactor
foreverneverer Nov 10, 2020
61d4bef
refactor
foreverneverer Nov 10, 2020
a37314b
refactor
foreverneverer Nov 10, 2020
6ca8e90
refactor
foreverneverer Nov 11, 2020
cc56670
refactor
foreverneverer Nov 11, 2020
b8bb0fe
refactor
foreverneverer Nov 11, 2020
dfe25db
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 11, 2020
e395cc9
refactor
foreverneverer Nov 11, 2020
92ff672
refactor
foreverneverer Nov 11, 2020
f6139a3
refactor
foreverneverer Nov 11, 2020
e1d06f0
refactor
foreverneverer Nov 11, 2020
7cbe4a4
refactor
foreverneverer Nov 11, 2020
1a239f0
refactor
foreverneverer Nov 11, 2020
85d772d
refactor
foreverneverer Nov 11, 2020
bf0dbf3
Merge branch 'master' into disk_balance_check
foreverneverer Nov 11, 2020
a5ad732
refactor
foreverneverer Nov 11, 2020
22d8521
refactor
foreverneverer Nov 11, 2020
e8d1786
refactor
foreverneverer Nov 11, 2020
09842fd
test ok
foreverneverer Nov 11, 2020
3bc7660
init
foreverneverer Nov 11, 2020
854cff6
init
foreverneverer Nov 11, 2020
2508a0d
Merge branch 'disk_balance_copy' into disk_balance_close
foreverneverer Nov 11, 2020
56c5880
init
foreverneverer Nov 11, 2020
417ccfd
init
foreverneverer Nov 12, 2020
222e9b7
init
foreverneverer Nov 12, 2020
8914521
delete
foreverneverer Nov 12, 2020
8e28a1c
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 12, 2020
7e0d7b9
Merge branch 'disk_balance_copy' into disk_balance_close
foreverneverer Nov 12, 2020
a862769
delete
foreverneverer Nov 12, 2020
97b53ba
Merge branch 'disk_balance_check' into disk_balance_copy
foreverneverer Nov 12, 2020
28244ef
delete
foreverneverer Nov 12, 2020
960f464
merge
foreverneverer Nov 25, 2020
2acb5c0
merge
foreverneverer Nov 26, 2020
81b1385
merge test
foreverneverer Nov 26, 2020
689e5b3
merge test
foreverneverer Nov 26, 2020
d76e920
merge test
foreverneverer Nov 27, 2020
3508a7f
update merge test 2
foreverneverer Nov 27, 2020
3572a54
update merge test 2
foreverneverer Nov 30, 2020
b5ae7c3
update merge test 2
foreverneverer Nov 30, 2020
76faca3
Merge branch 'master' into disk_balance_close
foreverneverer Nov 30, 2020
669c3e1
update review
foreverneverer Nov 30, 2020
08abc15
Merge branch 'master' of github.com:XiaoMi/rdsn into disk_balance_close
foreverneverer Nov 30, 2020
56d28d5
Merge branch 'disk_balance_close' of github.com:Shuo-Jia/rdsn into di…
foreverneverer Nov 30, 2020
98e84f9
update review
foreverneverer Nov 30, 2020
3c7341a
update review
foreverneverer Nov 30, 2020
c05568c
update review
foreverneverer Nov 30, 2020
bb93a0a
update review
foreverneverer Nov 30, 2020
40ae775
refactor gc
foreverneverer Dec 3, 2020
846d64c
refactor gc
foreverneverer Dec 3, 2020
a46febb
Merge branch 'master' into disk_balance_close
foreverneverer Dec 3, 2020
1a49590
Merge branch 'master' into disk_balance_close
hycdong Dec 7, 2020
b44cd42
fix review
foreverneverer Dec 9, 2020
bea380b
Merge branch 'disk_balance_close' of github.com:Shuo-Jia/rdsn into di…
foreverneverer Dec 9, 2020
88dbc83
fix review
foreverneverer Dec 9, 2020
6d0b3db
fix review
foreverneverer Dec 9, 2020
505b951
fix review
foreverneverer Dec 10, 2020
c4eabea
fix review
foreverneverer Dec 10, 2020
0758af4
fix review
foreverneverer Dec 10, 2020
6bdccd7
init
foreverneverer Dec 11, 2020
a61e211
init
foreverneverer Dec 11, 2020
1c5d527
init
foreverneverer Dec 11, 2020
7503ae0
update review
foreverneverer Feb 1, 2021
c37de7a
update review
foreverneverer Feb 2, 2021
9703915
merge master
foreverneverer Feb 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/fs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <dsn/utility/filesystem.h>
#include <thread>
#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/fail_point.h>

namespace dsn {
namespace replication {
Expand Down Expand Up @@ -76,6 +77,7 @@ unsigned dir_node::remove(const gpid &pid)

void dir_node::update_disk_stat()
{
FAIL_POINT_INJECT_F("mock_dir_node", [](string_view) -> void { return; });
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
dsn::utils::filesystem::disk_space_info info;
if (dsn::utils::filesystem::get_disk_space_info(full_dir, info)) {
disk_capacity_mb = info.capacity / 1024 / 1024;
Expand Down
18 changes: 14 additions & 4 deletions src/replica/replica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,13 @@ bool replica::verbose_commit_log() const { return _stub->_verbose_commit_log; }

void replica::close()
{
dassert(status() == partition_status::PS_ERROR || status() == partition_status::PS_INACTIVE,
"%s: invalid state %s when calling replica::close",
name(),
enum_to_string(status()));
dassert_replica(status() == partition_status::PS_ERROR ||
status() == partition_status::PS_INACTIVE ||
_disk_migrator->status() >= disk_migration_status::MOVED,
"invalid state(partition_status={}, migration_status={}) when calling "
"replica close",
enum_to_string(status()),
enum_to_string(_disk_migrator->status()));
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved

uint64_t start_time = dsn_now_ms();

Expand Down Expand Up @@ -422,6 +425,13 @@ void replica::close()
}
}

if (_disk_migrator->status() == disk_migration_status::MOVED) {
// this will update disk_migration_status::MOVED->disk_migration_status::CLOSED
_disk_migrator->update_replica_dir();
} else if (_disk_migrator->status() == disk_migration_status::CLOSED) {
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
_disk_migrator.reset();
}

_counter_private_log_size.clear();

// duplication_impl may have ongoing tasks.
Expand Down
72 changes: 57 additions & 15 deletions src/replica/replica_disk_migrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace dsn {
namespace replication {

const std::string replica_disk_migrator::kReplicaDirTempSuffix = ".disk.balance.tmp";
const std::string replica_disk_migrator::kReplicaDirOriginSuffix = ".disk.balance.ori";
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
const std::string replica_disk_migrator::kDataDirFolder = "data/rdb/";
const std::string replica_disk_migrator::kAppInfo = ".app-info";

Expand Down Expand Up @@ -58,7 +59,7 @@ void replica_disk_migrator::on_migrate_replica(replica_disk_migrate_rpc rpc)
enum_to_string(disk_migration_status::IDLE),
enum_to_string(status()));

const auto request = rpc.request();
const auto &request = rpc.request();
tasking::enqueue(LPC_REPLICATION_LONG_COMMON, _replica->tracker(), [=]() {
migrate_replica(request);
});
Expand Down Expand Up @@ -171,14 +172,11 @@ bool replica_disk_migrator::check_migration_args(replica_disk_migrate_rpc rpc)
// THREAD_POOL_REPLICATION_LONG
void replica_disk_migrator::migrate_replica(const replica_disk_migrate_request &req)
{
if (status() != disk_migration_status::MOVING) {
derror_replica("disk migration(origin={}, target={}), err = Invalid migration status({})",
req.origin_disk,
req.target_disk,
enum_to_string(status()));
reset_status();
return;
}
dassert_replica(status() == disk_migration_status::MOVING,
"disk migration(origin={}, target={}), err = Invalid migration status({})",
req.origin_disk,
req.target_disk,
enum_to_string(status()));
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved

if (init_target_dir(req) && migrate_replica_checkpoint(req) && migrate_replica_app_info(req)) {
_status = disk_migration_status::MOVED;
Expand All @@ -191,7 +189,7 @@ void replica_disk_migrator::migrate_replica(const replica_disk_migrate_request &
enum_to_string(status()),
_replica->dir());

close_current_replica();
close_current_replica(req);
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -310,12 +308,56 @@ bool replica_disk_migrator::migrate_replica_app_info(const replica_disk_migrate_
return true;
}

// TODO(jiashuo1)
// THREAD_POOL_REPLICATION_LONG
void replica_disk_migrator::close_current_replica() {}
dsn::task_ptr replica_disk_migrator::close_current_replica(const replica_disk_migrate_request &req)
{
if (_replica->status() != partition_status::type::PS_SECONDARY) {
derror_replica("migrate request(origin={}, target={}), err = Invalid partition status({})",
req.origin_disk,
req.target_disk,
enum_to_string(_replica->status()));
reset_status();
utils::filesystem::remove_path(_target_replica_dir);
return nullptr;
}

// TODO(jiashuo1)
// run in replica::close_replica of THREAD_POOL_REPLICATION_LONG
void replica_disk_migrator::update_replica_dir() {}
return _replica->_stub->begin_close_replica(_replica);
}

// run in replica->close_replica() of THREAD_POOL_REPLICATION_LONG
void replica_disk_migrator::update_replica_dir()
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
{
// origin_tmp_dir: /root/origin/gpid.app_type.disk.balance.ori
std::string origin_temp_dir = fmt::format("{}{}", _replica->dir(), kReplicaDirOriginSuffix);
if (!dsn::utils::filesystem::rename_path(_replica->dir(), origin_temp_dir)) {
reset_status();
utils::filesystem::remove_path(_target_replica_dir);
return;
}

std::string target_temp_dir = _target_replica_dir;
// update _target_replica_dir /root/gpid.app_type.disk.balance.tmp/ to
// /root/target/gpid.app_type/
boost::replace_first(_target_replica_dir, kReplicaDirTempSuffix, "");
if (!dsn::utils::filesystem::rename_path(target_temp_dir, _target_replica_dir)) {
reset_status();
// rename failed, delete tmp dir and revert origin dir
utils::filesystem::remove_path(target_temp_dir);
dsn::utils::filesystem::rename_path(origin_temp_dir, _replica->dir());
return;
}

_replica->get_replica_stub()->_fs_manager.remove_replica(get_gpid());
_replica->get_replica_stub()->_fs_manager.add_replica(get_gpid(), _target_replica_dir);
_replica->get_replica_stub()->update_disk_holding_replicas();

_status = disk_migration_status::CLOSED;
ddebug_replica("disk replica migration move data from origin dir({}) to new dir({}) "
"succeed, update status from {}=>{}",
_replica->dir(),
_target_replica_dir,
enum_to_string(disk_migration_status::MOVED),
enum_to_string(status()));
}
} // namespace replication
} // namespace dsn
4 changes: 3 additions & 1 deletion src/replica/replica_disk_migrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ class replica_disk_migrator : replica_base
bool migrate_replica_checkpoint(const replica_disk_migrate_request &req);
bool migrate_replica_app_info(const replica_disk_migrate_request &req);

void close_current_replica();
dsn::task_ptr close_current_replica(const replica_disk_migrate_request &req);
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
void update_replica_dir();

void reset_status() { _status = disk_migration_status::IDLE; }

private:
const static std::string kReplicaDirTempSuffix;
const static std::string kReplicaDirOriginSuffix;
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved
const static std::string kDataDirFolder;
const static std::string kAppInfo;

Expand All @@ -61,6 +62,7 @@ class replica_disk_migrator : replica_base
disk_migration_status::type _status{disk_migration_status::IDLE};

friend class replica;
friend class replica_stub;
friend class replica_disk_migrate_test;
};

Expand Down
3 changes: 3 additions & 0 deletions src/replica/replica_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <dsn/utility/filesystem.h>
#include <dsn/dist/replication/replication_app_base.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/utility/fail_point.h>

namespace dsn {
namespace replication {
Expand Down Expand Up @@ -124,6 +125,8 @@ error_code replica::initialize_on_load()

/*static*/ replica *replica::load(replica_stub *stub, const char *dir)
{
FAIL_POINT_INJECT_F("mock_replica_open", [&](string_view) -> replica * { return nullptr; });
foreverneverer marked this conversation as resolved.
Show resolved Hide resolved

char splitters[] = {'\\', '/', 0};
std::string name = utils::get_last_component(std::string(dir), splitters);
if (name == "") {
Expand Down
Loading