Repository: cassandra Updated Branches: refs/heads/trunk 2d2f55f2f -> c3be5ab02
Flush system schema tables after local schema changes Patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-10429 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5c2912d1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5c2912d1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5c2912d1 Branch: refs/heads/trunk Commit: 5c2912d1ce95aacdacb59ccc840b12cd9aa0c8f8 Parents: a1b04c4 Author: Tyler Hobbs <tylerlho...@gmail.com> Authored: Thu Oct 1 14:25:54 2015 -0500 Committer: Tyler Hobbs <tylerlho...@gmail.com> Committed: Thu Oct 1 14:25:54 2015 -0500 ---------------------------------------------------------------------- CHANGES.txt | 1 + build.xml | 3 +++ .../apache/cassandra/db/DefinitionsUpdateVerbHandler.java | 2 +- src/java/org/apache/cassandra/schema/SchemaKeyspace.java | 10 ++++++---- .../org/apache/cassandra/service/MigrationManager.java | 4 ++-- src/java/org/apache/cassandra/service/MigrationTask.java | 2 +- .../org/apache/cassandra/schema/SchemaKeyspaceTest.java | 4 ++-- 7 files changed, 16 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 53269e6..5fddce9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0 + * Flush system schema tables after local schema changes (CASSANDRA-10429) Merged from 2.2: * cqlsh prompt includes name of keyspace after failed `use` statement (CASSANDRA-10369) http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index 89e3d46..669ca56 100644 --- a/build.xml +++ b/build.xml @@ -101,6 +101,9 @@ <!-- default for cql tests. Can be override by -Dcassandra.test.use_prepared=false --> <property name="cassandra.test.use_prepared" value="true" /> + <!-- skip flushing schema tables during tests --> + <property name="cassandra.test.flush_local_schema_changes" value="false" /> + <!-- http://cobertura.sourceforge.net/ --> <property name="cobertura.version" value="2.0.3"/> <property name="cobertura.build.dir" value="${build.dir}/cobertura"/> http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/src/java/org/apache/cassandra/db/DefinitionsUpdateVerbHandler.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/DefinitionsUpdateVerbHandler.java b/src/java/org/apache/cassandra/db/DefinitionsUpdateVerbHandler.java index e4f4e35..b849f95 100644 --- a/src/java/org/apache/cassandra/db/DefinitionsUpdateVerbHandler.java +++ b/src/java/org/apache/cassandra/db/DefinitionsUpdateVerbHandler.java @@ -47,7 +47,7 @@ public class DefinitionsUpdateVerbHandler implements IVerbHandler<Collection<Mut { public void runMayThrow() throws Exception { - SchemaKeyspace.mergeSchema(message.payload); + SchemaKeyspace.mergeSchemaAndAnnounceVersion(message.payload); } }); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/src/java/org/apache/cassandra/schema/SchemaKeyspace.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java index bc9da31..f0bdd14 100644 --- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java +++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java @@ -62,6 +62,8 @@ public final class SchemaKeyspace private static final Logger logger = LoggerFactory.getLogger(SchemaKeyspace.class); + private static final boolean FLUSH_SCHEMA_TABLES = Boolean.valueOf(System.getProperty("cassandra.test.flush_local_schema_changes", "true")); + public static final String NAME = "system_schema"; public static final String KEYSPACES = "keyspaces"; @@ -476,13 +478,13 @@ public final class SchemaKeyspace * @throws ConfigurationException If one of metadata attributes has invalid value * @throws IOException If data was corrupted during transportation or failed to apply fs operations */ - public static synchronized void mergeSchema(Collection<Mutation> mutations) throws ConfigurationException, IOException + public static synchronized void mergeSchemaAndAnnounceVersion(Collection<Mutation> mutations) throws ConfigurationException, IOException { - mergeSchema(mutations, true); + mergeSchema(mutations); Schema.instance.updateVersionAndAnnounce(); } - public static synchronized void mergeSchema(Collection<Mutation> mutations, boolean doFlush) throws IOException + public static synchronized void mergeSchema(Collection<Mutation> mutations) throws IOException { // compare before/after schemas of the affected keyspaces only Set<String> keyspaces = new HashSet<>(mutations.size()); @@ -499,7 +501,7 @@ public final class SchemaKeyspace mutations.forEach(Mutation::apply); - if (doFlush) + if (FLUSH_SCHEMA_TABLES) flush(); // with new data applied http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/src/java/org/apache/cassandra/service/MigrationManager.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/MigrationManager.java b/src/java/org/apache/cassandra/service/MigrationManager.java index c820f18..de6c7f7 100644 --- a/src/java/org/apache/cassandra/service/MigrationManager.java +++ b/src/java/org/apache/cassandra/service/MigrationManager.java @@ -471,7 +471,7 @@ public class MigrationManager { try { - SchemaKeyspace.mergeSchema(Collections.singletonList(schema), false); + SchemaKeyspace.mergeSchema(Collections.singletonList(schema)); } catch (IOException e) { @@ -499,7 +499,7 @@ public class MigrationManager { protected void runMayThrow() throws IOException, ConfigurationException { - SchemaKeyspace.mergeSchema(schema); + SchemaKeyspace.mergeSchemaAndAnnounceVersion(schema); } }); http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/src/java/org/apache/cassandra/service/MigrationTask.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/MigrationTask.java b/src/java/org/apache/cassandra/service/MigrationTask.java index 33bb35f..4e3fac3 100644 --- a/src/java/org/apache/cassandra/service/MigrationTask.java +++ b/src/java/org/apache/cassandra/service/MigrationTask.java @@ -72,7 +72,7 @@ class MigrationTask extends WrappedRunnable { try { - SchemaKeyspace.mergeSchema(message.payload); + SchemaKeyspace.mergeSchemaAndAnnounceVersion(message.payload); } catch (IOException e) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/5c2912d1/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java index 2f51803..3eb4faf 100644 --- a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java +++ b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java @@ -162,7 +162,7 @@ public class SchemaKeyspaceTest { KeyspaceMetadata ksm = Schema.instance.getKeyspaceInstance(keyspace).getMetadata(); Mutation mutation = SchemaKeyspace.makeUpdateTableMutation(ksm, oldTable, newTable, FBUtilities.timestampMicros(), false); - SchemaKeyspace.mergeSchema(Collections.singleton(mutation), true); + SchemaKeyspace.mergeSchema(Collections.singleton(mutation)); } private static void createTable(String keyspace, String cql) throws IOException @@ -171,7 +171,7 @@ public class SchemaKeyspaceTest KeyspaceMetadata ksm = KeyspaceMetadata.create(keyspace, KeyspaceParams.simple(1), Tables.of(table)); Mutation mutation = SchemaKeyspace.makeCreateTableMutation(ksm, table, FBUtilities.timestampMicros()); - SchemaKeyspace.mergeSchema(Collections.singleton(mutation), true); + SchemaKeyspace.mergeSchema(Collections.singleton(mutation)); } private static void checkInverses(CFMetaData cfm) throws Exception