cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: Really prevent duplicate compilation on coordinator
Date Thu, 18 Jun 2015 08:25:35 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 dee675f1e -> 94be12c6f


Really prevent duplicate compilation on coordinator

patch by Robert Stupp; reviewed by Tyler Hobbs for CASSANDRA-9475


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

Branch: refs/heads/cassandra-2.2
Commit: 94be12c6fdfe48f042f63c1b5985ec59f772f005
Parents: dee675f
Author: Robert Stupp <snazy@snazy.de>
Authored: Thu Jun 18 10:24:37 2015 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Thu Jun 18 10:24:37 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                            |  1 +
 src/java/org/apache/cassandra/config/Schema.java       |  8 ++++----
 .../org/apache/cassandra/cql3/functions/Functions.java | 13 ++-----------
 .../cql3/statements/CreateFunctionStatement.java       |  4 +++-
 .../apache/cassandra/schema/LegacySchemaTables.java    |  4 ++--
 .../org/apache/cassandra/cql3/AggregationTest.java     |  4 ++--
 test/unit/org/apache/cassandra/cql3/UFTest.java        |  4 ++--
 7 files changed, 16 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 3b16b6f..3671af9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2
+ * Duplicate compilation of UDFs on coordinator (CASSANDRA-9475)
  * Fix connection leak in CqlRecordWriter (CASSANDRA-9576)
  * Mlockall before opening system sstables & remove boot_without_jna option (CASSANDRA-9573)
  * Add functions to convert timeuuid to date or time, deprecate dateOf and unixTimestampOf
(CASSANDRA-9229)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/src/java/org/apache/cassandra/config/Schema.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/Schema.java b/src/java/org/apache/cassandra/config/Schema.java
index 5429f07..2678cb3 100644
--- a/src/java/org/apache/cassandra/config/Schema.java
+++ b/src/java/org/apache/cassandra/config/Schema.java
@@ -554,7 +554,7 @@ public class Schema
     {
         logger.info("Loading {}", udf);
 
-        Functions.addFunction(udf);
+        Functions.addOrReplaceFunction(udf);
 
         MigrationManager.instance.notifyCreateFunction(udf);
     }
@@ -563,7 +563,7 @@ public class Schema
     {
         logger.info("Updating {}", udf);
 
-        Functions.replaceFunction(udf);
+        Functions.addOrReplaceFunction(udf);
 
         MigrationManager.instance.notifyUpdateFunction(udf);
     }
@@ -582,7 +582,7 @@ public class Schema
     {
         logger.info("Loading {}", udf);
 
-        Functions.addFunction(udf);
+        Functions.addOrReplaceFunction(udf);
 
         MigrationManager.instance.notifyCreateAggregate(udf);
     }
@@ -591,7 +591,7 @@ public class Schema
     {
         logger.info("Updating {}", udf);
 
-        Functions.replaceFunction(udf);
+        Functions.addOrReplaceFunction(udf);
 
         MigrationManager.instance.notifyUpdateAggregate(udf);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/src/java/org/apache/cassandra/cql3/functions/Functions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/Functions.java b/src/java/org/apache/cassandra/cql3/functions/Functions.java
index c940787..d6a8ab0 100644
--- a/src/java/org/apache/cassandra/cql3/functions/Functions.java
+++ b/src/java/org/apache/cassandra/cql3/functions/Functions.java
@@ -294,11 +294,10 @@ public abstract class Functions
         return sb.toString();
     }
 
-    // This is *not* thread safe but is only called in SchemaTables that is synchronized.
-    public static void addFunction(AbstractFunction fun)
+    public static void addOrReplaceFunction(AbstractFunction fun)
     {
         // We shouldn't get there unless that function don't exist
-        assert find(fun.name(), fun.argTypes()) == null;
+        removeFunction(fun.name(), fun.argTypes());
         declare(fun);
     }
 
@@ -320,17 +319,9 @@ public abstract class Functions
                     declared.remove(name);
                 return;
             }
-            assert false : "Function " + name + " not declared";
         }
     }
 
