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

Commit

Permalink
refactor: move func get_current_cluster_name out of duplication_commo…
Browse files Browse the repository at this point in the history
…n.h (#992)
  • Loading branch information
levy5307 authored Dec 24, 2021
1 parent af568d8 commit 24bf381
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 21 deletions.
28 changes: 28 additions & 0 deletions include/dsn/dist/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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

namespace dsn {
/// Returns the cluster name (i.e, "onebox") if it's configured under
/// "replication" section:
/// [replication]
/// cluster_name = "onebox"
extern const char *get_current_cluster_name();
} // namespace dsn
6 changes: 0 additions & 6 deletions include/dsn/dist/replication/duplication_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ inline bool is_duplication_status_valid(duplication_status::type status)
return status == duplication_status::DS_PAUSE || status == duplication_status::DS_START;
}

/// Returns the cluster name (i.e, "onebox") if it's configured under
/// "replication" section:
/// [replication]
/// cluster_name = "onebox"
extern const char *get_current_cluster_name();

/// Returns the cluster id of url specified in the duplication-group section
/// of your configuration, for example:
///
Expand Down
29 changes: 29 additions & 0 deletions src/common/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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/dist/common.h>
#include <dsn/utility/flags.h>

namespace dsn {
DSN_DEFINE_string("replication", cluster_name, "", "name of this cluster");

/*extern*/ const char *get_current_cluster_name()
{
dassert(strlen(FLAGS_cluster_name) != 0, "cluster_name is not set");
return FLAGS_cluster_name;
}
} // namespace dsn
9 changes: 0 additions & 9 deletions src/common/duplication_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
#include <dsn/utility/singleton.h>
#include <dsn/utils/time_utils.h>
#include <nlohmann/json.hpp>
#include <dsn/utility/flags.h>

namespace dsn {
namespace replication {
DSN_DEFINE_string("replication", cluster_name, "", "name of this cluster");

/*extern*/ const char *duplication_status_to_string(duplication_status::type status)
{
auto it = _duplication_status_VALUES_TO_NAMES.find(status);
Expand All @@ -45,12 +42,6 @@ DSN_DEFINE_string("replication", cluster_name, "", "name of this cluster");
return it->second;
}

/*extern*/ const char *get_current_cluster_name()
{
dassert(strlen(FLAGS_cluster_name) != 0, "cluster_name is not set");
return FLAGS_cluster_name;
}

namespace internal {

class duplication_group_registry : public utils::singleton<duplication_group_registry>
Expand Down
7 changes: 7 additions & 0 deletions src/common/replication_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
namespace dsn {
namespace replication {

/**
* TODO:
* According to the name of this file, it's should be used for a common file about replication.
* But now we put a lot of classes and types which have nothing to do with replication into it.
* So, it's better to refactor it later.
**/

typedef std::unordered_map<::dsn::rpc_address, partition_status::type> node_statuses;
typedef std::unordered_map<::dsn::rpc_address, dsn::task_ptr> node_tasks;

Expand Down
28 changes: 28 additions & 0 deletions src/common/test/common_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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/dist/common.h>
#include <gtest/gtest.h>

namespace dsn {
TEST(duplication_common, get_current_cluster_name)
{
ASSERT_STREQ(get_current_cluster_name(), "master-cluster");
}
} // namespace dsn
5 changes: 0 additions & 5 deletions src/common/test/duplication_common_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ TEST(duplication_common, get_duplication_cluster_id)
ASSERT_EQ(get_duplication_cluster_id("unknown").get_error().code(), ERR_OBJECT_NOT_FOUND);
}

TEST(duplication_common, get_current_cluster_name)
{
ASSERT_STREQ(get_current_cluster_name(), "master-cluster");
}

TEST(duplication_common, get_distinct_cluster_id_set)
{
ASSERT_EQ(get_distinct_cluster_id_set(), std::set<uint8_t>({1, 2}));
Expand Down
1 change: 1 addition & 0 deletions src/meta/duplication/meta_duplication_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <dsn/dist/replication/duplication_common.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/dist/common.h>
#include <dsn/utility/chrono_literals.h>
#include <dsn/utility/string_conv.h>

Expand Down
2 changes: 1 addition & 1 deletion src/meta/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <dsn/utility/extensible_object.h>
#include <dsn/utility/string_conv.h>
#include <dsn/dist/meta_state_service.h>
#include <dsn/dist/replication/duplication_common.h>
#include <dsn/dist/common.h>
#include <dsn/dist/remote_command.h>
#include <dsn/tool-api/command_manager.h>
#include <algorithm> // for std::remove_if
Expand Down
1 change: 1 addition & 0 deletions src/meta/test/meta_duplication_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <gtest/gtest.h>
#include <dsn/dist/fmt_logging.h>
#include <dsn/dist/common.h>
#include <dsn/utils/time_utils.h>

#include "meta/server_load_balancer.h"
Expand Down

0 comments on commit 24bf381

Please sign in to comment.