Author: jbellis
Date: Thu Dec 3 21:03:46 2009
New Revision: 886919
URL: http://svn.apache.org/viewvc?rev=886919&view=rev
Log:
simplify findSuitableEndPoint by using sortByProximity. patch by jbellis
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/DatacenterEndPointSnitch.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/EndPointSnitch.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/DatacenterEndPointSnitch.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/DatacenterEndPointSnitch.java?rev=886919&r1=886918&r2=886919&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/DatacenterEndPointSnitch.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/DatacenterEndPointSnitch.java
Thu Dec 3 21:03:46 2009
@@ -214,6 +214,10 @@
{
try
{
+ if (address.equals(a1) && !address.equals(a2))
+ return -1;
+ if (address.equals(a2) && !address.equals(a1))
+ return 1;
if (isOnSameRack(address, a1) && !isOnSameRack(address,
a2))
return -1;
if (isOnSameRack(address, a2) && !isOnSameRack(address,
a1))
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/EndPointSnitch.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/EndPointSnitch.java?rev=886919&r1=886918&r2=886919&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/EndPointSnitch.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/locator/EndPointSnitch.java
Thu Dec 3 21:03:46 2009
@@ -64,6 +64,10 @@
{
try
{
+ if (address.equals(a1) && !address.equals(a2))
+ return -1;
+ if (address.equals(a2) && !address.equals(a1))
+ return 1;
if (isOnSameRack(address, a1) && !isOnSameRack(address,
a2))
return -1;
if (isOnSameRack(address, a2) && !isOnSameRack(address,
a1))
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=886919&r1=886918&r2=886919&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
Thu Dec 3 21:03:46 2009
@@ -892,41 +892,17 @@
}
/**
- * This function finds the most suitable endpoint given a key.
- * It checks for locality and alive test.
+ * This function finds the closest live endpoint that contains a given key.
*/
public InetAddress findSuitableEndPoint(String key) throws IOException,
UnavailableException
{
List<InetAddress> endpoints = getNaturalEndpoints(key);
- for(InetAddress endPoint: endpoints)
+ endPointSnitch_.sortByProximity(FBUtilities.getLocalAddress(),
endpoints);
+ for (InetAddress endpoint : endpoints)
{
- if(endPoint.equals(FBUtilities.getLocalAddress()))
- {
- return endPoint;
- }
+ if (FailureDetector.instance().isAlive(endpoint))
+ return endpoint;
}
- int j = 0;
- for ( ; j < endpoints.size(); ++j )
- {
- if (
StorageService.instance().isInSameDataCenter(endpoints.get(j)) &&
FailureDetector.instance().isAlive(endpoints.get(j)))
- {
- return endpoints.get(j);
- }
- }
- // We have tried to be really nice but looks like there are no servers
- // in the local data center that are alive and can service this
request so
- // just send it to the first alive guy and see if we get anything.
- j = 0;
- for ( ; j < endpoints.size(); ++j )
- {
- if ( FailureDetector.instance().isAlive(endpoints.get(j)))
- {
- if (logger_.isDebugEnabled())
- logger_.debug("InetAddress " + endpoints.get(j) + " is alive
so get data from it.");
- return endpoints.get(j);
- }
- }
-
throw new UnavailableException(); // no nodes that could contain key
are alive
}