You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2017/01/18 13:11:12 UTC

cassandra git commit: Avoid un-needed system flushes on startup

Repository: cassandra
Updated Branches:
  refs/heads/trunk 39d7cf50e -> d6ceb940e


Avoid un-needed system flushes on startup

patch by Corentin Chary, reviewed by Ariel Weisberg for CASSANDRA-13031


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

Branch: refs/heads/trunk
Commit: d6ceb940e3dc9484ec197c539aa65c41116ce660
Parents: 39d7cf5
Author: Corentin Chary <c....@criteo.com>
Authored: Thu Dec 22 12:39:50 2016 -0500
Committer: Jason Brown <ja...@gmail.com>
Committed: Wed Jan 18 05:10:18 2017 -0800

----------------------------------------------------------------------
 .../org/apache/cassandra/db/SystemKeyspace.java | 26 +++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/d6ceb940/src/java/org/apache/cassandra/db/SystemKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java
index 36f0605..5b63ba6 100644
--- a/src/java/org/apache/cassandra/db/SystemKeyspace.java
+++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java
@@ -413,6 +413,9 @@ public final class SystemKeyspace
 
     public static void setViewBuilt(String keyspaceName, String viewName, boolean replicated)
     {
+        if (isViewBuilt(keyspaceName, viewName) && isViewStatusReplicated(keyspaceName, viewName) == replicated)
+            return;
+
         String req = "INSERT INTO %s.\"%s\" (keyspace_name, view_name, status_replicated) VALUES (?, ?, ?)";
         executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName, replicated);
         forceBlockingFlush(BUILT_VIEWS);
@@ -420,11 +423,11 @@ public final class SystemKeyspace
 
     public static void setViewRemoved(String keyspaceName, String viewName)
     {
-        String buildReq = "DELETE FROM %S.%s WHERE keyspace_name = ? AND view_name = ?";
+        String buildReq = "DELETE FROM %S.%s WHERE keyspace_name = ? AND view_name = ? IF EXISTS";
         executeInternal(String.format(buildReq, SchemaConstants.SYSTEM_KEYSPACE_NAME, VIEWS_BUILDS_IN_PROGRESS), keyspaceName, viewName);
         forceBlockingFlush(VIEWS_BUILDS_IN_PROGRESS);
 
-        String builtReq = "DELETE FROM %s.\"%s\" WHERE keyspace_name = ? AND view_name = ?";
+        String builtReq = "DELETE FROM %s.\"%s\" WHERE keyspace_name = ? AND view_name = ? IF EXISTS";
         executeInternal(String.format(builtReq, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName);
         forceBlockingFlush(BUILT_VIEWS);
     }
@@ -445,7 +448,7 @@ public final class SystemKeyspace
         // Also, if writing to the built_view succeeds, but the view_builds_in_progress deletion fails, we will be able
         // to skip the view build next boot.
         setViewBuilt(ksname, viewName, false);
-        executeInternal(String.format("DELETE FROM system.%s WHERE keyspace_name = ? AND view_name = ?", VIEWS_BUILDS_IN_PROGRESS), ksname, viewName);
+        executeInternal(String.format("DELETE FROM system.%s WHERE keyspace_name = ? AND view_name = ? IF EXISTS", VIEWS_BUILDS_IN_PROGRESS), ksname, viewName);
         forceBlockingFlush(VIEWS_BUILDS_IN_PROGRESS);
     }
 
@@ -496,6 +499,10 @@ public final class SystemKeyspace
      */
     public static synchronized void removeTruncationRecord(UUID cfId)
     {
+        Pair<CommitLogPosition, Long> truncationRecord = getTruncationRecord(cfId);
+        if (truncationRecord == null)
+            return;
+
         String req = "DELETE truncated_at[?] from system.%s WHERE key = '%s'";
         executeInternal(String.format(req, LOCAL, LOCAL), cfId);
         truncationRecords = null;
@@ -577,6 +584,9 @@ public final class SystemKeyspace
 
     public static synchronized void updatePreferredIP(InetAddress ep, InetAddress preferred_ip)
     {
+        if (getPreferredIP(ep) == preferred_ip)
+            return;
+
         String req = "INSERT INTO system.%s (peer, preferred_ip) VALUES (?, ?)";
         executeInternal(String.format(req, PEERS), ep, preferred_ip);
         forceBlockingFlush(PEERS);
@@ -640,6 +650,11 @@ public final class SystemKeyspace
     public static synchronized void updateTokens(Collection<Token> tokens)
     {
         assert !tokens.isEmpty() : "removeEndpoint should be used instead";
+
+        Collection<Token> savedTokens = getSavedTokens();
+        if (tokens.containsAll(savedTokens) && tokens.size() == savedTokens.size())
+            return;
+
         String req = "INSERT INTO system.%s (key, tokens) VALUES ('%s', ?)";
         executeInternal(String.format(req, LOCAL, LOCAL), tokensAsSet(tokens));
         forceBlockingFlush(LOCAL);
@@ -867,6 +882,9 @@ public final class SystemKeyspace
 
     public static void setBootstrapState(BootstrapState state)
     {
+        if (getBootstrapState() == state)
+            return;
+
         String req = "INSERT INTO system.%s (key, bootstrapped) VALUES ('%s', ?)";
         executeInternal(String.format(req, LOCAL, LOCAL), state.name());
         forceBlockingFlush(LOCAL);
@@ -888,7 +906,7 @@ public final class SystemKeyspace
 
     public static void setIndexRemoved(String keyspaceName, String indexName)
     {
-        String req = "DELETE FROM %s.\"%s\" WHERE table_name = ? AND index_name = ?";
+        String req = "DELETE FROM %s.\"%s\" WHERE table_name = ? AND index_name = ? IF EXISTS";
         executeInternal(String.format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, indexName);
         forceBlockingFlush(BUILT_INDEXES);
     }