Skip to content

Commit ac96f57

Browse files
wangguangshuolimowang
authored andcommitted
refactor(FQDN): feather refactor on shell side
1 parent cb40b23 commit ac96f57

File tree

6 files changed

+106
-52
lines changed

6 files changed

+106
-52
lines changed

src/rpc/rpc_host_port.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class TProtocol;
7373
} else { \
7474
_target.reserve(_obj.field.size()); \
7575
for (const auto &addr : _obj.field) { \
76-
_target.emplace_back(host_port::from_address(addr)); \
76+
_target.emplace_back(dsn::host_port::from_address(addr)); \
7777
} \
7878
} \
7979
} while (0)

src/shell/command_helper.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,10 @@ inline std::unique_ptr<aggregate_stats_calcs> create_table_aggregate_stats_calcs
16921692
row.app_id);
16931693

16941694
for (const auto &pc : iter->second) {
1695-
if (pc.hp_primary != node) {
1695+
dsn::host_port primary;
1696+
GET_HOST_PORT(pc, primary, primary);
1697+
1698+
if (primary != node) {
16961699
// Ignore once the replica of the metrics is not the primary of the partition.
16971700
continue;
16981701
}
@@ -1723,7 +1726,10 @@ create_partition_aggregate_stats_calcs(const int32_t table_id,
17231726
partition_stat_map increases;
17241727
partition_stat_map rates;
17251728
for (size_t i = 0; i < rows.size(); ++i) {
1726-
if (pcs[i].hp_primary != node) {
1729+
dsn::host_port primary;
1730+
GET_HOST_PORT(pcs[i], primary, primary);
1731+
1732+
if (primary != node) {
17271733
// Ignore once the replica of the metrics is not the primary of the partition.
17281734
continue;
17291735
}
@@ -1979,12 +1985,16 @@ inline bool get_app_partition_stat(shell_context *sc,
19791985
m.name, app_id_x, partition_index_x, counter_name)) {
19801986
// only primary partition will be counted
19811987
const auto find = pcs_by_appid.find(app_id_x);
1982-
if (find != pcs_by_appid.end() &&
1983-
find->second[partition_index_x].hp_primary == nodes[i].hp) {
1984-
row_data &row = rows[app_id_name[app_id_x]][partition_index_x];
1985-
row.row_name = std::to_string(partition_index_x);
1986-
row.app_id = app_id_x;
1987-
update_app_pegasus_perf_counter(row, counter_name, m.value);
1988+
if (find != pcs_by_appid.end()) {
1989+
dsn::host_port primary;
1990+
GET_HOST_PORT(find->second[partition_index_x], primary, primary);
1991+
1992+
if (primary == nodes[i].hp) {
1993+
row_data &row = rows[app_id_name[app_id_x]][partition_index_x];
1994+
row.row_name = std::to_string(partition_index_x);
1995+
row.app_id = app_id_x;
1996+
update_app_pegasus_perf_counter(row, counter_name, m.value);
1997+
}
19881998
}
19891999
} else if (parse_app_perf_counter_name(m.name, app_name, counter_name)) {
19902000
// if the app_name from perf-counter isn't existed(maybe the app was dropped), it
@@ -2233,8 +2243,13 @@ inline bool get_storage_size_stat(shell_context *sc, app_storage_size_stat &st_s
22332243
if (find == pcs_by_appid.end()) // app id not found
22342244
continue;
22352245
auto &pc = find->second[partition_index_x];
2236-
if (pc.hp_primary != nodes[i].hp) // not primary replica
2246+
2247+
dsn::host_port primary;
2248+
GET_HOST_PORT(pc, primary, primary);
2249+
2250+
if (primary != nodes[i].hp) { // not primary replica
22372251
continue;
2252+
}
22382253
if (pc.partition_flags != 0) // already calculated
22392254
continue;
22402255
pc.partition_flags = 1;

src/shell/commands/data_operations.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,10 @@ create_rdb_estimated_keys_stats_calcs(const int32_t table_id,
22402240

22412241
partition_stat_map sums;
22422242
for (size_t i = 0; i < rows.size(); ++i) {
2243-
if (pcs[i].hp_primary != node) {
2243+
dsn::host_port primary;
2244+
GET_HOST_PORT(pcs[i], primary, primary);
2245+
2246+
if (primary != node) {
22442247
// Ignore once the replica of the metrics is not the primary of the partition.
22452248
continue;
22462249
}
@@ -2885,9 +2888,15 @@ bool calculate_hash_value(command_executor *e, shell_context *sc, arguments args
28852888
tp.add_row_name_and_data("partition_index", partition_index);
28862889
if (pcs.size() > partition_index) {
28872890
const auto &pc = pcs[partition_index];
2888-
tp.add_row_name_and_data("primary", pc.hp_primary.to_string());
2889-
tp.add_row_name_and_data("secondaries",
2890-
fmt::format("{}", fmt::join(pc.hp_secondaries, ",")));
2891+
2892+
dsn::host_port primary;
2893+
GET_HOST_PORT(pc, primary, primary);
2894+
2895+
std::vector<dsn::host_port> secondaries;
2896+
GET_HOST_PORTS(pc, secondaries, secondaries);
2897+
2898+
tp.add_row_name_and_data("primary", primary.to_string());
2899+
tp.add_row_name_and_data("secondaries", fmt::format("{}", fmt::join(secondaries, ",")));
28912900
}
28922901
}
28932902
tp.output(std::cout);

src/shell/commands/node_management.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,19 @@ bool ls_nodes(command_executor *, shell_context *sc, arguments args)
556556
}
557557

558558
for (const auto &pc : pcs) {
559-
if (pc.hp_primary) {
560-
auto find = tmp_map.find(pc.hp_primary);
559+
dsn::host_port primary;
560+
GET_HOST_PORT(pc, primary, primary);
561+
562+
std::vector<dsn::host_port> secondaries;
563+
GET_HOST_PORTS(pc, secondaries, secondaries);
564+
565+
if (primary) {
566+
auto find = tmp_map.find(primary);
561567
if (find != tmp_map.end()) {
562568
find->second.primary_count++;
563569
}
564570
}
565-
for (const auto &secondary : pc.hp_secondaries) {
571+
for (const auto &secondary : secondaries) {
566572
auto find = tmp_map.find(secondary);
567573
if (find != tmp_map.end()) {
568574
find->second.secondary_count++;

src/shell/commands/recovery.cpp

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,23 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
166166

167167
dsn::host_port diagnose_recommend(const dsn::replication::ddd_partition_info &pinfo)
168168
{
169-
if (pinfo.config.hp_last_drops.size() < 2) {
169+
std::vector<dsn::host_port> last_drops;
170+
GET_HOST_PORTS(pinfo.config, last_drops, last_drops);
171+
172+
if (last_drops.size() < 2) {
170173
return dsn::host_port();
171174
}
172175

173-
std::vector<dsn::host_port> last_two_nodes(pinfo.config.hp_last_drops.end() - 2,
174-
pinfo.config.hp_last_drops.end());
176+
std::vector<dsn::host_port> last_two_nodes(last_drops.end() - 2, last_drops.end());
175177
std::vector<dsn::replication::ddd_node_info> last_dropped;
176178
for (const auto &node : last_two_nodes) {
177-
const auto it = std::find_if(
178-
pinfo.dropped.begin(),
179-
pinfo.dropped.end(),
180-
[&node](const dsn::replication::ddd_node_info &r) { return r.hp_node == node; });
179+
const auto it = std::find_if(pinfo.dropped.begin(),
180+
pinfo.dropped.end(),
181+
[&node](const dsn::replication::ddd_node_info &r) {
182+
dsn::host_port hp_node;
183+
GET_HOST_PORT(r, node, hp_node);
184+
return hp_node == node;
185+
});
181186
if (it->is_alive && it->is_collected) {
182187
last_dropped.push_back(*it);
183188
}
@@ -186,7 +191,9 @@ dsn::host_port diagnose_recommend(const dsn::replication::ddd_partition_info &pi
186191
if (last_dropped.size() == 1) {
187192
const auto &ninfo = last_dropped.back();
188193
if (ninfo.last_committed_decree >= pinfo.config.last_committed_decree) {
189-
return ninfo.hp_node;
194+
dsn::host_port node;
195+
GET_HOST_PORT(ninfo, node, node);
196+
return node;
190197
}
191198
} else if (last_dropped.size() == 2) {
192199
const auto &secondary = last_dropped.front();
@@ -196,19 +203,24 @@ dsn::host_port diagnose_recommend(const dsn::replication::ddd_partition_info &pi
196203
// - choose the node with the largest last committed decree
197204
// - if last committed decree is the same, choose node with the largest ballot
198205

206+
dsn::host_port latest_node;
207+
dsn::host_port secondary_node;
208+
GET_HOST_PORT(latest, node, latest_node);
209+
GET_HOST_PORT(secondary, node, secondary_node);
210+
199211
if (latest.last_committed_decree == secondary.last_committed_decree &&
200212
latest.last_committed_decree >= pinfo.config.last_committed_decree) {
201-
return latest.ballot >= secondary.ballot ? latest.hp_node : secondary.hp_node;
213+
return latest.ballot >= secondary.ballot ? latest_node : secondary_node;
202214
}
203215

204216
if (latest.last_committed_decree > secondary.last_committed_decree &&
205217
latest.last_committed_decree >= pinfo.config.last_committed_decree) {
206-
return latest.hp_node;
218+
return latest_node;
207219
}
208220

209221
if (secondary.last_committed_decree > latest.last_committed_decree &&
210222
secondary.last_committed_decree >= pinfo.config.last_committed_decree) {
211-
return secondary.hp_node;
223+
return secondary_node;
212224
}
213225
}
214226

@@ -293,43 +305,49 @@ bool ddd_diagnose(command_executor *e, shell_context *sc, arguments args)
293305
out << " config: ballot(" << pinfo.config.ballot << "), "
294306
<< "last_committed(" << pinfo.config.last_committed_decree << ")" << std::endl;
295307
out << " ----" << std::endl;
296-
dsn::host_port latest_dropped, secondary_latest_dropped;
297-
if (pinfo.config.hp_last_drops.size() > 0) {
298-
latest_dropped = pinfo.config.hp_last_drops[pinfo.config.hp_last_drops.size() - 1];
308+
309+
std::vector<dsn::host_port> last_drops;
310+
GET_HOST_PORTS(pinfo.config, last_drops, last_drops);
311+
312+
dsn::host_port latest_dropped;
313+
dsn::host_port secondary_latest_dropped;
314+
if (!last_drops.empty()) {
315+
latest_dropped = last_drops[last_drops.size() - 1];
299316
}
300-
if (pinfo.config.hp_last_drops.size() > 1) {
301-
secondary_latest_dropped =
302-
pinfo.config.hp_last_drops[pinfo.config.hp_last_drops.size() - 2];
317+
if (last_drops.size() > 1) {
318+
secondary_latest_dropped = last_drops[last_drops.size() - 2];
303319
}
304320
int j = 0;
305321
for (const dsn::replication::ddd_node_info &n : pinfo.dropped) {
306-
dsn::host_port hp_node;
307-
GET_HOST_PORT(n, node, hp_node);
322+
dsn::host_port node;
323+
GET_HOST_PORT(n, node, node);
308324
char time_buf[30] = {0};
309325
::dsn::utils::time_ms_to_string(n.drop_time_ms, time_buf);
310326
out << " dropped[" << j++ << "]: "
311-
<< "node(" << hp_node << "), "
327+
<< "node(" << node << "), "
312328
<< "drop_time(" << time_buf << "), "
313329
<< "alive(" << (n.is_alive ? "true" : "false") << "), "
314330
<< "collected(" << (n.is_collected ? "true" : "false") << "), "
315331
<< "ballot(" << n.ballot << "), "
316332
<< "last_committed(" << n.last_committed_decree << "), "
317333
<< "last_prepared(" << n.last_prepared_decree << ")";
318-
if (hp_node == latest_dropped)
334+
if (node == latest_dropped) {
319335
out << " <== the latest";
320-
else if (hp_node == secondary_latest_dropped)
336+
} else if (node == secondary_latest_dropped) {
321337
out << " <== the secondary latest";
338+
}
322339
out << std::endl;
323340
}
324341
out << " ----" << std::endl;
325342
j = 0;
326-
for (const auto &r : pinfo.config.hp_last_drops) {
343+
for (const auto &r : last_drops) {
327344
out << " last_drops[" << j++ << "]: "
328345
<< "node(" << r.to_string() << ")";
329-
if (j == (int)pinfo.config.hp_last_drops.size() - 1)
346+
if (j == static_cast<int>(last_drops.size()) - 1) {
330347
out << " <== the secondary latest";
331-
else if (j == (int)pinfo.config.hp_last_drops.size())
348+
} else if (j == static_cast<int>(last_drops.size())) {
332349
out << " <== the latest";
350+
}
333351
out << std::endl;
334352
}
335353
out << " ----" << std::endl;

src/shell/commands/table_management.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,17 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
341341
double disk_used_for_all_replicas = 0;
342342
int all_replicas_count = 0;
343343
for (const auto &pc : pcs) {
344+
dsn::host_port primary;
345+
GET_HOST_PORT(pc, primary, primary);
346+
347+
std::vector<dsn::host_port> secondaries;
348+
GET_HOST_PORTS(pc, secondaries, secondaries);
349+
344350
std::string primary_str("-");
345-
if (pc.hp_primary) {
351+
if (primary) {
346352
bool disk_found = false;
347353
double disk_value = 0;
348-
auto f1 = disk_map.find(pc.hp_primary);
354+
auto f1 = disk_map.find(primary);
349355
if (f1 != disk_map.end()) {
350356
auto &sub_map = f1->second;
351357
auto f2 = sub_map.find(pc.pid.get_partition_index());
@@ -360,7 +366,7 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
360366
}
361367
bool count_found = false;
362368
double count_value = 0;
363-
auto f3 = count_map.find(pc.hp_primary);
369+
auto f3 = count_map.find(primary);
364370
if (f3 != count_map.end()) {
365371
auto &sub_map = f3->second;
366372
auto f4 = sub_map.find(pc.pid.get_partition_index());
@@ -372,7 +378,7 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
372378

373379
// TODO(wangdan): refactor as format style.
374380
std::stringstream oss;
375-
oss << pc.hp_primary.resolve(resolve_ip) << "(";
381+
oss << primary.resolve(resolve_ip) << "(";
376382
if (disk_found) {
377383
oss << disk_value;
378384
} else {
@@ -391,12 +397,12 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
391397
{
392398
std::stringstream oss;
393399
oss << "[";
394-
for (int j = 0; j < pc.hp_secondaries.size(); j++) {
400+
for (int j = 0; j < secondaries.size(); j++) {
395401
if (j != 0)
396402
oss << ",";
397403
bool found = false;
398404
double value = 0;
399-
auto f1 = disk_map.find(pc.hp_secondaries[j]);
405+
auto f1 = disk_map.find(secondaries[j]);
400406
if (f1 != disk_map.end()) {
401407
auto &sub_map = f1->second;
402408
auto f2 = sub_map.find(pc.pid.get_partition_index());
@@ -409,7 +415,7 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
409415
}
410416
bool count_found = false;
411417
double count_value = 0;
412-
auto f3 = count_map.find(pc.hp_secondaries[j]);
418+
auto f3 = count_map.find(secondaries[j]);
413419
if (f3 != count_map.end()) {
414420
auto &sub_map = f3->second;
415421
auto f3 = sub_map.find(pc.pid.get_partition_index());
@@ -420,7 +426,7 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
420426
}
421427

422428
// TODO(wangdan): refactor as format style.
423-
oss << pc.hp_secondaries[j].resolve(resolve_ip) << "(";
429+
oss << secondaries[j].resolve(resolve_ip) << "(";
424430
if (found) {
425431
oss << value;
426432
} else {
@@ -441,8 +447,8 @@ bool app_disk(command_executor *e, shell_context *sc, arguments args)
441447
if (detailed) {
442448
tp_details.add_row(std::to_string(pc.pid.get_partition_index()));
443449
tp_details.append_data(pc.ballot);
444-
tp_details.append_data(fmt::format(
445-
"{}/{}", pc.hp_secondaries.size() + (pc.hp_primary ? 1 : 0), pc.max_replica_count));
450+
tp_details.append_data(
451+
fmt::format("{}/{}", secondaries.size() + (primary ? 1 : 0), pc.max_replica_count));
446452
tp_details.append_data(primary_str);
447453
tp_details.append_data(secondary_str);
448454
}

0 commit comments

Comments
 (0)