cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r830046 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/SystemTable.java gms/Gossiper.java gms/HeartBeatState.java
Date Tue, 27 Oct 2009 02:25:52 GMT
Author: jbellis
Date: Tue Oct 27 02:25:50 2009
New Revision: 830046

URL: http://svn.apache.org/viewvc?rev=830046&view=rev
Log:
initialize generation to seconds-since-epoch, a value much more likely to be unique than "1"
patch by jbellis; reviewed by eevans for CASSANDRA-515

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java?rev=830046&r1=830045&r2=830046&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java Tue Oct 27
02:25:50 2009
@@ -108,25 +108,28 @@
         {
             Token token = p.getDefaultToken();
             logger.info("Saved Token not found. Using " + token);
-            int generation = 1;
+            // seconds-since-epoch isn't a foolproof new generation
+            // (where foolproof is "guaranteed to be larger than the last one seen at this
ip address"),
+            // but it's as close as sanely possible
+            int generation = (int) (System.currentTimeMillis() / 1000);
 
             RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
             cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF);
             cf.addColumn(new Column(TOKEN, p.getTokenFactory().toByteArray(token)));
-            cf.addColumn(new Column(GENERATION, BasicUtilities.intToByteArray(generation))
);
+            cf.addColumn(new Column(GENERATION, BasicUtilities.intToByteArray(generation)));
             rm.add(cf);
             rm.apply();
             metadata = new StorageMetadata(token, generation);
             return metadata;
         }
 
-        /* we crashed and came back up need to bump generation # */
+        /* we crashed and came back up: make sure new generation is greater than old */
         IColumn tokenColumn = cf.getColumn(TOKEN);
         Token token = p.getTokenFactory().fromByteArray(tokenColumn.value());
         logger.info("Saved Token found: " + token);
 
         IColumn generation = cf.getColumn(GENERATION);
-        int gen = BasicUtilities.byteArrayToInt(generation.value()) + 1;
+        int gen = Math.max(BasicUtilities.byteArrayToInt(generation.value()) + 1, (int) (System.currentTimeMillis()
/ 1000));
         
         RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, LOCATION_KEY);
         cf = ColumnFamily.create(Table.SYSTEM_TABLE, SystemTable.STATUS_CF);

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java?rev=830046&r1=830045&r2=830046&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/Gossiper.java Tue Oct 27 02:25:50
2009
@@ -727,6 +727,7 @@
 
             int remoteGeneration = remoteStatePtr.getHeartBeatState().getGeneration();
             int localGeneration = localStatePtr.getHeartBeatState().getGeneration();
+            assert remoteGeneration >= localGeneration; // SystemTable makes sure we never
generate a smaller generation on start
 
             /* If the remoteGeneration is greater than localGeneration then apply state blindly
*/
             if ( remoteGeneration > localGeneration )

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java?rev=830046&r1=830045&r2=830046&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/gms/HeartBeatState.java Tue Oct
27 02:25:50 2009
@@ -43,10 +43,6 @@
     AtomicInteger heartbeat_;
     int version_;
 
-    HeartBeatState()
-    {
-    }
-    
     HeartBeatState(int generation, int heartbeat)
     {
         this(generation, heartbeat, 0);
@@ -68,13 +64,7 @@
     {
         return generation_;
     }
-    
-    void updateGeneration()
-    {
-        ++generation_;
-        version_ = VersionGenerator.getNextVersion();
-    }
-    
+
     int getHeartBeat()
     {
         return heartbeat_.get();
@@ -90,7 +80,7 @@
     {
         return version_;
     }
-};
+}
 
 class HeartBeatStateSerializer implements ICompactSerializer<HeartBeatState>
 {



Mime
View raw message