@@ -166,18 +166,23 @@ bool recover(command_executor *e, shell_context *sc, arguments args)
166166
167167dsn::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;
0 commit comments