Really prevent duplicate compilation on coordinator

patch by Robert Stupp; reviewed by Tyler Hobbs for CASSANDRA-9475
This commit is contained in:
Robert Stupp 2015-06-18 10:24:37 +02:00
parent dee675f1ef
commit 94be12c6fd
7 changed files with 16 additions and 22 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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<>();

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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");