{"record":{"id":"edd0569c2951e185","repo":"apache/dolphinscheduler","slug":"query-t-ds-schedules-error","errorCode":null,"errorMessage":"Query t_ds_schedules error","messagePattern":"Query t_ds_schedules error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java","lineNumber":242,"sourceCode":"    }\n\n    private Map<String, Object> getSchedulerByProcessDefinitionCode(Long processDefinitionCode) {\n        try (\n                Connection connection = dataSource.getConnection();\n                PreparedStatement preparedStatement = connection\n                        .prepareStatement(\"select  * from t_ds_schedules where process_definition_code = ?\")) {\n            preparedStatement.setLong(1, processDefinitionCode);\n\n            try (ResultSet resultSet = preparedStatement.executeQuery()) {\n                while (resultSet.next()) {\n                    Map<String, Object> row = new HashMap<>();\n                    row.put(\"tenant_code\", resultSet.getString(\"tenant_code\"));\n                    return row;\n                }\n            }\n            return Collections.emptyMap();\n        } catch (Exception ex) {\n            throw new RuntimeException(\"Query t_ds_schedules error\", ex);\n        }\n    }\n\n    private void updateProjectCodeInProcessInstance(Integer processInstanceId, Long projectCode, String tenantCode,\n                                                    String executorName) {\n        try (\n                Connection connection = dataSource.getConnection();\n                PreparedStatement preparedStatement = connection.prepareStatement(\n                        \"update t_ds_process_instance set project_code = ?, tenant_code = ?, executor_name = ? where id = ?\")) {\n            preparedStatement.setLong(1, projectCode);\n            preparedStatement.setString(2, tenantCode);\n            preparedStatement.setString(3, executorName);\n            preparedStatement.setInt(4, processInstanceId);\n            preparedStatement.executeUpdate();\n        } catch (Exception ex) {\n            throw new RuntimeException(\"Update t_ds_process_instance error\", ex);\n        }\n    }","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-tools/src/main/java/org/apache/dolphinscheduler/tools/datasource/upgrader/v320/V320DolphinSchedulerUpgrader.java#L224-L260","documentation":"Thrown by V320DolphinSchedulerUpgrader.getSchedulerByProcessDefinitionCode when the SELECT against t_ds_schedules fails. The upgrade uses scheduler rows to derive tenant_code while backfilling process instances. Any exception in the JDBC block is wrapped in this RuntimeException.","triggerScenarios":"Running the 3.2.0 upgrade when t_ds_schedules is missing, lacks expected columns (e.g. tenant_code / process_definition_code), or the connection fails during scheduler lookup.","commonSituations":"Metadata DB partially migrated so t_ds_schedules schema differs; DB user without SELECT privilege; transient DB outage mid-upgrade.","solutions":["Inspect the cause chain for the real SQLException","Confirm t_ds_schedules exists and matches the 3.2.0 schema","Grant SELECT on t_ds_schedules to the upgrade user","Re-run the upgrade after restoring DB connectivity/schema"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try (Connection c = dataSource.getConnection();\n     ResultSet rs = c.createStatement().executeQuery(\n         \"select process_definition_code, tenant_code from t_ds_schedules where 1=0\")) {\n} catch (SQLException e) {\n    throw new IllegalStateException(\"t_ds_schedules unreadable or missing columns: \" + e.getMessage(), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    upgrader.upgrade();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Query t_ds_schedules error\")) {\n        log.error(\"Scheduler lookup failed: {}\", e.getCause(), e);\n    } else { throw e; }\n}","preventionTips":["Verify t_ds_schedules matches the expected schema before upgrading","Grant the migration user SELECT on schedule tables","Test the upgrade against a staging copy of the metadata DB"],"tags":["database","jdbc","upgrade","sql"],"backgroundTag":"database-query-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}