cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcken...@apache.org
Subject [05/18] cassandra git commit: Fix missing host ID on hinted handoff write
Date Fri, 13 Nov 2015 14:50:47 GMT
Fix missing host ID on hinted handoff write

Patch by pauloricardomg; reviewed by aweisberg for CASSANDRA-10485


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e291382f
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e291382f
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e291382f

Branch: refs/heads/trunk
Commit: e291382fd00e4c7fc9258116885267515da3c49c
Parents: 582b66f
Author: Paulo Motta <pauloricardomg@gmail.com>
Authored: Fri Nov 13 09:46:57 2015 -0500
Committer: Joshua McKenzie <jmckenzie@apache.org>
Committed: Fri Nov 13 09:46:57 2015 -0500

----------------------------------------------------------------------
 .../org/apache/cassandra/db/HintedHandOffManager.java   | 12 +++++-------
 src/java/org/apache/cassandra/service/StorageProxy.java | 11 ++++++-----
 .../unit/org/apache/cassandra/db/HintedHandOffTest.java |  5 +++--
 3 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e291382f/src/java/org/apache/cassandra/db/HintedHandOffManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/HintedHandOffManager.java b/src/java/org/apache/cassandra/db/HintedHandOffManager.java
index 4fbdd27..0d3ef39 100644
--- a/src/java/org/apache/cassandra/db/HintedHandOffManager.java
+++ b/src/java/org/apache/cassandra/db/HintedHandOffManager.java
@@ -130,16 +130,14 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean
      * Returns a mutation representing a Hint to be sent to <code>targetId</code>
      * as soon as it becomes available again.
      */
-    public Mutation hintFor(Mutation mutation, long now, int ttl, UUID targetId)
+    public Mutation hintFor(Mutation mutation, long now, int ttl, Pair<InetAddress, UUID>
target)
     {
         assert ttl > 0;
 
-        InetAddress endpoint = StorageService.instance.getTokenMetadata().getEndpointForHostId(targetId);
-        // during tests we may not have a matching endpoint, but this would be unexpected
in real clusters
-        if (endpoint != null)
-            metrics.incrCreatedHints(endpoint);
-        else
-            logger.warn("Unable to find matching endpoint for target {} when storing a hint",
targetId);
+        InetAddress endpoint = target.left;
+        UUID targetId = target.right;
+
+        metrics.incrCreatedHints(endpoint);
 
         UUID hintId = UUIDGen.getTimeUUID();
         // serialize the hint with id and version as a composite column name

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e291382f/src/java/org/apache/cassandra/service/StorageProxy.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java
index 4f20ef0..b701015 100644
--- a/src/java/org/apache/cassandra/service/StorageProxy.java
+++ b/src/java/org/apache/cassandra/service/StorageProxy.java
@@ -983,14 +983,15 @@ public class StorageProxy implements StorageProxyMBean
     public static void writeHintForMutation(Mutation mutation, long now, int ttl, InetAddress
target)
     {
         assert ttl > 0;
+
         UUID hostId = StorageService.instance.getTokenMetadata().getHostId(target);
-        if (hostId == null)
+        if (hostId != null)
         {
-            logger.warn("Missing host Id for {}", target.getHostAddress());
-            throw new AssertionError("Missing host Id for " + target.getHostAddress());
+            HintedHandOffManager.instance.hintFor(mutation, now, ttl, Pair.create(target,
hostId)).apply();
+            StorageMetrics.totalHints.inc();
         }
-        HintedHandOffManager.instance.hintFor(mutation, now, ttl, hostId).apply();
-        StorageMetrics.totalHints.inc();
+        else
+            logger.debug("Discarding hint for endpoint not part of ring: {}", target);
     }
 
     private static void sendMessagesToNonlocalDC(MessageOut<? extends IMutation> message,
Collection<InetAddress> targets, AbstractWriteResponseHandler handler)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e291382f/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
index c29c08e..ad1e6cf 100644
--- a/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
+++ b/test/unit/org/apache/cassandra/db/HintedHandOffTest.java
@@ -35,6 +35,7 @@ import org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy;
 import org.apache.cassandra.db.marshal.Int32Type;
 import org.apache.cassandra.db.marshal.UUIDType;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.Pair;
 
 import static org.junit.Assert.assertEquals;
 import static org.apache.cassandra.cql3.QueryProcessor.executeInternal;
@@ -65,7 +66,7 @@ public class HintedHandOffTest extends SchemaLoader
         HintedHandOffManager.instance.hintFor(rm,
                                               System.currentTimeMillis(),
                                               HintedHandOffManager.calculateHintTTL(rm),
-                                              UUID.randomUUID())
+                                              Pair.create(InetAddress.getByName("127.0.0.1"),
UUID.randomUUID()))
                                      .apply();
 
         // flush data to disk
@@ -106,7 +107,7 @@ public class HintedHandOffTest extends SchemaLoader
         HintedHandOffManager.instance.hintFor(rm,
                                               System.currentTimeMillis(),
                                               HintedHandOffManager.calculateHintTTL(rm),
-                                              UUID.randomUUID())
+                                              Pair.create(InetAddress.getByName("127.0.0.1"),
UUID.randomUUID()))
                                      .apply();
 
         assert getNoOfHints() == 1;


Mime
View raw message