cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Save tokens as string in local and peers system table
Date Fri, 05 Oct 2012 17:05:10 GMT
Updated Branches:
  refs/heads/trunk 1b56ad122 -> c2a8f1288


Save tokens as string in local and peers system table

patch by slebresne; reviewed by jbellis for CASSANDRA-4351


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

Branch: refs/heads/trunk
Commit: c2a8f1288f8985cdec374c88a063ac84cec60181
Parents: 1b56ad1
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Fri Oct 5 19:03:26 2012 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Oct 5 19:03:26 2012 +0200

----------------------------------------------------------------------
 .../org/apache/cassandra/config/CFMetaData.java    |    4 ++--
 src/java/org/apache/cassandra/db/SystemTable.java  |   15 ++++++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c2a8f128/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java b/src/java/org/apache/cassandra/config/CFMetaData.java
index ef25d2a..176d63a 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -160,7 +160,7 @@ public final class CFMetaData
     public static final CFMetaData PeersCf = compile(12, "CREATE TABLE " + SystemTable.PEERS_CF
+ " ("
                                                          + "peer inet PRIMARY KEY,"
                                                          + "ring_id uuid,"
-                                                         + "tokens set<blob>,"
+                                                         + "tokens set<varchar>,"
                                                          + "schema_version uuid,"
                                                          + "release_version text,"
                                                          + "rpc_address inet,"
@@ -170,7 +170,7 @@ public final class CFMetaData
 
     public static final CFMetaData LocalCf = compile(13, "CREATE TABLE " + SystemTable.LOCAL_CF
+ " ("
                                                          + "key text PRIMARY KEY,"
-                                                         + "tokens set<blob>,"
+                                                         + "tokens set<varchar>,"
                                                          + "cluster_name text,"
                                                          + "gossip_generation int,"
                                                          + "bootstrapped text,"

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c2a8f128/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 ff7d81a..2883e0b 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -41,6 +41,7 @@ import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.db.marshal.AsciiType;
 import org.apache.cassandra.db.marshal.BytesType;
+import org.apache.cassandra.db.marshal.UTF8Type;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.dht.Token;
@@ -208,7 +209,7 @@ public class SystemTable
         Iterator<Token> iter = tokens.iterator();
         while (iter.hasNext())
         {
-            sb.append("'").append(ByteBufferUtil.bytesToHex(factory.toByteArray(iter.next()))).append("'");
+            sb.append("'").append(factory.toString(iter.next())).append("'");
             if (iter.hasNext())
                 sb.append(",");
         }
@@ -216,12 +217,12 @@ public class SystemTable
         return sb.toString();
     }
 
-    private static Collection<Token> deserializeTokens(Collection<ByteBuffer>
tokensBytes)
+    private static Collection<Token> deserializeTokens(Collection<String> tokensStrings)
     {
         Token.TokenFactory factory = StorageService.getPartitioner().getTokenFactory();
-        List<Token> tokens = new ArrayList<Token>(tokensBytes.size());
-        for (ByteBuffer tk : tokensBytes)
-            tokens.add(factory.fromByteArray(tk));
+        List<Token> tokens = new ArrayList<Token>(tokensStrings.size());
+        for (String tk : tokensStrings)
+            tokens.add(factory.fromString(tk));
         return tokens;
     }
 
@@ -296,7 +297,7 @@ public class SystemTable
         {
             InetAddress peer = row.getInetAddress("peer");
             if (row.has("tokens"))
-                tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", BytesType.instance)));
+                tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance)));
         }
 
         return tokenMap;
@@ -351,7 +352,7 @@ public class SystemTable
         UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
         return result.isEmpty() || !result.one().has("tokens")
              ? Collections.<Token>emptyList()
-             : deserializeTokens(result.one().<ByteBuffer>getSet("tokens", BytesType.instance));
+             : deserializeTokens(result.one().<String>getSet("tokens", UTF8Type.instance));
     }
 
     public static int incrementAndGetGeneration()


Mime
View raw message