Merge branch 'cassandra-2.1' into trunk Conflicts: src/java/org/apache/cassandra/db/DefsTables.java
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/fa592a46 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/fa592a46 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/fa592a46 Branch: refs/heads/trunk Commit: fa592a46bda084c7ec5579698c2a9e159923ddf3 Parents: 47863bc 42582ec Author: Aleksey Yeschenko <alek...@apache.org> Authored: Fri Oct 10 20:27:52 2014 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Fri Oct 10 20:27:52 2014 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../org/apache/cassandra/db/DefsTables.java | 330 +++++++++---------- 2 files changed, 156 insertions(+), 175 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/fa592a46/CHANGES.txt ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/fa592a46/src/java/org/apache/cassandra/db/DefsTables.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/db/DefsTables.java index 14c5241,59f2e20..1693914 --- a/src/java/org/apache/cassandra/db/DefsTables.java +++ b/src/java/org/apache/cassandra/db/DefsTables.java @@@ -278,96 -308,50 +251,103 @@@ public class DefsTable // New keyspace with types for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) - { - ColumnFamily cfTypes = entry.getValue(); - if (!cfTypes.hasColumns()) - continue; - - for (UserType ut : UTMetaData.fromSchema(new Row(entry.getKey(), cfTypes)).values()) - addType(ut); - } + if (entry.getValue().hasColumns()) + created.addAll(UTMetaData.fromSchema(new Row(entry.getKey(), entry.getValue())).values()); - for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> modifiedEntry : diff.entriesDiffering().entrySet()) + for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering().entrySet()) { - DecoratedKey keyspace = modifiedEntry.getKey(); - ColumnFamily prevCFTypes = modifiedEntry.getValue().leftValue(); // state before external modification - ColumnFamily newCFTypes = modifiedEntry.getValue().rightValue(); // updated state + String keyspaceName = AsciiType.instance.compose(entry.getKey().getKey()); - if (!prevCFTypes.hasColumns()) // whole keyspace was deleted and now it's re-created + ColumnFamily pre = entry.getValue().leftValue(); + ColumnFamily post = entry.getValue().rightValue(); + + if (pre.hasColumns() && post.hasColumns()) { - for (UserType ut : UTMetaData.fromSchema(new Row(keyspace, newCFTypes)).values()) - addType(ut); + MapDifference<ByteBuffer, UserType> delta = + Maps.difference(Schema.instance.getKSMetaData(keyspaceName).userTypes.getAllTypes(), + UTMetaData.fromSchema(new Row(entry.getKey(), post))); + + dropped.addAll(delta.entriesOnlyOnLeft().values()); + created.addAll(delta.entriesOnlyOnRight().values()); + Iterables.addAll(altered, Iterables.transform(delta.entriesDiffering().values(), new Function<MapDifference.ValueDifference<UserType>, UserType>() + { + public UserType apply(MapDifference.ValueDifference<UserType> pair) + { + return pair.rightValue(); + } + })); } - else if (!newCFTypes.hasColumns()) // whole keyspace is deleted + else if (pre.hasColumns()) { - for (UserType ut : UTMetaData.fromSchema(new Row(keyspace, prevCFTypes)).values()) - dropType(ut); + dropped.addAll(Schema.instance.getKSMetaData(keyspaceName).userTypes.getAllTypes().values()); } - else // has modifications in the types, need to perform nested diff to determine what was really changed + else if (post.hasColumns()) { - MapDifference<ByteBuffer, UserType> typesDiff = Maps.difference(UTMetaData.fromSchema(new Row(keyspace, prevCFTypes)), - UTMetaData.fromSchema(new Row(keyspace, newCFTypes))); - - for (UserType type : typesDiff.entriesOnlyOnRight().values()) - addType(type); - - for (UserType type : typesDiff.entriesOnlyOnLeft().values()) - dropType(type); - - for (MapDifference.ValueDifference<UserType> tdiff : typesDiff.entriesDiffering().values()) - updateType(tdiff.rightValue()); // use the most recent value + created.addAll(UTMetaData.fromSchema(new Row(entry.getKey(), post)).values()); } } + + for (UserType type : created) + addType(type); + for (UserType type : altered) + updateType(type); + for (UserType type : dropped) + dropType(type); } - private static void mergeFunctions(Map<DecoratedKey, ColumnFamily> old, Map<DecoratedKey, ColumnFamily> updated) ++ // see the comments for mergeKeyspaces() ++ private static void mergeFunctions(Map<DecoratedKey, ColumnFamily> before, Map<DecoratedKey, ColumnFamily> after) + { - MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(old, updated); ++ List<UDFunction> created = new ArrayList<>(); ++ List<UDFunction> altered = new ArrayList<>(); ++ List<UDFunction> dropped = new ArrayList<>(); ++ ++ MapDifference<DecoratedKey, ColumnFamily> diff = Maps.difference(before, after); + + // New namespace with functions + for (Map.Entry<DecoratedKey, ColumnFamily> entry : diff.entriesOnlyOnRight().entrySet()) - { - ColumnFamily cfFunctions = entry.getValue(); - if (!cfFunctions.hasColumns()) - continue; - - for (UDFunction udf : UDFunction.fromSchema(new Row(entry.getKey(), cfFunctions)).values()) - addFunction(udf); - } ++ if (entry.getValue().hasColumns()) ++ created.addAll(UDFunction.fromSchema(new Row(entry.getKey(), entry.getValue())).values()); + - for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> modifiedEntry : diff.entriesDiffering().entrySet()) ++ for (Map.Entry<DecoratedKey, MapDifference.ValueDifference<ColumnFamily>> entry : diff.entriesDiffering().entrySet()) + { - DecoratedKey namespace = modifiedEntry.getKey(); - ColumnFamily prevCFFunctions = modifiedEntry.getValue().leftValue(); // state before external modification - ColumnFamily newCFFunctions = modifiedEntry.getValue().rightValue(); // updated state ++ ColumnFamily pre = entry.getValue().leftValue(); ++ ColumnFamily post = entry.getValue().rightValue(); + - if (!prevCFFunctions.hasColumns()) // whole namespace was deleted and now it's re-created ++ if (pre.hasColumns() && post.hasColumns()) + { - for (UDFunction udf : UDFunction.fromSchema(new Row(namespace, newCFFunctions)).values()) - addFunction(udf); ++ MapDifference<ByteBuffer, UDFunction> delta = ++ Maps.difference(UDFunction.fromSchema(new Row(entry.getKey(), pre)), ++ UDFunction.fromSchema(new Row(entry.getKey(), post))); ++ ++ dropped.addAll(delta.entriesOnlyOnLeft().values()); ++ created.addAll(delta.entriesOnlyOnRight().values()); ++ Iterables.addAll(altered, Iterables.transform(delta.entriesDiffering().values(), new Function<MapDifference.ValueDifference<UDFunction>, UDFunction>() ++ { ++ public UDFunction apply(MapDifference.ValueDifference<UDFunction> pair) ++ { ++ return pair.rightValue(); ++ } ++ })); + } - else if (!newCFFunctions.hasColumns()) // whole namespace is deleted ++ else if (pre.hasColumns()) + { - for (UDFunction udf : UDFunction.fromSchema(new Row(namespace, prevCFFunctions)).values()) - dropFunction(udf); ++ dropped.addAll(UDFunction.fromSchema(new Row(entry.getKey(), pre)).values()); + } - else // has modifications in the functions, need to perform nested diff to determine what was really changed ++ else if (post.hasColumns()) + { - MapDifference<ByteBuffer, UDFunction> functionsDiff = Maps.difference(UDFunction.fromSchema(new Row(namespace, prevCFFunctions)), - UDFunction.fromSchema(new Row(namespace, newCFFunctions))); - - for (UDFunction udf : functionsDiff.entriesOnlyOnRight().values()) - addFunction(udf); - - for (UDFunction udf : functionsDiff.entriesOnlyOnLeft().values()) - dropFunction(udf); - - for (MapDifference.ValueDifference<UDFunction> tdiff : functionsDiff.entriesDiffering().values()) - updateFunction(tdiff.rightValue()); // use the most recent value ++ created.addAll(UDFunction.fromSchema(new Row(entry.getKey(), post)).values()); + } + } ++ ++ for (UDFunction udf : created) ++ addFunction(udf); ++ for (UDFunction udf : altered) ++ updateFunction(udf); ++ for (UDFunction udf : dropped) ++ dropFunction(udf); + } + private static void addKeyspace(KSMetaData ksm) { assert Schema.instance.getKSMetaData(ksm.name) == null; @@@ -416,19 -400,9 +396,19 @@@ MigrationManager.instance.notifyCreateUserType(ut); } + private static void addFunction(UDFunction udf) + { + logger.info("Loading {}", udf); + + Functions.addFunction(udf); + + if (!StorageService.instance.isClientMode()) + MigrationManager.instance.notifyCreateFunction(udf); + } + - private static void updateKeyspace(KSMetaData newState) + private static void updateKeyspace(String ksName) { - KSMetaData oldKsm = Schema.instance.getKSMetaData(newState.name); + KSMetaData oldKsm = Schema.instance.getKSMetaData(ksName); assert oldKsm != null; KSMetaData newKsm = KSMetaData.cloneWith(oldKsm.reloadAttributes(), oldKsm.cfMetaData().values());