Skip to content

Commit

Permalink
HBASE-26680 Close the broken writer in AsyncFSWALProvider#createAsync…
Browse files Browse the repository at this point in the history
…Writer
  • Loading branch information
sunhelly committed Mar 7, 2022
1 parent f3a48d1 commit 0be356d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,8 +101,9 @@ public static AsyncWriter createAsyncWriter(Configuration conf, FileSystem fs, P
// Configuration already does caching for the Class lookup.
Class<? extends AsyncWriter> 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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ interface AsyncWriter extends WriterBase {
CompletableFuture<Long> sync(boolean forceSync);

void append(WAL.Entry entry);

void closeWithoutTrailer();
}

/**
Expand Down

0 comments on commit 0be356d

Please sign in to comment.