store hints by host ID, instead of token Patch by eevans; reviewed by Brandon Williams for CASSANDRA-4120
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/0a5267e5 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/0a5267e5 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/0a5267e5 Branch: refs/heads/trunk Commit: 0a5267e5c9c5b8282a4ccf056be1f203f83b687b Parents: ad685c4 Author: Eric Evans <[email protected]> Authored: Wed May 2 18:48:16 2012 -0500 Committer: Eric Evans <[email protected]> Committed: Wed May 2 18:48:16 2012 -0500 ---------------------------------------------------------------------- NEWS.txt | 10 +++++++ .../apache/cassandra/db/HintedHandOffManager.java | 20 ++++++++------ src/java/org/apache/cassandra/db/SystemTable.java | 2 +- .../org/apache/cassandra/service/StorageProxy.java | 7 +++-- 4 files changed, 26 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a5267e5/NEWS.txt ---------------------------------------------------------------------- diff --git a/NEWS.txt b/NEWS.txt index 8c65101..50a0d3c 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -9,6 +9,16 @@ upgrade, just in case you need to roll back to the previous version. by version X, but the inverse is not necessarily the case.) +1.2 +=== + +Upgrading +--------- + - The hints schema was changed from 1.1 to 1.2. Cassandra automatically + snapshots and then truncates the hints column family as part of + starting up 1.2 for the first time. Additionally, upgraded nodes + will not store new hints destined for older (pre-1.2) nodes. + 1.1.1 ===== http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a5267e5/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 178aca4..6569c46 100644 --- a/src/java/org/apache/cassandra/db/HintedHandOffManager.java +++ b/src/java/org/apache/cassandra/db/HintedHandOffManager.java @@ -52,6 +52,7 @@ import org.apache.cassandra.service.*; import org.apache.cassandra.thrift.*; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.UUIDGen; import org.apache.cassandra.utils.WrappedRunnable; import org.cliffc.high_scale_lib.NonBlockingHashSet; @@ -163,9 +164,9 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean { if (!StorageService.instance.getTokenMetadata().isMember(endpoint)) return; - Token<?> token = StorageService.instance.getTokenMetadata().getToken(endpoint); - ByteBuffer tokenBytes = StorageService.getPartitioner().getTokenFactory().toByteArray(token); - final RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, tokenBytes); + UUID hostId = StorageService.instance.getTokenMetadata().getHostId(endpoint); + ByteBuffer hostIdBytes = ByteBuffer.wrap(UUIDGen.decompose(hostId)); + final RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, hostIdBytes); rm.delete(new QueryPath(HINTS_CF), System.currentTimeMillis()); // execute asynchronously to avoid blocking caller (which may be processing gossip) @@ -289,10 +290,11 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean // 5. Do major compaction to clean up all deletes etc. // find the hints for the node using its token. - Token<?> token = StorageService.instance.getTokenMetadata().getToken(endpoint); - logger.info("Started hinted handoff for token: {} with IP: {}", token, endpoint); - ByteBuffer tokenBytes = StorageService.getPartitioner().getTokenFactory().toByteArray(token); - DecoratedKey epkey = StorageService.getPartitioner().decorateKey(tokenBytes); + UUID hostId = StorageService.instance.getTokenMetadata().getHostId(endpoint); + logger.info("Started hinted handoff for host: {} with IP: {}", hostId, endpoint); + ByteBuffer hostIdBytes = ByteBuffer.wrap(UUIDGen.decompose(hostId)); + DecoratedKey epkey = StorageService.getPartitioner().decorateKey(hostIdBytes); + int rowsReplayed = 0; ByteBuffer startColumn = ByteBufferUtil.EMPTY_BYTE_BUFFER; @@ -324,7 +326,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean if (ByteBufferUtil.string(subColumn.name()).contains(SEPARATOR_08)) { logger.debug("0.8-style hint found. This should have been taken care of by purgeIncompatibleHints"); - deleteHint(tokenBytes, hint.name(), hint.maxTimestamp()); + deleteHint(hostIdBytes, hint.name(), hint.maxTimestamp()); continue page; } } @@ -356,7 +358,7 @@ public class HintedHandOffManager implements HintedHandOffManagerMBean sendMutation(endpoint, rm); rowsReplayed++; } - deleteHint(tokenBytes, hint.name(), hint.maxTimestamp()); + deleteHint(hostIdBytes, hint.name(), hint.maxTimestamp()); } catch (TimeoutException e) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a5267e5/src/java/org/apache/cassandra/db/SystemTable.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/SystemTable.java b/src/java/org/apache/cassandra/db/SystemTable.java index 335cf19..6fb68f0 100644 --- a/src/java/org/apache/cassandra/db/SystemTable.java +++ b/src/java/org/apache/cassandra/db/SystemTable.java @@ -109,7 +109,7 @@ public class SystemTable /** if hints become incompatible across versions of cassandra, that logic (and associated purging) is managed here. */ private static void purgeIncompatibleHints() throws IOException { - ByteBuffer upgradeMarker = ByteBufferUtil.bytes("Pre-1.0 hints purged"); + ByteBuffer upgradeMarker = ByteBufferUtil.bytes("Pre-1.2 hints purged"); Table table = Table.open(Table.SYSTEM_TABLE); QueryFilter filter = QueryFilter.getNamesFilter(decorate(COOKIE_KEY), new QueryPath(STATUS_CF), upgradeMarker); ColumnFamily cf = table.getColumnFamilyStore(STATUS_CF).getColumnFamily(filter); http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a5267e5/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 c56abd6..73c2965 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -364,9 +364,10 @@ public class StorageProxy implements StorageProxyMBean try { - Token<?> token = StorageService.instance.getTokenMetadata().getToken(target); - ByteBuffer tokenbytes = StorageService.getPartitioner().getTokenFactory().toByteArray(token); - RowMutation hintedMutation = RowMutation.hintFor(mutation, tokenbytes); + UUID hostId = StorageService.instance.getTokenMetadata().getHostId(target); + if ((hostId == null) && (Gossiper.instance.getVersion(target) < MessagingService.VERSION_12)) + logger.info("Unable to store hint for host with missing ID, {} (old node?)", target.toString()); + RowMutation hintedMutation = RowMutation.hintFor(mutation, ByteBuffer.wrap(UUIDGen.decompose(hostId))); hintedMutation.apply(); totalHints.incrementAndGet();
