{"record":{"id":"1dfd1400bcb137b8","repo":"prestodb/presto","slug":"hive-writer-close-error-1dfd14","errorCode":"HIVE_WRITER_CLOSE_ERROR","errorMessage":"Error committing write to Hive","messagePattern":"Error committing write to Hive","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/RecordFileWriter.java","lineNumber":194,"sourceCode":"\n        try {\n            recordWriter.write(serializer.serialize(row, tableInspector));\n        }\n        catch (SerDeException | IOException e) {\n            throw new PrestoException(HIVE_WRITER_DATA_ERROR, e);\n        }\n    }\n\n    @Override\n    public Optional<Page> commit()\n    {\n        try {\n            recordWriter.close(false);\n            committed = true;\n            return Optional.empty();\n        }\n        catch (IOException e) {\n            throw new PrestoException(HIVE_WRITER_CLOSE_ERROR, \"Error committing write to Hive\", e);\n        }\n    }\n\n    @Override\n    public void rollback()\n    {\n        try {\n            try {\n                recordWriter.close(true);\n            }\n            finally {\n                // perform explicit deletion here as implementations of RecordWriter.close() often ignore the abort flag.\n                path.getFileSystem(conf).delete(path, false);\n            }\n        }\n        catch (IOException e) {\n            throw new PrestoException(HIVE_WRITER_CLOSE_ERROR, \"Error rolling back write to Hive\", e);\n        }","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/RecordFileWriter.java#L176-L212","documentation":"RecordFileWriter.commit() closes the underlying Hive RecordWriter to finalize the output file. If closing throws an IOException, the failure is wrapped in HIVE_WRITER_CLOSE_ERROR with this message. The output file could not be finalized and the write should be treated as failed.","triggerScenarios":"recordWriter.close(false) throwing IOException at the end of an INSERT using a record-based format (TextFile/SequenceFile etc.) — usually an I/O failure flushing final bytes to HDFS.","commonSituations":"HDFS DataNode loss or network error during the final flush; disk full/quota at commit time; buggy custom RecordWriter implementations that throw on close; long-running writes hitting a cluster change (restart, decommission).","solutions":["Retry the query after confirming HDFS is healthy — most causes are transient I/O faults.","Inspect the wrapped IOException to find the storage-level problem (quota, DataNode, permissions).","Check remaining HDFS quota and repair the write path if files were left in staging.","If a custom RecordWriter/InputFormat is in use, verify its close() implementation is correct."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    executeInsert(sql);\n} catch (PrestoException e) {\n    if (e.getErrorCode() == HiveErrorCode.HIVE_WRITER_CLOSE_ERROR.toErrorCode().getId()\n            && e.getCause() instanceof IOException) {\n        // verify HDFS health then retry; clean up staging leftovers\n    }\n}","preventionTips":["Ensure HDFS quota and disk headroom before large record-file writes.","Avoid concurrent maintenance (node restarts, decommissions) during INSERTs.","Audit custom RecordWriter implementations for correct close() behavior."],"tags":["hive","record-writer","commit","io","close"],"backgroundTag":"writer-close-error","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}