{"record":{"id":"dbef35b86bc7ff70","repo":"prestodb/presto","slug":"hive-writer-close-error","errorCode":"HIVE_WRITER_CLOSE_ERROR","errorMessage":"Error rolling back write to Hive","messagePattern":"Error rolling back write to Hive","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-hive/src/main/java/com/facebook/presto/hive/HivePageSink.java","lineNumber":311,"sourceCode":"    }\n\n    private void doAbort()\n    {\n        Optional<Exception> rollbackException = Optional.empty();\n        for (HiveWriter writer : writers) {\n            // writers can contain nulls if an exception is thrown when doAppend expends the writer list\n            if (writer != null) {\n                try {\n                    writer.rollback();\n                }\n                catch (Exception e) {\n                    log.warn(\"exception '%s' while rollback on %s\", e, writer);\n                    rollbackException = Optional.of(e);\n                }\n            }\n        }\n        if (rollbackException.isPresent()) {\n            throw new PrestoException(HIVE_WRITER_CLOSE_ERROR, \"Error rolling back write to Hive\", rollbackException.get());\n        }\n    }\n\n    @Override\n    public CompletableFuture<?> appendPage(Page page)\n    {\n        if (page.getPositionCount() > 0) {\n            // Must be wrapped in doAs entirely\n            // Implicit FileSystem initializations are possible in HiveRecordWriter#addRow or #createWriter\n            hdfsEnvironment.doAs(session.getUser(), () -> doAppend(page));\n        }\n\n        return NOT_BLOCKED;\n    }\n\n    private void doAppend(Page page)\n    {\n        while (page.getPositionCount() > MAX_PAGE_POSITIONS) {","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-hive/src/main/java/com/facebook/presto/hive/HivePageSink.java#L293-L329","documentation":"HivePageSink.doAbort attempts to roll back every open writer when a write is aborted. If any writer's rollback itself throws, the sink wraps that exception in HIVE_WRITER_CLOSE_ERROR with this message, preserving the original as cause. It signals failure during cleanup of a failed write, not the original write failure.","triggerScenarios":"Query failure or cancellation triggers doAbort(); a writer's rollback() call throws (e.g. underlying writer.close/abort raised an IOException, or the original write error left the writer in a broken state).","commonSituations":"Node losing connection to storage mid-write, ORC/Parquet writer throwing while aborting an in-progress file, disk full on local spill/staging paths during abort.","solutions":["Inspect the cause exception attached to this PrestoException; it contains the real rollback failure.","Check storage connectivity/permissions and free space on staging directories.","Retry the query; abort-time rollback failures usually leave no committed data since the write was already aborted.","If reproducible on a specific format/compression, upgrade the Hive connector or disable that writer type."],"exampleFix":"// The thrown exception carries the root cause; surface it\ntry { ... } catch (PrestoException e) {\n  log.error(\"rollback failed: %s\", e.getCause()); // cause is the writer's rollback exception\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    // sink operation / query\n} catch (PrestoException e) {\n    if (\"HIVE_WRITER_CLOSE_ERROR\".equals(e.getErrorCode().getName())) {\n        Throwable root = e.getCause(); // real rollback failure\n        log.error(\"Writer rollback failed: %s\", root);\n    }\n    throw e;\n}","preventionTips":["Ensure staging directories have adequate disk space and correct permissions.","Monitor storage backend connectivity; transient I/O failures during abort cause this.","Always read getCause() — the message alone hides the real failure.","Keep the Hive connector up to date to pick up writer abort-path fixes."],"tags":["hive","sink","rollback","writer-close"],"backgroundTag":"writer-rollback-failure","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"}