diff --git a/src/shell/commands/duplication.cpp b/src/shell/commands/duplication.cpp index 187cbbc194..7e1ac03498 100644 --- a/src/shell/commands/duplication.cpp +++ b/src/shell/commands/duplication.cpp @@ -119,10 +119,12 @@ void attach_dups_stat(const list_dups_stat &stat, dsn::utils::multi_table_printe { dsn::utils::table_printer printer("summary"); + // Add stats for tables. printer.add_row_name_and_data("total_app_count", stat.total_app_count); printer.add_row_name_and_data("duplicating_app_count", stat.duplicating_app_count); printer.add_row_name_and_data("unfinished_app_count", stat.unfinished_app_count); + // Add stats for duplications. printer.add_row_name_and_data("duplication_count", stat.duplication_count); for (const auto &[status, cnt] : stat.dup_status_stats) { printer.add_row_name_and_data(fmt::format("{}_count", status), cnt); @@ -131,6 +133,7 @@ void attach_dups_stat(const list_dups_stat &stat, dsn::utils::multi_table_printe printer.add_row_name_and_data(fmt::format("{}_count", remote_cluster), cnt); } + // Add stats for partitions. printer.add_row_name_and_data("total_partition_count", stat.total_partition_count); printer.add_row_name_and_data("duplicating_partition_count", stat.duplicating_partition_count); printer.add_row_name_and_data("unfinished_partition_count", stat.unfinished_partition_count); @@ -138,56 +141,75 @@ void attach_dups_stat(const list_dups_stat &stat, dsn::utils::multi_table_printe multi_printer.add(std::move(printer)); } +// Stats for listed duplications. void stat_dups(const std::map &app_states, uint32_t progress_gap, list_dups_stat &stat) { + // Record as the number of all listed tables. stat.total_app_count = app_states.size(); for (const auto &[app_name, app] : app_states) { + // Sum up as the total number of all listed partitions. stat.total_partition_count += app.partition_count; + if (app.duplications.empty()) { + // No need to stat other items since there is no duplications for this table. continue; } + // There's at least 1 duplication for this table. Sum up for duplicating tables + // with all partitions of each table marked as duplicating. ++stat.duplicating_app_count; stat.duplicating_partition_count += app.partition_count; + // Use individual variables as counter for "unfinished" tables and partitions in + // case one stat is calculated multiple times. Record 1 as the table and partition + // are "unfinished", while keeping 0 as both are "finished".Initialize all of them + // with 0 to sum up later. size_t unfinished_app_counter = 0; std::vector unfinished_partition_counters(app.partition_count); for (const auto &[dup_id, dup] : app.duplications) { + // Count for all duplication-level stats. ++stat.duplication_count; ++stat.dup_status_stats[dsn::replication::duplication_status_to_string(dup.status)]; ++stat.dup_remote_cluster_stats[dup.remote]; if (!dup.__isset.partition_states) { + // Partition-level states are not set. Only to be compatible with old version + // where there is no this field for duplication entry. continue; } for (const auto &[partition_id, partition_state] : dup.partition_states) { if (partition_state.last_committed_decree < partition_state.confirmed_decree) { + // This is unlikely to happen. continue; } if (partition_state.last_committed_decree - partition_state.confirmed_decree <= progress_gap) { + // This partition is defined as "finished". continue; } + // Just assign with 1 to dedup, in case calculated multiple times. unfinished_app_counter = 1; - CHECK_LT(partition_id, unfinished_partition_counters.size()); unfinished_partition_counters[partition_id] = 1; + // Record the partitions that are still "unfinished". stat.unfinished_apps[app_name][dup_id].insert(partition_id); } } + // Sum up for each "unfinished" partition. for (const auto &counter : unfinished_partition_counters) { stat.unfinished_partition_count += counter; } + // Sum up if table is "unfinished". stat.unfinished_app_count += unfinished_app_counter; } } diff --git a/src/shell/commands/node_management.cpp b/src/shell/commands/node_management.cpp index 8d473252bf..109a8b1ccc 100644 --- a/src/shell/commands/node_management.cpp +++ b/src/shell/commands/node_management.cpp @@ -617,7 +617,7 @@ bool ls_nodes(command_executor *, shell_context *sc, arguments args) } // print configuration_list_nodes_response - std::streambuf *buf; + std::streambuf *buf = nullptr; std::ofstream of; // TODO(wangdan): use dsn::utils::output() in output_utils.h instead. diff --git a/src/utils/output_utils.cpp b/src/utils/output_utils.cpp index dfaa799633..057304f2d8 100644 --- a/src/utils/output_utils.cpp +++ b/src/utils/output_utils.cpp @@ -17,7 +17,7 @@ #include "utils/output_utils.h" -#include +#include // IWYU pragma: no_include #include diff --git a/src/utils/output_utils.h b/src/utils/output_utils.h index ca90e1ba6f..0950f92ddc 100644 --- a/src/utils/output_utils.h +++ b/src/utils/output_utils.h @@ -21,7 +21,6 @@ #include #include #include // IWYU pragma: keep -#include #include #include #include