@InterfaceAudience.Private public class AsyncProtobufLogWriter extends AbstractProtobufLogWriter implements AsyncFSWALProvider.AsyncWriter
Modifier and Type | Class and Description |
---|---|
private static class |
AsyncProtobufLogWriter.OutputStreamWrapper |
Modifier and Type | Field and Description |
---|---|
private OutputStream |
asyncOutputWrapper |
private Class<? extends org.apache.hbase.thirdparty.io.netty.channel.Channel> |
channelClass |
private org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup |
eventLoopGroup |
private long |
finalSyncedLength
Save
AsyncFSOutput.getSyncedLength() when output is closed. |
private static org.slf4j.Logger |
LOG |
private AsyncFSOutput |
output |
private long |
waitTimeout |
cellEncoder, compressionContext, compressor, conf, length, trailer, trailerWarnSize, trailerWritten
Constructor and Description |
---|
AsyncProtobufLogWriter(org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup eventLoopGroup,
Class<? extends org.apache.hbase.thirdparty.io.netty.channel.Channel> channelClass) |
Modifier and Type | Method and Description |
---|---|
void |
append(WAL.Entry entry) |
void |
close() |
protected void |
closeOutputIfNecessary()
It is straight forward to close the output, do not need to write trailer like the Writer.close
|
AsyncFSOutput |
getOutput() |
protected OutputStream |
getOutputStreamForCellEncoder() |
long |
getSyncedLength()
NOTE: We add this method for
WALFileLengthProvider used for replication, considering
the case if we use AsyncFSWAL ,we write to 3 DNs concurrently, according to the
visibility guarantee of HDFS, the data will be available immediately when arriving at DN
since all the DNs will be considered as the last one in pipeline. |
protected String |
getWriterClassName() |
protected void |
initOutput(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path,
boolean overwritable,
int bufferSize,
short replication,
long blockSize,
StreamSlowMonitor monitor) |
CompletableFuture<Long> |
sync(boolean forceSync) |
protected long |
writeMagicAndWALHeader(byte[] magic,
org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header)
return the file length after written.
|
private long |
writeWALMetadata(Consumer<CompletableFuture<Long>> action) |
protected long |
writeWALTrailerAndMagic(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALTrailer trailer,
byte[] magic) |
buildSecureWALHeader, buildWALHeader, getLength, init, initAfterHeader, secureInitAfterHeader, setEncryptor, setWALTrailer, writeWALTrailer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
init
getLength
private static final org.slf4j.Logger LOG
private final org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup eventLoopGroup
private final Class<? extends org.apache.hbase.thirdparty.io.netty.channel.Channel> channelClass
private volatile AsyncFSOutput output
private volatile long finalSyncedLength
AsyncFSOutput.getSyncedLength()
when output
is closed.private OutputStream asyncOutputWrapper
private long waitTimeout
public AsyncProtobufLogWriter(org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup eventLoopGroup, Class<? extends org.apache.hbase.thirdparty.io.netty.channel.Channel> channelClass)
protected String getWriterClassName()
getWriterClassName
in class AbstractProtobufLogWriter
public void append(WAL.Entry entry)
append
in interface WALProvider.AsyncWriter
public CompletableFuture<Long> sync(boolean forceSync)
sync
in interface WALProvider.AsyncWriter
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public AsyncFSOutput getOutput()
protected void initOutput(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, boolean overwritable, int bufferSize, short replication, long blockSize, StreamSlowMonitor monitor) throws IOException, CommonFSUtils.StreamLacksCapabilityException
initOutput
in class AbstractProtobufLogWriter
IOException
CommonFSUtils.StreamLacksCapabilityException
protected void closeOutputIfNecessary()
AbstractProtobufLogWriter
closeOutputIfNecessary
in class AbstractProtobufLogWriter
private long writeWALMetadata(Consumer<CompletableFuture<Long>> action) throws IOException
IOException
protected long writeMagicAndWALHeader(byte[] magic, org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader header) throws IOException
AbstractProtobufLogWriter
writeMagicAndWALHeader
in class AbstractProtobufLogWriter
IOException
protected long writeWALTrailerAndMagic(org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALTrailer trailer, byte[] magic) throws IOException
writeWALTrailerAndMagic
in class AbstractProtobufLogWriter
IOException
protected OutputStream getOutputStreamForCellEncoder()
getOutputStreamForCellEncoder
in class AbstractProtobufLogWriter
public long getSyncedLength()
WALProvider.WriterBase
WALFileLengthProvider
used for replication, considering
the case if we use AsyncFSWAL
,we write to 3 DNs concurrently, according to the
visibility guarantee of HDFS, the data will be available immediately when arriving at DN
since all the DNs will be considered as the last one in pipeline. This means replication may
read uncommitted data and replicate it to the remote cluster and cause data inconsistency.
The method WALProvider.WriterBase.getLength()
may return length which just in hdfs client buffer
and not successfully synced to HDFS, so we use this method to return the length successfully
synced to HDFS and replication thread could only read writing WAL file limited by this
length. see also HBASE-14004 and this document for more details:
https://docs.google.com/document/d/11AyWtGhItQs6vsLRIx32PwTxmBY3libXwGXI25obVEY/edit#getSyncedLength
in interface WALProvider.WriterBase
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.