---
title: "Replica Selection/Propogate Strategy"
author: "willpower"
date: "2007-03-22T18:11:28Z"
tags: []
slug: "replica-selection-propogate-strategy"
draft: false
lastmod: "2007-03-22T18:11:28Z"
id: 64741
url: "https://willpower.iteye.com/blog/64741"
---

Choose sequence: local node -&gt; local rack -&gt; remote rack

a selected replica node should be a good node:  
1&gt; if the node is (being) decommissed  
2&gt; the remaining capacity of the target machine  
3&gt; the communication traffic of the target machine  
 based on current connection of that machine, if current connection number &gt; average connection num(total connections / total machine size) node.getXceiverCount() &gt; (2.0 * avgLoad)  
4&gt; if the target rack has chosen too many nodes

Data replication topology:  
first replica machine -&gt; second replica -&gt; ...

After a list of replicas are selected, replica list should be sorted in pipe.  
The aim of this sort is to find the shortest path, since data replication will be travelling from the first replica machine to the final replica machine, so, we should reduce round trip.  
This is basically a traveling salesman problem:

java 代码

01. int index=0;
02. for( ;index
03. DatanodeDescriptor shortestNode = null;
04. int shortestDistance = Integer.MAX\_VALUE;
05. int shortestIndex = index;
06. for( int i=index; i
07. DatanodeDescriptor currentNode = nodes.get(i);
08. int currentDistance = clusterMap.getDistance( writer, currentNode );
09. if(shortestDistance&gt;currentDistance ) {
10. shortestDistance = currentDistance;
11. shortestNode = currentNode;
12. shortestIndex = i;
13. }
14. }
15. //switch position index & shortestIndex
16. if( index != shortestIndex ) {
17. nodes.set(shortestIndex, nodes.get(index));
18. nodes.set(index, shortestNode);
19. }
20. writer = shortestNode;
21. }