This is an automated email from the ASF dual-hosted git repository. marcuse pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push: new 4d29a1c75e Merge pre-existing schema with the system defined one during upgrade 4d29a1c75e is described below commit 4d29a1c75e4c7a5493d5601c7a907b75e042c5f9 Author: Marcus Eriksson <marc...@apache.org> AuthorDate: Thu May 2 09:21:50 2024 +0200 Merge pre-existing schema with the system defined one during upgrade Patch by marcuse; reviewed by Sam Tunnicliffe for CASSANDRA-19615 --- .../apache/cassandra/schema/DistributedSchema.java | 28 +++++++++++++++++----- .../tcm/transformations/cms/Initialize.java | 6 ++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/java/org/apache/cassandra/schema/DistributedSchema.java b/src/java/org/apache/cassandra/schema/DistributedSchema.java index a837b0773d..3bac327c17 100644 --- a/src/java/org/apache/cassandra/schema/DistributedSchema.java +++ b/src/java/org/apache/cassandra/schema/DistributedSchema.java @@ -114,16 +114,32 @@ public class DistributedSchema implements MetadataValue<DistributedSchema> public static DistributedSchema fromSystemTables(Keyspaces keyspaces, Set<String> knownDatacenters) { if (!keyspaces.containsKeyspace(SchemaConstants.METADATA_KEYSPACE_NAME)) - keyspaces = keyspaces.withAddedOrReplaced(Keyspaces.of(DistributedMetadataLogKeyspace.initialMetadata(knownDatacenters), - TraceKeyspace.metadata(), - SystemDistributedKeyspace.metadata(), - AuthKeyspace.metadata())); + { + Keyspaces kss = Keyspaces.of(DistributedMetadataLogKeyspace.initialMetadata(knownDatacenters), + TraceKeyspace.metadata(), + SystemDistributedKeyspace.metadata(), + AuthKeyspace.metadata()); + for (KeyspaceMetadata ksm : keyspaces) // on disk keyspaces + kss = kss.withAddedOrUpdated(kss.get(ksm.name) + .map(k -> merged(k, ksm)) + .orElse(ksm)); + keyspaces = kss; + } return new DistributedSchema(keyspaces, Epoch.UPGRADE_GOSSIP); } - public void initializeKeyspaceInstances(DistributedSchema prev) + /** + * merges any tables in `mergeFrom` to `mergeTo` unless they already exist there. + */ + private static KeyspaceMetadata merged(KeyspaceMetadata mergeTo, KeyspaceMetadata mergeFrom) { - initializeKeyspaceInstances(prev, true); + Tables newTables = mergeTo.tables; + for (TableMetadata metadata : mergeFrom.tables) + { + if (!newTables.containsTable(metadata.id)) + newTables = newTables.with(metadata); + } + return mergeTo.withSwapped(newTables); } public void initializeKeyspaceInstances(DistributedSchema prev, boolean loadSSTables) diff --git a/src/java/org/apache/cassandra/tcm/transformations/cms/Initialize.java b/src/java/org/apache/cassandra/tcm/transformations/cms/Initialize.java index 8103e14f92..11c2ed4d31 100644 --- a/src/java/org/apache/cassandra/tcm/transformations/cms/Initialize.java +++ b/src/java/org/apache/cassandra/tcm/transformations/cms/Initialize.java @@ -69,7 +69,11 @@ public class Initialize extends ForceSnapshot public Result execute(ClusterMetadata prev) { ClusterMetadata next = baseState; - DistributedSchema initialSchema = new DistributedSchema(setUpDistributedSystemKeyspaces(next)); + // when upgrading the schema is read from disk and set correctly in baseState, but we still need to + // make sure that lastModified is bumped, otherwise the keyspace instances are not created + DistributedSchema initialSchema = new DistributedSchema(next.schema.getKeyspaces().get(SystemDistributedKeyspace.NAME).isEmpty() + ? setUpDistributedSystemKeyspaces(next) + : next.schema.getKeyspaces()); ClusterMetadata.Transformer transformer = next.transformer().with(initialSchema); return Transformation.success(transformer, MetaStrategy.affectedRanges(prev)); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org