diff --git a/include/dsn/cpp/pipeline.h b/include/dsn/cpp/pipeline.h index caf73191a4..7689c35e80 100644 --- a/include/dsn/cpp/pipeline.h +++ b/include/dsn/cpp/pipeline.h @@ -290,6 +290,8 @@ struct do_when : when void run(Args &&... args) override { _cb(std::forward(args)...); } + virtual ~do_when() = default; + private: std::function _cb; }; diff --git a/src/aio/native_linux_aio_provider.cpp b/src/aio/native_linux_aio_provider.cpp index d301dfb8c0..c799f7fc9d 100644 --- a/src/aio/native_linux_aio_provider.cpp +++ b/src/aio/native_linux_aio_provider.cpp @@ -38,7 +38,7 @@ native_linux_aio_provider::native_linux_aio_provider(disk_engine *disk) : aio_pr dassert(ret == 0, "io_setup error, ret = %d", ret); _is_running = true; - _worker = std::thread([this, disk]() { + _worker = std::thread([this]() { task::set_tls_dsn_context(node(), nullptr); get_event(); }); diff --git a/src/block_service/block_service_manager.cpp b/src/block_service/block_service_manager.cpp index 5a506d7d94..bcdf94123d 100644 --- a/src/block_service/block_service_manager.cpp +++ b/src/block_service/block_service_manager.cpp @@ -94,7 +94,7 @@ error_code block_service_manager::download_file(const std::string &remote_dir, error_code download_err = ERR_OK; task_tracker tracker; - auto download_file_callback_func = [this, &download_err, &download_file_size]( + auto download_file_callback_func = [&download_err, &download_file_size]( const download_response &resp, block_file_ptr bf, const std::string &local_file_name) { if (resp.err != ERR_OK) { // during bulk load process, ERR_OBJECT_NOT_FOUND will be considered as a recoverable @@ -144,8 +144,7 @@ error_code block_service_manager::download_file(const std::string &remote_dir, download_file_size = resp.downloaded_size; }; - auto create_file_cb = [this, - &local_dir, + auto create_file_cb = [&local_dir, &download_err, &download_file_size, &download_file_callback_func, diff --git a/src/meta/meta_bulk_load_service.cpp b/src/meta/meta_bulk_load_service.cpp index 2c615d9182..e7dbc955a8 100644 --- a/src/meta/meta_bulk_load_service.cpp +++ b/src/meta/meta_bulk_load_service.cpp @@ -11,9 +11,8 @@ namespace dsn { namespace replication { bulk_load_service::bulk_load_service(meta_service *meta_svc, const std::string &bulk_load_dir) - : _meta_svc(meta_svc), _bulk_load_root(bulk_load_dir) + : _meta_svc(meta_svc), _state(meta_svc->get_server_state()), _bulk_load_root(bulk_load_dir) { - _state = _meta_svc->get_server_state(); } // ThreadPool: THREAD_POOL_META_SERVER @@ -1254,14 +1253,14 @@ void bulk_load_service::on_query_bulk_load_status(query_bulk_load_rpc rpc) response.app_status = get_app_bulk_load_status_unlocked(app_id); response.partitions_status.resize(partition_count); - for (const auto kv : _partition_bulk_load_info) { + for (const auto &kv : _partition_bulk_load_info) { if (kv.first.get_app_id() == app_id) { response.partitions_status[kv.first.get_partition_index()] = kv.second.status; } } response.bulk_load_states.resize(partition_count); - for (const auto kv : _partitions_bulk_load_state) { + for (const auto &kv : _partitions_bulk_load_state) { if (kv.first.get_app_id() == app_id) { response.bulk_load_states[kv.first.get_partition_index()] = kv.second; } diff --git a/src/meta/meta_rpc_types.h b/src/meta/meta_rpc_types.h new file mode 100644 index 0000000000..015297529e --- /dev/null +++ b/src/meta/meta_rpc_types.h @@ -0,0 +1,54 @@ +// 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 +#include + +namespace dsn { +namespace replication { + +typedef rpc_holder + app_env_rpc; +typedef rpc_holder ddd_diagnose_rpc; +typedef rpc_holder + app_partition_split_rpc; +typedef rpc_holder + configuration_query_by_node_rpc; +typedef rpc_holder + configuration_query_by_index_rpc; +typedef rpc_holder + configuration_list_apps_rpc; +typedef rpc_holder + configuration_list_nodes_rpc; +typedef rpc_holder + configuration_cluster_info_rpc; +typedef rpc_holder + configuration_balancer_rpc; +typedef rpc_holder + configuration_meta_control_rpc; +typedef rpc_holder + configuration_recovery_rpc; +typedef rpc_holder + configuration_report_restore_status_rpc; +typedef rpc_holder + configuration_query_restore_rpc; + +} // namespace replication +} // namespace dsn diff --git a/src/meta/meta_service.h b/src/meta/meta_service.h index ef7aec6dfd..760a8b84fc 100644 --- a/src/meta/meta_service.h +++ b/src/meta/meta_service.h @@ -42,6 +42,7 @@ #include #include "common/replication_common.h" +#include "meta_rpc_types.h" #include "meta_options.h" #include "meta_backup_service.h" #include "meta_state_service_utils.h" @@ -62,33 +63,6 @@ class test_checker; DEFINE_TASK_CODE(LPC_DEFAULT_CALLBACK, TASK_PRIORITY_COMMON, dsn::THREAD_POOL_DEFAULT) -typedef rpc_holder - app_env_rpc; -typedef rpc_holder ddd_diagnose_rpc; -typedef rpc_holder - app_partition_split_rpc; -typedef rpc_holder - configuration_query_by_node_rpc; -typedef rpc_holder - configuration_query_by_index_rpc; -typedef rpc_holder - configuration_list_apps_rpc; -typedef rpc_holder - configuration_list_nodes_rpc; -typedef rpc_holder - configuration_cluster_info_rpc; -typedef rpc_holder - configuration_balancer_rpc; -typedef rpc_holder - configuration_meta_control_rpc; -typedef rpc_holder - configuration_recovery_rpc; -typedef rpc_holder - configuration_report_restore_status_rpc; -typedef rpc_holder - configuration_query_restore_rpc; - class meta_service : public serverlet { public: diff --git a/src/meta/test/meta_bulk_load_service_test.cpp b/src/meta/test/meta_bulk_load_service_test.cpp index d99fa86681..b929687f95 100644 --- a/src/meta/test/meta_bulk_load_service_test.cpp +++ b/src/meta/test/meta_bulk_load_service_test.cpp @@ -151,7 +151,7 @@ class bulk_load_service_test : public meta_test_base // mock app for (auto &info : app_list) { - mock_app_on_remote_stroage(info); + mock_app_on_remote_storage(info); } state->initialize_data_structure(); @@ -182,7 +182,7 @@ class bulk_load_service_test : public meta_test_base auto app_iter = app_bulk_load_info_map.find(app_id); auto partition_iter = partition_bulk_load_info_map.find(app_id); if (app_iter != app_bulk_load_info_map.end()) { - mock_app_bulk_load_info_on_remote_stroage( + mock_app_bulk_load_info_on_remote_storage( app_iter->second, partition_iter == partition_bulk_load_info_map.end() ? pinfo_map @@ -193,7 +193,7 @@ class bulk_load_service_test : public meta_test_base wait_all(); } - void mock_app_bulk_load_info_on_remote_stroage( + void mock_app_bulk_load_info_on_remote_storage( const app_bulk_load_info &ainfo, const std::unordered_map &partition_bulk_load_info_map) { @@ -210,19 +210,19 @@ class bulk_load_service_test : public meta_test_base app_path, dsn::enum_to_string(ainfo.status)); for (const auto kv : partition_bulk_load_info_map) { - mock_partition_bulk_load_info_on_remote_stroage(gpid(ainfo.app_id, kv.first), + mock_partition_bulk_load_info_on_remote_storage(gpid(ainfo.app_id, kv.first), kv.second); } }); } - void mock_partition_bulk_load_info_on_remote_stroage(const gpid &pid, + void mock_partition_bulk_load_info_on_remote_storage(const gpid &pid, const partition_bulk_load_info &pinfo) { std::string partition_path = bulk_svc().get_partition_bulk_load_path(pid); blob value = json::json_forwarder::encode(pinfo); _ms->get_meta_storage()->create_node( - std::move(partition_path), std::move(value), [this, partition_path, pid, &pinfo]() { + std::move(partition_path), std::move(value), [partition_path, pid, &pinfo]() { ddebug_f("create partition[{}] bulk load dir({}), bulk_load_status={}", pid, partition_path, @@ -230,7 +230,7 @@ class bulk_load_service_test : public meta_test_base }); } - void mock_app_on_remote_stroage(const app_info &info) + void mock_app_on_remote_storage(const app_info &info) { static const char *lock_state = "lock"; static const char *unlock_state = "unlock"; @@ -258,7 +258,7 @@ class bulk_load_service_test : public meta_test_base _app_root + "/" + boost::lexical_cast(info.app_id) + "/" + boost::lexical_cast(i), std::move(v), - [info, i, this]() { + [info, i]() { ddebug_f("create app({}), partition({}.{}) dir succeed", info.app_name, info.app_id, diff --git a/src/replica/duplication/duplication_pipeline.h b/src/replica/duplication/duplication_pipeline.h index 413cfcb200..64738cba68 100644 --- a/src/replica/duplication/duplication_pipeline.h +++ b/src/replica/duplication/duplication_pipeline.h @@ -19,9 +19,9 @@ using namespace literals::chrono_literals; // load_mutation is a pipeline stage for loading mutations, aka mutation_tuple_set, // to the next stage, `ship_mutation`. // ThreadPool: THREAD_POOL_REPLICATION -class load_mutation : public replica_base, - public pipeline::when<>, - public pipeline::result +class load_mutation final : public replica_base, + public pipeline::when<>, + public pipeline::result { public: void run() override; @@ -44,9 +44,9 @@ class load_mutation : public replica_base, // sending them to the remote cluster. After finished, the pipeline // will restart from load_mutation. // ThreadPool: THREAD_POOL_REPLICATION -class ship_mutation : public replica_base, - public pipeline::when, - public pipeline::result<> +class ship_mutation final : public replica_base, + public pipeline::when, + public pipeline::result<> { public: void run(decree &&last_decree, mutation_tuple_set &&in) override; @@ -60,7 +60,7 @@ class ship_mutation : public replica_base, private: void update_progress(); - friend struct ship_mutation_test; + friend class ship_mutation_test; friend class replica_duplicator_test; std::unique_ptr _mutation_duplicator; diff --git a/src/replica/duplication/load_from_private_log.h b/src/replica/duplication/load_from_private_log.h index 38493bb902..e1ae63d42c 100644 --- a/src/replica/duplication/load_from_private_log.h +++ b/src/replica/duplication/load_from_private_log.h @@ -22,9 +22,9 @@ class replica_stub; /// It works in THREAD_POOL_REPLICATION_LONG (LPC_DUPLICATION_LOAD_MUTATIONS), /// which permits tasks to be executed in a blocking way. /// NOTE: The resulted `mutation_tuple_set` may be empty. -class load_from_private_log : public replica_base, - public pipeline::when<>, - public pipeline::result +class load_from_private_log final : public replica_base, + public pipeline::when<>, + public pipeline::result { public: load_from_private_log(replica *r, replica_duplicator *dup); diff --git a/src/replica/duplication/test/duplication_test_base.h b/src/replica/duplication/test/duplication_test_base.h index 5834da72ff..ec02e11f3e 100644 --- a/src/replica/duplication/test/duplication_test_base.h +++ b/src/replica/duplication/test/duplication_test_base.h @@ -59,7 +59,7 @@ class duplication_test_base : public replica_test_base return log_file_map; } - mutation_ptr create_test_mutation(int64_t decree, string_view data) override + mutation_ptr create_test_mutation(int64_t decree, const std::string &data) override { auto mut = replica_test_base::create_test_mutation(decree, data); mut->data.updates[0].code = RPC_DUPLICATION_IDEMPOTENT_WRITE; // must be idempotent write diff --git a/src/replica/duplication/test/ship_mutation_test.cpp b/src/replica/duplication/test/ship_mutation_test.cpp index b9a76ac54a..cc9e77633d 100644 --- a/src/replica/duplication/test/ship_mutation_test.cpp +++ b/src/replica/duplication/test/ship_mutation_test.cpp @@ -16,8 +16,9 @@ struct mock_stage : pipeline::when<> void run() override {} }; -struct ship_mutation_test : public duplication_test_base +class ship_mutation_test : public duplication_test_base { +public: ship_mutation_test() { _replica->init_private_log(_log_dir); diff --git a/src/replica/replica_split.cpp b/src/replica/replica_split.cpp index c2d5797ef6..05fd21167f 100644 --- a/src/replica/replica_split.cpp +++ b/src/replica/replica_split.cpp @@ -353,7 +353,7 @@ error_code replica::child_apply_private_logs(std::vector plog_files // replay private log ec = mutation_log::replay(plog_files, - [this, &plist](int log_length, mutation_ptr &mu) { + [&plist](int log_length, mutation_ptr &mu) { decree d = mu->data.header.decree; if (d <= plist.last_committed_decree()) { return false; diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index c670ec694d..22d3ccd35d 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -702,7 +702,7 @@ void replica_stub::initialize(const replication_options &opts, bool clear /* = f _fs_manager.add_replica(kv.first, kv.second->dir()); } - _nfs = std::move(dsn::nfs_node::create()); + _nfs = dsn::nfs_node::create(); _nfs->start(); dist::cmd::register_remote_command_rpc(); @@ -2732,7 +2732,7 @@ replica_stub::split_replica_exec(dsn::task_code code, gpid pid, local_execution if (replica && handler) { tasking::enqueue(code, replica.get()->tracker(), - [this, handler, replica]() { handler(replica); }, + [handler, replica]() { handler(replica); }, pid.thread_hash()); return ERR_OK; } diff --git a/src/replica/test/mutation_log_test.cpp b/src/replica/test/mutation_log_test.cpp index 207125d861..bf45e372b4 100644 --- a/src/replica/test/mutation_log_test.cpp +++ b/src/replica/test/mutation_log_test.cpp @@ -233,8 +233,8 @@ TEST(replication, log_file) lf->reset_stream(); for (int i = 0; i < 100; i++) { blob bb; - auto err = lf->read_next_log_block(bb); - ASSERT_EQ(ERR_OK, err); + auto err2 = lf->read_next_log_block(bb); + ASSERT_EQ(ERR_OK, err2); binary_reader reader(bb); @@ -280,7 +280,7 @@ class mutation_log_test : public replica_test_base void TearDown() override { utils::filesystem::remove_path(_log_dir); } - mutation_ptr create_test_mutation(const std::string &data, decree d) + mutation_ptr create_test_mutation(decree d, const std::string &data) override { mutation_ptr mu(new mutation()); mu->data.header.ballot = 1; @@ -316,7 +316,7 @@ class mutation_log_test : public replica_test_base mutation_log_ptr mlog = create_private_log(); for (int i = 1; i <= 10; i++) { std::string msg = "hello!"; - mutation_ptr mu = create_test_mutation(msg, 10 * f + i); + mutation_ptr mu = create_test_mutation(10 * f + i, msg); mlog->append(mu, LPC_AIO_IMMEDIATE_CALLBACK, nullptr, nullptr, 0); } mlog->tracker()->wait_outstanding_tasks(); @@ -358,7 +358,7 @@ class mutation_log_test : public replica_test_base mutation_log_ptr mlog = create_private_log(); for (int i = 0; i < num_entries; i++) { - mutation_ptr mu = create_test_mutation("hello!", 2 + i); + mutation_ptr mu = create_test_mutation(2 + i, "hello!"); mutations.push_back(mu); mlog->append(mu, LPC_AIO_IMMEDIATE_CALLBACK, nullptr, nullptr, 0); } @@ -396,7 +396,7 @@ class mutation_log_test : public replica_test_base { // writing logs mutation_log_ptr mlog = create_private_log(private_log_file_size_mb); for (int i = 0; i < num_entries; i++) { - mutation_ptr mu = create_test_mutation("hello!", 2 + i); + mutation_ptr mu = create_test_mutation(2 + i, "hello!"); mutations.push_back(mu); mlog->append(mu, LPC_AIO_IMMEDIATE_CALLBACK, nullptr, nullptr, 0); } @@ -450,7 +450,7 @@ TEST_F(mutation_log_test, open) mutation_log_ptr mlog = create_private_log(4); for (int i = 0; i < 1000; i++) { - mutation_ptr mu = create_test_mutation("hello!", 2 + i); + mutation_ptr mu = create_test_mutation(2 + i, "hello!"); mutations.push_back(mu); mlog->append(mu, LPC_AIO_IMMEDIATE_CALLBACK, nullptr, nullptr, 0); } diff --git a/src/replica/test/replica_test_base.h b/src/replica/test/replica_test_base.h index 7d60f18dd2..a5fb107e34 100644 --- a/src/replica/test/replica_test_base.h +++ b/src/replica/test/replica_test_base.h @@ -55,7 +55,7 @@ struct replica_test_base : replica_stub_test_base replica_test_base() { _replica = create_mock_replica(stub.get(), 1, 1, _log_dir.c_str()); } - virtual mutation_ptr create_test_mutation(int64_t decree, string_view data) + virtual mutation_ptr create_test_mutation(int64_t decree, const std::string &data) { mutation_ptr mu(new mutation()); mu->data.header.ballot = 1; diff --git a/src/utils/test/autoref_ptr_test.cpp b/src/utils/test/autoref_ptr_test.cpp index 66720c6716..fe07110a17 100644 --- a/src/utils/test/autoref_ptr_test.cpp +++ b/src/utils/test/autoref_ptr_test.cpp @@ -135,7 +135,7 @@ TEST(RefCountedUnitTest, TestSelfAssignment) { SelfAssign *p = new SelfAssign; dsn::ref_ptr var(p); - var = var; + // var = var; EXPECT_EQ(var.get(), p); // comment the following two lines because clang compiler would complain with "-Wself-move" // var = std::move(var);