/** * Ensure the schema of a pseudo-system keyspace (a distributed system keyspace: traces, auth and the so-called distributedKeyspace), * is up to date with what we expected (creating it if it doesn't exist and updating tables that may have been upgraded). */ private void maybeAddOrUpdateKeyspace(KeyspaceMetadata expected) { // Note that want to deal with the keyspace and its table a bit differently: for the keyspace definition // itself, we want to create it if it doesn't exist yet, but if it does exist, we don't want to modify it, // because user can modify the definition to change the replication factor (#6016) and we don't want to // override it. For the tables however, we have to deal with the fact that new version can add new columns // (#8162 being an example), so even if the table definition exists, we still need to force the "current" // version of the schema, the one the node will be expecting. KeyspaceMetadata defined = Schema.instance.getKSMetaData(expected.name); // If the keyspace doesn't exist, create it if (defined == null) { maybeAddKeyspace(expected); defined = Schema.instance.getKSMetaData(expected.name); } // While the keyspace exists, it might miss table or have outdated one // There is also the potential for a race, as schema migrations add the bare // keyspace into Schema.instance before adding its tables, so double check that // all the expected tables are present for (CFMetaData expectedTable : expected.tables) { CFMetaData definedTable = defined.tables.get(expectedTable.cfName).orElse(null); if (definedTable == null || !definedTable.equals(expectedTable)) MigrationManager.forceAnnounceNewColumnFamily(expectedTable); } }
/** * Ensure the schema of a pseudo-system keyspace (a distributed system keyspace: traces, auth and the so-called distributedKeyspace), * is up to date with what we expected (creating it if it doesn't exist and updating tables that may have been upgraded). */ private void maybeAddOrUpdateKeyspace(KeyspaceMetadata expected) { // Note that want to deal with the keyspace and its table a bit differently: for the keyspace definition // itself, we want to create it if it doesn't exist yet, but if it does exist, we don't want to modify it, // because user can modify the definition to change the replication factor (#6016) and we don't want to // override it. For the tables however, we have to deal with the fact that new version can add new columns // (#8162 being an example), so even if the table definition exists, we still need to force the "current" // version of the schema, the one the node will be expecting. KeyspaceMetadata defined = Schema.instance.getKSMetaData(expected.name); // If the keyspace doesn't exist, create it if (defined == null) { maybeAddKeyspace(expected); defined = Schema.instance.getKSMetaData(expected.name); } // While the keyspace exists, it might miss table or have outdated one // There is also the potential for a race, as schema migrations add the bare // keyspace into Schema.instance before adding its tables, so double check that // all the expected tables are present for (CFMetaData expectedTable : expected.tables) { CFMetaData definedTable = defined.tables.get(expectedTable.cfName).orElse(null); if (definedTable == null || !definedTable.equals(expectedTable)) MigrationManager.forceAnnounceNewColumnFamily(expectedTable); } }
/** * Ensure the schema of a pseudo-system keyspace (a distributed system keyspace: traces, auth and the so-called distributedKeyspace), * is up to date with what we expected (creating it if it doesn't exist and updating tables that may have been upgraded). */ private void maybeAddOrUpdateKeyspace(KeyspaceMetadata expected) { // Note that want to deal with the keyspace and its table a bit differently: for the keyspace definition // itself, we want to create it if it doesn't exist yet, but if it does exist, we don't want to modify it, // because user can modify the definition to change the replication factor (#6016) and we don't want to // override it. For the tables however, we have to deal with the fact that new version can add new columns // (#8162 being an example), so even if the table definition exists, we still need to force the "current" // version of the schema, the one the node will be expecting. KeyspaceMetadata defined = Schema.instance.getKSMetaData(expected.name); // If the keyspace doesn't exist, create it if (defined == null) { maybeAddKeyspace(expected); defined = Schema.instance.getKSMetaData(expected.name); } // While the keyspace exists, it might miss table or have outdated one // There is also the potential for a race, as schema migrations add the bare // keyspace into Schema.instance before adding its tables, so double check that // all the expected tables are present for (CFMetaData expectedTable : expected.tables) { CFMetaData definedTable = defined.tables.get(expectedTable.cfName).orElse(null); if (definedTable == null || !definedTable.equals(expectedTable)) MigrationManager.forceAnnounceNewColumnFamily(expectedTable); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof ColumnFamily)) return false; ColumnFamily comparison = (ColumnFamily) o; return metadata.equals(comparison.metadata) && deletionInfo().equals(comparison.deletionInfo()) && ByteBufferUtil.compareUnsigned(digest(this), digest(comparison)) == 0; }