From 65a80b3f53304e61d5f33e5c97f4127d40b48f95 Mon Sep 17 00:00:00 2001 From: Guangxu Cheng Date: Tue, 5 Dec 2017 20:53:15 +0800 Subject: [PATCH] HBASE-19432 Roll the specified writer in HFileOutputFormat2 --- .../hadoop/hbase/mapreduce/HFileOutputFormat2.java | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java index d7606fca76..155e4bd1e3 100644 --- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java +++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/HFileOutputFormat2.java @@ -242,7 +242,7 @@ public class HFileOutputFormat2 Cell kv = cell; // null input == user explicitly wants to flush if (row == null && kv == null) { - rollWriters(); + rollWriters(null); return; } @@ -284,7 +284,7 @@ public class HFileOutputFormat2 // This can only happen once a row is finished though if (rollRequested && Bytes.compareTo(this.previousRow, rowKey) != 0) { - rollWriters(); + rollWriters(wl); } // create a new WAL writer, if necessary @@ -345,19 +345,27 @@ public class HFileOutputFormat2 this.previousRow = rowKey; } - private void rollWriters() throws IOException { - for (WriterLength wl : this.writers.values()) { - if (wl.writer != null) { - LOG.info( - "Writer=" + wl.writer.getPath() + ((wl.written == 0)? "": ", wrote=" + wl.written)); - close(wl.writer); + private void rollWriters(WriterLength writerLength) throws IOException { + if (writerLength != null) { + closeWriter(writerLength); + } else { + for (WriterLength wl : this.writers.values()) { + closeWriter(wl); } - wl.writer = null; - wl.written = 0; } this.rollRequested = false; } + private void closeWriter(WriterLength wl) throws IOException { + if (wl.writer != null) { + LOG.info( + "Writer=" + wl.writer.getPath() + ((wl.written == 0)? "": ", wrote=" + wl.written)); + close(wl.writer); + } + wl.writer = null; + wl.written = 0; + } + /* * Create a new StoreFile.Writer. * @param family -- 2.13