-    // Same remarks than for addFunction
-    public static void replaceFunction(AbstractFunction fun)
-    {
-        removeFunction(fun.name(), fun.argTypes());
-        addFunction(fun);
-    }
-
     public static List<Function> getReferencesTo(Function old)
     {
         List<Function> references = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java
index 9e9d544..77e41ed 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateFunctionStatement.java
@@ -26,7 +26,6 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.cassandra.cql3.ColumnIdentifier;
-import org.apache.cassandra.cql3.Operation.RawUpdate;
 import org.apache.cassandra.cql3.functions.*;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.exceptions.*;
@@ -171,6 +170,9 @@ public final class CreateFunctionStatement extends SchemaAlteringStatement
         this.udFunction = UDFunction.create(functionName, argNames, argTypes, returnType,
calledOnNullInput, language, body);
         this.replaced = old != null;
 
+        // add function to registry to prevent duplicate compilation on coordinator during
migration
+        Functions.addOrReplaceFunction(udFunction);
+
         MigrationManager.announceNewFunction(udFunction, isLocalOnly);
 
         return true;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/src/java/org/apache/cassandra/schema/LegacySchemaTables.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/LegacySchemaTables.java b/src/java/org/apache/cassandra/schema/LegacySchemaTables.java
index 9553df0..1840829 100644
--- a/src/java/org/apache/cassandra/schema/LegacySchemaTables.java
+++ b/src/java/org/apache/cassandra/schema/LegacySchemaTables.java
@@ -222,11 +222,11 @@ public class LegacySchemaTables
 
             // Will be moved away in #6717
             for (UDFunction function : createFunctionsFromFunctionsPartition(readSchemaPartitionForKeyspace(FUNCTIONS,
partition.key)).values())
-                org.apache.cassandra.cql3.functions.Functions.addFunction(function);
+                org.apache.cassandra.cql3.functions.Functions.addOrReplaceFunction(function);
 
             // Will be moved away in #6717
             for (UDAggregate aggregate : createAggregatesFromAggregatesPartition(readSchemaPartitionForKeyspace(AGGREGATES,
partition.key)).values())
-                org.apache.cassandra.cql3.functions.Functions.addFunction(aggregate);
+                org.apache.cassandra.cql3.functions.Functions.addOrReplaceFunction(aggregate);
         }
 
         return keyspaces;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/test/unit/org/apache/cassandra/cql3/AggregationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/AggregationTest.java b/test/unit/org/apache/cassandra/cql3/AggregationTest.java
index 768fdc3..4281262 100644
--- a/test/unit/org/apache/cassandra/cql3/AggregationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/AggregationTest.java
@@ -1013,8 +1013,8 @@ public class AggregationTest extends CQLTester
 
         UDAggregate f = (UDAggregate) Functions.find(parseFunctionName(a)).get(0);
 
-        Functions.replaceFunction(UDAggregate.createBroken(f.name(), f.argTypes(), f.returnType(),
-                                                           null, new InvalidRequestException("foo
bar is broken")));
+        Functions.addOrReplaceFunction(UDAggregate.createBroken(f.name(), f.argTypes(), f.returnType(),
+                                                                null, new InvalidRequestException("foo
bar is broken")));
 
         assertInvalidThrowMessage("foo bar is broken", InvalidRequestException.class,
                                   "SELECT " + a + "(val) FROM %s");

http://git-wip-us.apache.org/repos/asf/cassandra/blob/94be12c6/test/unit/org/apache/cassandra/cql3/UFTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/UFTest.java b/test/unit/org/apache/cassandra/cql3/UFTest.java
index 5a20c18..1b3326b 100644
--- a/test/unit/org/apache/cassandra/cql3/UFTest.java
+++ b/test/unit/org/apache/cassandra/cql3/UFTest.java
@@ -2163,8 +2163,8 @@ public class UFTest extends CQLTester
 
         UDFunction f = (UDFunction) Functions.find(parseFunctionName(fName)).get(0);
 
-        Functions.replaceFunction(UDFunction.createBrokenFunction(f.name(), f.argNames(),
f.argTypes(), f.returnType(), true,
-                                                                  "java", f.body(), new InvalidRequestException("foo
bar is broken")));
+        Functions.addOrReplaceFunction(UDFunction.createBrokenFunction(f.name(), f.argNames(),
f.argTypes(), f.returnType(), true,
+                                                                       "java", f.body(),
new InvalidRequestException("foo bar is broken")));
 
         assertInvalidThrowMessage("foo bar is broken", InvalidRequestException.class,
                                   "SELECT key, " + fName + "(dval) FROM %s");


Mime
View raw message