From 0be356d6f80f433acd8b90fc931ddf270665698f Mon Sep 17 00:00:00 2001 From: haxiaolin Date: Mon, 7 Mar 2022 20:09:48 +0800 Subject: [PATCH] HBASE-26680 Close the broken writer in AsyncFSWALProvider#createAsyncWriter --- .../regionserver/wal/AsyncProtobufLogWriter.java | 13 +++++++++++++ .../apache/hadoop/hbase/wal/AsyncFSWALProvider.java | 7 +++++-- .../org/apache/hadoop/hbase/wal/WALProvider.java | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncProtobufLogWriter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncProtobufLogWriter.java index 0ab04076e781..6d04c00fc629 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncProtobufLogWriter.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncProtobufLogWriter.java @@ -171,6 +171,19 @@ public synchronized void close() throws IOException { this.output = null; } + @Override + public synchronized void closeWithoutTrailer() { + if (this.output == null) { + return; + } + try { + output.close(); + } catch (IOException e) { + LOG.warn("close without writing trailer failed, will not recover lease", e); + } + this.output = null; + } + public AsyncFSOutput getOutput() { return this.output; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java index 06729e2356a2..1db02b712b09 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AsyncFSWALProvider.java @@ -35,7 +35,6 @@ import org.apache.yetus.audience.InterfaceStability; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.apache.hbase.thirdparty.com.google.common.base.Throwables; import org.apache.hbase.thirdparty.io.netty.channel.Channel; import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup; @@ -102,8 +101,9 @@ public static AsyncWriter createAsyncWriter(Configuration conf, FileSystem fs, P // Configuration already does caching for the Class lookup. Class logWriterClass = conf.getClass( WRITER_IMPL, AsyncProtobufLogWriter.class, AsyncWriter.class); + AsyncWriter writer = null; try { - AsyncWriter writer = logWriterClass.getConstructor(EventLoopGroup.class, Class.class) + writer = logWriterClass.getConstructor(EventLoopGroup.class, Class.class) .newInstance(eventLoopGroup, channelClass); writer.init(fs, path, conf, overwritable, blocksize, monitor); return writer; @@ -117,6 +117,9 @@ public static AsyncWriter createAsyncWriter(Configuration conf, FileSystem fs, P } else { LOG.debug("Error instantiating log writer.", e); } + if (writer != null) { + writer.closeWithoutTrailer(); + } Throwables.propagateIfPossible(e, IOException.class); throw new IOException("cannot get log writer", e); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java index 01c1d11ead70..02d6327855f6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java @@ -108,6 +108,8 @@ interface AsyncWriter extends WriterBase { CompletableFuture sync(boolean forceSync); void append(WAL.Entry entry); + + void closeWithoutTrailer(); } /**