jackjlli commented on code in PR #11574: URL: https://github.com/apache/pinot/pull/11574#discussion_r1340691844
########## pinot-controller/src/main/java/org/apache/pinot/controller/BaseControllerStarter.java: ########## @@ -549,6 +555,69 @@ protected void configure() { _serviceStatusCallbackList.add(generateServiceStatusCallback(_helixParticipantManager)); } + @VisibleForTesting + public void fixSchemaNameInTableConfig() { + AtomicInteger fixedTableCount = new AtomicInteger(); + AtomicInteger failedToFixTableCount = new AtomicInteger(); + AtomicInteger misConfiguredTableCount = new AtomicInteger(); + _helixResourceManager.getAllTables().forEach(table -> { + TableConfig tableConfig = _helixResourceManager.getTableConfig(table); + if ((tableConfig == null) || (tableConfig.getValidationConfig() == null)) { + LOGGER.warn("Failed to find table config for table: {}", table); + failedToFixTableCount.getAndIncrement(); + return; + } + String existSchemaName = tableConfig.getValidationConfig().getSchemaName(); + if (existSchemaName == null) { + // Table config is already in good status + return; + } + String rawTableName = TableNameBuilder.extractRawTableName(tableConfig.getTableName()); + if (_helixResourceManager.getSchema(rawTableName) != null) { + // If a schema named `rawTableName` already exists, then likely this is a misconfiguration. + // Reset schema name in table config to null to let the table point to the existing schema. + LOGGER.warn("Schema: {} already exists, fix the schema name in table config from {} to null", rawTableName, + existSchemaName); + misConfiguredTableCount.getAndIncrement(); + } else { + // Copy the schema current table referring to to `rawTableName` if it does not exist + Schema schema = _helixResourceManager.getSchema(existSchemaName); + if (schema == null) { + LOGGER.warn("Failed to find schema for schema name: {}", existSchemaName); + failedToFixTableCount.getAndIncrement(); + return; + } + schema.setSchemaName(rawTableName); + try { + _helixResourceManager.addSchema(schema, false, false); + LOGGER.info("Copied schema: {} to {}", existSchemaName, rawTableName); Review Comment: nit: maybe add a `TODO` here to clean up the existing schema in the next major official release? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org