{"record":{"id":"a5e302a182933f24","repo":"apache/flink","slug":"exception-in-finalizeglobal","errorCode":null,"errorMessage":"Exception in finalizeGlobal","messagePattern":"Exception in finalizeGlobal","errorType":"exception","errorClass":"TableException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/FileSystemOutputFormat.java","lineNumber":160,"sourceCode":"                            stagingPath,\n                            partitionColumns.length,\n                            isToLocal,\n                            identifier,\n                            staticPartitions,\n                            policies);\n            committer.commitPartitions(\n                    (subtaskIndex, attemptNumber) -> {\n                        try {\n                            if (context.getFinishedAttempt(subtaskIndex) == attemptNumber) {\n                                return true;\n                            }\n                        } catch (IllegalArgumentException ignored) {\n                            // maybe met a dir or file which does not belong to this job\n                        }\n                        return false;\n                    });\n        } catch (Exception e) {\n            throw new TableException(\"Exception in finalizeGlobal\", e);\n        } finally {\n            try {\n                fsFactory.create(stagingPath.toUri()).delete(stagingPath, true);\n            } catch (IOException ignore) {\n            }\n        }\n    }\n\n    @Override\n    public void configure(Configuration parameters) {\n        this.parameters = parameters;\n    }\n\n    @Override\n    public void open(InitializationContext context) throws IOException {\n        try {\n            PartitionTempFileManager fileManager =\n                    new PartitionTempFileManager(","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/FileSystemOutputFormat.java#L142-L178","documentation":"FileSystemOutputFormat.finalizeGlobal executes after all parallel subtasks finish, committing partitions and cleaning up the staging directory. Any exception during partition commitment (metaStoreFactory operations, commit logic, or finished-attempt checks) is wrapped in a TableException. The finally block always attempts to delete the staging directory regardless of success or failure.","triggerScenarios":"An exception occurs during finalizeGlobal: the partition committer fails (e.g. metastore connection error in HiveMetastore), the file system operation during commit fails, or the context.getFinishedAttempt call logic encounters unexpected state. The original exception is chained as the cause of the TableException.","commonSituations":"Hive metastore is down or unreachable during global finalization. File system rename or commit operation fails (S3 eventual consistency, HDFS safe mode). Partition commit policy encounters an unexpected file structure. Network issue during the commit phase of a large batch write.","solutions":["Examine the chained cause exception in the stack trace to identify the root failure (metastore, file system, or commit logic).","If the cause is metastore connectivity, ensure the metastore service is running and reachable from the JobManager.","If the cause is file system related, verify HDFS/S3 availability and that the output directory is writable.","Retry the job after resolving the underlying infrastructure issue; the staging directory is cleaned in finally."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    outputFormat.finalizeGlobal(context);\n} catch (TableException e) {\n    // Examine e.getCause() for the root failure\n    Throwable root = e.getCause();\n    LOG.error(\"Finalize failed due to: {}\", root.getMessage(), root);\n    // Depending on root cause: retry, alert, or fail the job\n    throw e;\n}","preventionTips":["Ensure metastore (Hive, etc.) is reachable and healthy before running finalizeGlobal.","Monitor file system health during long-running batch jobs.","Implement job-level retry for transient infrastructure failures during finalization.","Check the chained cause exception for the root failure, not the wrapper."],"tags":["output-format","finalize-global","partition-commit","table-exception","flink"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}