apache/hadoop · error · UnsupportedOperationException
hsync not supported by {out}
Error message
hsync not supported by {out} What it means
BufferedIOStatisticsOutputStream.hsync() mirrors hflush(): the inner stream must implement org.apache.hadoop.fs.Syncable for the sync to be forwarded after the buffer flush. If the inner stream is not Syncable and downgradeSyncable=false, UnsupportedOperationException('hsync not supported by <out>') is thrown.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/statistics/BufferedIOStatisticsOutputStream.java:150
/**
* If the inner stream is Syncable, flush the buffer and then
* invoke the inner stream's hsync() operation.
*
* Otherwise: throw an exception, unless the stream was constructed with
* {@link #downgradeSyncable} set to true, in which case the stream
* is just flushed.
* @throws IOException IO Problem
* @throws UnsupportedOperationException if the inner class is not syncable
*/
@Override
public void hsync() throws IOException {
if (out instanceof Syncable) {
flush();
((Syncable) out).hsync();
} else {
if (!downgradeSyncable) {
throw new UnsupportedOperationException("hsync not supported by "
+ out);
} else {
flush();
}
}
}
}
View on GitHub (pinned to 2add963021)
Solutions
- Construct with downgradeSyncable=true if a plain flush is acceptable
- Ensure the inner stream implements Syncable (wrap it in FSDataOutputStream)
- Check 'out instanceof Syncable' before calling hsync()
Example fix
// before
BufferedIOStatisticsOutputStream out =
new BufferedIOStatisticsOutputStream(inner, false);
out.hsync(); // UnsupportedOperationException when inner is not Syncable
// after
BufferedIOStatisticsOutputStream out =
new BufferedIOStatisticsOutputStream(inner, true);
out.hsync(); // degrades to flush() Defensive patterns
Strategy: type-guard
Validate before calling
if (out instanceof Syncable) {
statsStream.hsync();
} else {
statsStream.flush(); // or construct the wrapper with downgradeSyncable=true
} Type guard
static boolean supportsHsync(OutputStream out) {
return out instanceof org.apache.hadoop.fs.Syncable;
} Try / catch
Catch UnsupportedOperationException from hsync() and fall back to flush() only as a last resort; the constructor flag downgradeSyncable=true makes the downgrade explicit and non-throwing.
Prevention
- Set downgradeSyncable=true unless you require the Syncable durability contract
- Verify the innermost stream of a layered pipeline implements Syncable
- Test hsync paths with realistic inner streams, not bare mocks
When it happens
Trigger: Constructing the wrapper over a non-Syncable stream (compression, crypto, in-memory, mock streams) with downgradeSyncable=false, then calling hsync() to force durability.
Common situations: Durability flushes ('hsync' for data + metadata) attempted on instrumented pipelines whose bottom layer is not Syncable; tests with mock inner streams.
Related errors
- hflush not supported by {out}
- write (b[{b.length}], {off}, {len})
- catch exception when allocating BosBlockBuffer:
- Stream closed
- %s: Stream is closed!
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/e865fcc1bd489ff7.
Report an issue: GitHub.