Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 98C49D3C5 for ; Mon, 10 Sep 2012 22:13:33 +0000 (UTC) Received: (qmail 15000 invoked by uid 500); 10 Sep 2012 22:13:32 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 14910 invoked by uid 500); 10 Sep 2012 22:13:32 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 14615 invoked by uid 99); 10 Sep 2012 22:13:31 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Sep 2012 22:13:31 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9FB8835305; Mon, 10 Sep 2012 22:13:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: xedin@apache.org To: commits@cassandra.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [7/13] git commit: Multiple values for CurrentLocal Node ID Message-Id: <20120910221331.9FB8835305@tyr.zones.apache.org> Date: Mon, 10 Sep 2012 22:13:31 +0000 (UTC) Multiple values for CurrentLocal Node ID patch by slebresne; reviewed by jbellis for CASSANDRA-4626 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/19800189 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/19800189 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/19800189 Branch: refs/heads/trunk Commit: 19800189d76453cf08af60e21a544729565714ba Parents: d391726 Author: Sylvain Lebresne Authored: Fri Sep 7 16:14:58 2012 +0200 Committer: Sylvain Lebresne Committed: Fri Sep 7 18:32:31 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/db/SystemTable.java | 44 +++++---------- 2 files changed, 16 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/19800189/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 8a0ce59..6157022 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,7 @@ * (Hadoop) fix setting key length for old-style mapred api (CASSANDRA-4534) * (Hadoop) fix iterating through a resultset consisting entirely of tombstoned rows (CASSANDRA-4466) + * Fix multiple values for CurrentLocal NodeID (CASSANDRA-4626) 1.0.11 http://git-wip-us.apache.org/repos/asf/cassandra/blob/19800189/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 628719b..7b96c6f 100644 --- a/src/java/org/apache/cassandra/db/SystemTable.java +++ b/src/java/org/apache/cassandra/db/SystemTable.java @@ -430,25 +430,19 @@ public class SystemTable { ByteBuffer id = null; Table table = Table.open(Table.SYSTEM_TABLE); - QueryFilter filter = QueryFilter.getIdentityFilter(decorate(CURRENT_LOCAL_NODE_ID_KEY), - new QueryPath(NODE_ID_CF)); + + // Get the last NodeId (since NodeId are timeuuid is thus ordered from the older to the newer one) + QueryFilter filter = QueryFilter.getSliceFilter(decorate(ALL_LOCAL_NODE_ID_KEY), + new QueryPath(NODE_ID_CF), + ByteBufferUtil.EMPTY_BYTE_BUFFER, + ByteBufferUtil.EMPTY_BYTE_BUFFER, + true, + 1); ColumnFamily cf = table.getColumnFamilyStore(NODE_ID_CF).getColumnFamily(filter); - if (cf != null) - { - // Even though gc_grace==0 on System table, we can have a race where we get back tombstones (see CASSANDRA-2824) - cf = ColumnFamilyStore.removeDeleted(cf, 0); - assert cf.getColumnCount() <= 1; - if (cf.getColumnCount() > 0) - id = cf.iterator().next().name(); - } - if (id != null) - { - return NodeId.wrap(id); - } + if (cf != null && cf.getColumnCount() != 0) + return NodeId.wrap(cf.iterator().next().name()); else - { return null; - } } /** @@ -465,24 +459,17 @@ public class SystemTable ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, NODE_ID_CF); cf.addColumn(new Column(newNodeId.bytes(), ip, now)); - ColumnFamily cf2 = cf.cloneMe(); - if (oldNodeId != null) - { - cf2.addColumn(new DeletedColumn(oldNodeId.bytes(), (int) (now / 1000), now)); - } - RowMutation rmCurrent = new RowMutation(Table.SYSTEM_TABLE, CURRENT_LOCAL_NODE_ID_KEY); - RowMutation rmAll = new RowMutation(Table.SYSTEM_TABLE, ALL_LOCAL_NODE_ID_KEY); - rmCurrent.add(cf2); - rmAll.add(cf); + RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, ALL_LOCAL_NODE_ID_KEY); + rm.add(cf); try { - rmCurrent.apply(); - rmAll.apply(); + rm.apply(); } catch (IOException e) { throw new RuntimeException(e); } + forceBlockingFlush(NODE_ID_CF); } public static List getOldLocalNodeIds() @@ -490,8 +477,7 @@ public class SystemTable List l = new ArrayList(); Table table = Table.open(Table.SYSTEM_TABLE); - QueryFilter filter = QueryFilter.getIdentityFilter(decorate(ALL_LOCAL_NODE_ID_KEY), - new QueryPath(NODE_ID_CF)); + QueryFilter filter = QueryFilter.getIdentityFilter(decorate(ALL_LOCAL_NODE_ID_KEY), new QueryPath(NODE_ID_CF)); ColumnFamily cf = table.getColumnFamilyStore(NODE_ID_CF).getColumnFamily(filter); NodeId previous = null;