hdfs: close file writer on write error and return close errors #5061
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.43) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 189 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.314
Real PR Conversation Timeline
1 comments
"Review active on #5061"
general
weight: 0.35
ska2704
The
hdfsoutput dropped the error fromFileWriter.Close(), and ifWrite()failed it returned before closing the writer at all.Close()is where the client flushes the last block and sendscompleteto the namenode, so when it fails the file stays under construction while the message is still acked. That's what made the stuck files in #5051 so hard to spot: nothing showed up in the logs.This change:
AsBytes()no longer leaves an open writer behindWrite()failsClose()error (wrapped with the file path), so the message gets retried instead of ackedTo make the write path testable without a cluster, the writer now holds a small
hdfsClientinterface (MkdirAllandCreate), andConnectwraps*hdfs.Clientin an adapter.output_test.goadds unit tests for the success path, a failingWrite, and a failingClose. The two error tests fail on the current code and pass with this change.This doesn't add erasure-coding support. colinmarc/hdfs can't write striped files (colinmarc/hdfs#318), and v1.1.3 also ignores
completereturning false, so this fix alone won't surface that case. It does mean a realClose()failure is no longer silent.Tested locally with Go 1.27.3 on macOS arm64:
go test ./internal/impl/hdfs/passes (the integration test is skipped without Docker), andgo vetandgofmt -lare clean. I didn't rungolangci-lintor the HDFS integration test.