cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [5/6] git commit: Load host_ids when adding saved endpoints Patch by brandonwilliams, reviewed by tjake for CASSANDRA-5032
Date Thu, 06 Dec 2012 14:26:05 GMT
Load host_ids when adding saved endpoints
Patch by brandonwilliams, reviewed by tjake for CASSANDRA-5032


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

Branch: refs/heads/cassandra-1.2.0
Commit: 7322f8238bb53efbac2a078585c4582cb1fc5e4a
Parents: a90b310
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Thu Dec 6 08:24:30 2012 -0600
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Thu Dec 6 08:24:30 2012 -0600

----------------------------------------------------------------------
 .../org/apache/cassandra/config/CFMetaData.java    |    4 +-
 src/java/org/apache/cassandra/db/SystemTable.java  |   26 ++++++++++++--
 .../apache/cassandra/service/StorageService.java   |    4 ++-
 3 files changed, 27 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/7322f823/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 c2aa768..986e95d 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -161,7 +161,7 @@ public final class CFMetaData
 
     public static final CFMetaData PeersCf = compile(12, "CREATE TABLE " + SystemTable.PEERS_CF
+ " ("
                                                          + "peer inet PRIMARY KEY,"
-                                                         + "ring_id uuid,"
+                                                         + "host_id uuid,"
                                                          + "tokens set<varchar>,"
                                                          + "schema_version uuid,"
                                                          + "release_version text,"
@@ -176,7 +176,7 @@ public final class CFMetaData
                                                          + "cluster_name text,"
                                                          + "gossip_generation int,"
                                                          + "bootstrapped text,"
-                                                         + "ring_id uuid,"
+                                                         + "host_id uuid,"
                                                          + "release_version text,"
                                                          + "thrift_version text,"
                                                          + "cql_version text,"

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7322f823/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 7737887..bfd7ac9 100644
--- a/src/java/org/apache/cassandra/db/SystemTable.java
+++ b/src/java/org/apache/cassandra/db/SystemTable.java
@@ -377,6 +377,24 @@ public class SystemTable
     }
 
     /**
+     * Return a map of store host_ids to IP addresses
+     *
+     */
+    public static Map<InetAddress, UUID> loadHostIds()
+    {
+        Map<InetAddress, UUID> hostIdMap = new HashMap<InetAddress, UUID>();
+        for (UntypedResultSet.Row row : processInternal("SELECT peer, host_id FROM system."
+ PEERS_CF))
+        {
+            InetAddress peer = row.getInetAddress("peer");
+            if (row.has("host_id"))
+            {
+                hostIdMap.put(peer, row.getUUID("host_id"));
+            }
+        }
+        return hostIdMap;
+    }
+
+    /**
      * One of three things will happen if you try to read the system table:
      * 1. files are present and you can read them: great
      * 2. no files are there: great (new node is assumed)
@@ -528,20 +546,20 @@ public class SystemTable
     {
         UUID hostId = null;
 
-        String req = "SELECT ring_id FROM system.%s WHERE key='%s'";
+        String req = "SELECT host_id FROM system.%s WHERE key='%s'";
         UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
 
         // Look up the Host UUID (return it if found)
-        if (!result.isEmpty() && result.one().has("ring_id"))
+        if (!result.isEmpty() && result.one().has("host_id"))
         {
-            return result.one().getUUID("ring_id");
+            return result.one().getUUID("host_id");
         }
 
         // ID not found, generate a new one, persist, and then return it.
         hostId = UUID.randomUUID();
         logger.warn("No host ID found, created {} (Note: This should happen exactly once
per node).", hostId);
 
-        req = "INSERT INTO system.%s (key, ring_id) VALUES ('%s', '%s')";
+        req = "INSERT INTO system.%s (key, host_id) VALUES ('%s', '%s')";
         processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, hostId));
         return hostId;
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/7322f823/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 4bf6ba7..bc418f4 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -428,6 +428,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
         {
             logger.info("Loading persisted ring state");
             Multimap<InetAddress, Token> loadedTokens = SystemTable.loadTokens();
+            Map<InetAddress, UUID> loadedHostIds = SystemTable.loadHostIds();
             for (InetAddress ep : loadedTokens.keySet())
             {
                 if (ep.equals(FBUtilities.getBroadcastAddress()))
@@ -438,6 +439,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
                 else
                 {
                     tokenMetadata.updateNormalTokens(loadedTokens.get(ep), ep);
+                    tokenMetadata.updateHostId(loadedHostIds.get(ep), ep);
                     Gossiper.instance.addSavedEndpoint(ep);
                 }
             }
@@ -1179,7 +1181,7 @@ public class StorageService implements IEndpointStateChangeSubscriber,
StorageSe
                 SystemTable.updatePeerInfo(endpoint, "schema_version", value.value);
                 break;
             case HOST_ID:
-                SystemTable.updatePeerInfo(endpoint, "ring_id", value.value);
+                SystemTable.updatePeerInfo(endpoint, "host_id", value.value);
                 break;
         }
     }


Mime
View raw message