forked from apache/incubator-pegasus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dup_enhancement#11): follower replica add
replica_follower
to …
…support duplicate checkpoint when open replica (apache#1060)
- Loading branch information
1 parent
78aaf35
commit 57e92c3
Showing
19 changed files
with
419 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
#include "replica_follower.h" | ||
#include "replica/replica_stub.h" | ||
#include "dsn/utility/filesystem.h" | ||
#include "dsn/dist/replication/duplication_common.h" | ||
|
||
#include <boost/algorithm/string.hpp> | ||
#include <dsn/tool-api/group_address.h> | ||
#include <dsn/dist/nfs_node.h> | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
replica_follower::replica_follower(replica *r) : replica_base(r), _replica(r) | ||
{ | ||
init_master_info(); | ||
} | ||
|
||
replica_follower::~replica_follower() { _tracker.wait_outstanding_tasks(); } | ||
|
||
void replica_follower::init_master_info() | ||
{ | ||
const auto &envs = _replica->get_app_info()->envs; | ||
|
||
if (envs.find(duplication_constants::kDuplicationEnvMasterClusterKey) == envs.end() || | ||
envs.find(duplication_constants::kDuplicationEnvMasterMetasKey) == envs.end()) { | ||
return; | ||
} | ||
|
||
need_duplicate = true; | ||
|
||
_master_cluster_name = envs.at(duplication_constants::kDuplicationEnvMasterClusterKey); | ||
_master_app_name = _replica->get_app_info()->app_name; | ||
|
||
const auto &meta_list_str = envs.at(duplication_constants::kDuplicationEnvMasterMetasKey); | ||
std::vector<std::string> metas; | ||
boost::split(metas, meta_list_str, boost::is_any_of(",")); | ||
dassert_f(!metas.empty(), "master cluster meta list is invalid!"); | ||
for (const auto &meta : metas) { | ||
dsn::rpc_address node; | ||
dassert_f(node.from_string_ipv4(meta.c_str()), "{} is invalid meta address", meta); | ||
_master_meta_list.emplace_back(std::move(node)); | ||
} | ||
} | ||
|
||
// todo(jiashuo1) | ||
error_code replica_follower::duplicate_checkpoint() { return ERR_OK; } | ||
|
||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
#pragma once | ||
#include "replica/replica.h" | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
class replica_follower : replica_base | ||
{ | ||
public: | ||
explicit replica_follower(replica *r); | ||
~replica_follower(); | ||
error_code duplicate_checkpoint(); | ||
|
||
const std::string &get_master_cluster_name() const { return _master_cluster_name; }; | ||
|
||
const std::string &get_master_app_name() const { return _master_app_name; }; | ||
|
||
const std::vector<rpc_address> &get_master_meta_list() const { return _master_meta_list; }; | ||
|
||
const bool is_need_duplicate() const { return need_duplicate; } | ||
|
||
private: | ||
replica *_replica; | ||
task_tracker _tracker; | ||
|
||
std::string _master_cluster_name; | ||
std::string _master_app_name; | ||
std::vector<rpc_address> _master_meta_list; | ||
|
||
bool need_duplicate{false}; | ||
|
||
void init_master_info(); | ||
|
||
friend class replica_follower_test; | ||
}; | ||
|
||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
|
||
#include <dsn/utility/filesystem.h> | ||
#include <dsn/dist/fmt_logging.h> | ||
|
||
#include "replica/duplication/replica_follower.h" | ||
#include "duplication_test_base.h" | ||
|
||
namespace dsn { | ||
namespace apps { | ||
|
||
} // namespace apps | ||
} // namespace dsn | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
class replica_follower_test : public duplication_test_base | ||
{ | ||
public: | ||
replica_follower_test() | ||
{ | ||
_app_info.app_id = 2; | ||
_app_info.app_name = "follower"; | ||
_app_info.app_type = "replica"; | ||
_app_info.is_stateful = true; | ||
_app_info.max_replica_count = 3; | ||
_app_info.partition_count = 8; | ||
} | ||
|
||
void update_mock_replica(const dsn::app_info &app) | ||
{ | ||
bool is_duplication_follower = | ||
(app.envs.find(duplication_constants::kDuplicationEnvMasterClusterKey) != | ||
app.envs.end()) && | ||
(app.envs.find(duplication_constants::kDuplicationEnvMasterMetasKey) != app.envs.end()); | ||
_mock_replica = stub->generate_replica_ptr( | ||
app, gpid(2, 1), partition_status::PS_PRIMARY, 1, false, is_duplication_follower); | ||
} | ||
|
||
public: | ||
dsn::app_info _app_info; | ||
mock_replica_ptr _mock_replica; | ||
}; | ||
|
||
TEST_F(replica_follower_test, test_init_master_info) | ||
{ | ||
_app_info.envs.emplace(duplication_constants::kDuplicationEnvMasterClusterKey, "master"); | ||
_app_info.envs.emplace(duplication_constants::kDuplicationEnvMasterMetasKey, | ||
"127.0.0.1:34801,127.0.0.2:34801,127.0.0.3:34802"); | ||
update_mock_replica(_app_info); | ||
|
||
auto follower = _mock_replica->get_replica_follower(); | ||
ASSERT_EQ(follower->get_master_app_name(), "follower"); | ||
ASSERT_EQ(follower->get_master_cluster_name(), "master"); | ||
ASSERT_TRUE(follower->is_need_duplicate()); | ||
ASSERT_TRUE(_mock_replica->is_duplication_follower()); | ||
std::vector<std::string> test_ip{"127.0.0.1:34801", "127.0.0.2:34801", "127.0.0.3:34802"}; | ||
for (int i = 0; i < follower->get_master_meta_list().size(); i++) { | ||
ASSERT_EQ(std::string(follower->get_master_meta_list()[i].to_string()), test_ip[i]); | ||
} | ||
|
||
_app_info.envs.clear(); | ||
update_mock_replica(_app_info); | ||
follower = _mock_replica->get_replica_follower(); | ||
ASSERT_FALSE(follower->is_need_duplicate()); | ||
ASSERT_FALSE(_mock_replica->is_duplication_follower()); | ||
} | ||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.