Skip to content

Commit 932540d

Browse files
committed
HBASE-26680 Close and do not write trailer for the broken WAL writer
1 parent f3a48d1 commit 932540d

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AbstractProtobufLogWriter.java

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -171,38 +171,43 @@ private boolean initializeCompressionContext(Configuration conf, Path path) thro
171171
public void init(FileSystem fs, Path path, Configuration conf, boolean overwritable,
172172
long blocksize, StreamSlowMonitor monitor) throws IOException,
173173
StreamLacksCapabilityException {
174-
this.conf = conf;
175-
boolean doCompress = initializeCompressionContext(conf, path);
176-
this.trailerWarnSize = conf.getInt(WAL_TRAILER_WARN_SIZE, DEFAULT_WAL_TRAILER_WARN_SIZE);
177-
int bufferSize = CommonFSUtils.getDefaultBufferSize(fs);
178-
short replication = (short) conf.getInt("hbase.regionserver.hlog.replication",
179-
CommonFSUtils.getDefaultReplication(fs, path));
180-
181-
initOutput(fs, path, overwritable, bufferSize, replication, blocksize, monitor);
182-
183-
boolean doTagCompress = doCompress &&
184-
conf.getBoolean(CompressionContext.ENABLE_WAL_TAGS_COMPRESSION, true);
185-
boolean doValueCompress = doCompress &&
186-
conf.getBoolean(CompressionContext.ENABLE_WAL_VALUE_COMPRESSION, false);
187-
WALHeader.Builder headerBuilder = WALHeader.newBuilder()
188-
.setHasCompression(doCompress)
189-
.setHasTagCompression(doTagCompress)
190-
.setHasValueCompression(doValueCompress);
191-
if (doValueCompress) {
192-
headerBuilder.setValueCompressionAlgorithm(
193-
CompressionContext.getValueCompressionAlgorithm(conf).ordinal());
194-
}
195-
length.set(writeMagicAndWALHeader(ProtobufLogReader.PB_WAL_MAGIC,
196-
buildWALHeader(conf, headerBuilder)));
174+
try {
175+
this.conf = conf;
176+
boolean doCompress = initializeCompressionContext(conf, path);
177+
this.trailerWarnSize = conf.getInt(WAL_TRAILER_WARN_SIZE, DEFAULT_WAL_TRAILER_WARN_SIZE);
178+
int bufferSize = CommonFSUtils.getDefaultBufferSize(fs);
179+
short replication = (short) conf.getInt("hbase.regionserver.hlog.replication",
180+
CommonFSUtils.getDefaultReplication(fs, path));
181+
182+
initOutput(fs, path, overwritable, bufferSize, replication, blocksize, monitor);
183+
184+
boolean doTagCompress =
185+
doCompress && conf.getBoolean(CompressionContext.ENABLE_WAL_TAGS_COMPRESSION, true);
186+
boolean doValueCompress =
187+
doCompress && conf.getBoolean(CompressionContext.ENABLE_WAL_VALUE_COMPRESSION, false);
188+
WALHeader.Builder headerBuilder =
189+
WALHeader.newBuilder().setHasCompression(doCompress).setHasTagCompression(doTagCompress)
190+
.setHasValueCompression(doValueCompress);
191+
if (doValueCompress) {
192+
headerBuilder.setValueCompressionAlgorithm(
193+
CompressionContext.getValueCompressionAlgorithm(conf).ordinal());
194+
}
195+
length.set(writeMagicAndWALHeader(ProtobufLogReader.PB_WAL_MAGIC,
196+
buildWALHeader(conf, headerBuilder)));
197197

198-
initAfterHeader(doCompress);
198+
initAfterHeader(doCompress);
199199

200-
// instantiate trailer to default value.
201-
trailer = WALTrailer.newBuilder().build();
200+
// instantiate trailer to default value.
201+
trailer = WALTrailer.newBuilder().build();
202202

203-
if (LOG.isTraceEnabled()) {
204-
LOG.trace("Initialized protobuf WAL={}, compression={}, tagCompression={}" +
205-
", valueCompression={}", path, doCompress, doTagCompress, doValueCompress);
203+
if (LOG.isTraceEnabled()) {
204+
LOG.trace("Initialized protobuf WAL={}, compression={}, tagCompression={}"
205+
+ ", valueCompression={}", path, doCompress, doTagCompress, doValueCompress);
206+
}
207+
} catch (Exception e) {
208+
LOG.warn("Init output failed, path={}", path, e);
209+
closeOutput();
210+
throw e;
206211
}
207212
}
208213

@@ -270,6 +275,8 @@ protected abstract void initOutput(FileSystem fs, Path path, boolean overwritabl
270275
short replication, long blockSize, StreamSlowMonitor monitor)
271276
throws IOException, StreamLacksCapabilityException;
272277

278+
protected abstract void closeOutput();
279+
273280
/**
274281
* return the file length after written.
275282
*/

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/AsyncProtobufLogWriter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.apache.hbase.thirdparty.com.google.common.base.Throwables;
4444
import org.apache.hbase.thirdparty.io.netty.channel.Channel;
4545
import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup;
46-
4746
import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALHeader;
4847
import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.WALTrailer;
4948

@@ -184,6 +183,17 @@ protected void initOutput(FileSystem fs, Path path, boolean overwritable, int bu
184183
this.asyncOutputWrapper = new OutputStreamWrapper(output);
185184
}
186185

186+
@Override
187+
protected void closeOutput() {
188+
if (this.output != null) {
189+
try {
190+
this.output.close();
191+
} catch (IOException e) {
192+
LOG.warn("Close output failed", e);
193+
}
194+
}
195+
}
196+
187197
private long write(Consumer<CompletableFuture<Long>> action) throws IOException {
188198
CompletableFuture<Long> future = new CompletableFuture<>();
189199
action.accept(future);

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/ProtobufLogWriter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ protected void initOutput(FileSystem fs, Path path, boolean overwritable, int bu
131131
}
132132
}
133133

134+
@Override
135+
protected void closeOutput() {
136+
if (this.output != null) {
137+
try {
138+
this.output.close();
139+
} catch (IOException e) {
140+
LOG.warn("Close output failed", e);
141+
}
142+
}
143+
}
144+
134145
@Override
135146
protected long writeMagicAndWALHeader(byte[] magic, WALHeader header) throws IOException {
136147
output.write(magic);

hbase-server/src/main/java/org/apache/hadoop/hbase/wal/FSHLogProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ public static Writer createWriter(final Configuration conf, final FileSystem fs,
9090
} else {
9191
LOG.debug("Error instantiating log writer.", e);
9292
}
93-
if (writer != null) {
94-
try{
95-
writer.close();
96-
} catch(IOException ee){
97-
LOG.error("cannot close log writer", ee);
98-
}
99-
}
10093
throw new IOException("cannot get log writer", e);
10194
}
10295
}

0 commit comments

Comments
 (0)