From 6c78d4e6a635283f52bd8b2b4fc7cc14baaa23ff Mon Sep 17 00:00:00 2001 From: Jim Kellerman Date: Fri, 23 Jan 2009 23:09:37 +0000 Subject: [PATCH] HBASE-1148 Always flush HLog on root or meta region updates git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@737241 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../apache/hadoop/hbase/regionserver/HLog.java | 17 +++++++++-------- .../hadoop/hbase/regionserver/HRegion.java | 3 ++- .../hadoop/hbase/regionserver/TestHLog.java | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6cea83ff4e9..0c36bcf991b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ Release 0.20.0 - Unreleased HBASE-1138 Test that readers opened after a sync can see all data up to the sync (temporary until HADOOP-4379 is resolved) HBASE-1121 Cluster confused about where -ROOT- is + HBASE-1148 Always flush HLog on root or meta region updates IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HLog.java b/src/java/org/apache/hadoop/hbase/regionserver/HLog.java index fbd2f4a26ab..80edb34d531 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HLog.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HLog.java @@ -455,13 +455,12 @@ public class HLog implements HConstants, Syncable { * * @param regionName * @param tableName - * @param row - * @param columns - * @param timestamp + * @param edits + * @param sync * @throws IOException */ void append(byte [] regionName, byte [] tableName, - TreeMap edits) + TreeMap edits, boolean sync) throws IOException { if (closed) { throw new IOException("Cannot append; log is closed"); @@ -482,7 +481,7 @@ public class HLog implements HConstants, Syncable { new HLogKey(regionName, tableName, key.getRow(), seqNum[counter++]); HLogEdit logEdit = new HLogEdit(key.getColumn(), es.getValue(), key.getTimestamp()); - doWrite(logKey, logEdit); + doWrite(logKey, logEdit, sync); this.numEntries++; } @@ -520,10 +519,11 @@ public class HLog implements HConstants, Syncable { } } - private void doWrite(HLogKey logKey, HLogEdit logEdit) throws IOException { + private void doWrite(HLogKey logKey, HLogEdit logEdit, boolean sync) + throws IOException { try { this.writer.append(logKey, logEdit); - if (++unflushedEntries >= flushlogentries) { + if (sync || ++unflushedEntries >= flushlogentries) { sync(); } } catch (IOException e) { @@ -569,7 +569,8 @@ public class HLog implements HConstants, Syncable { } HLogKey logKey = new HLogKey(regionName, tableName, row, seqNum); - doWrite(logKey, logEdit); + boolean sync = regionInfo.isMetaRegion() || regionInfo.isRootRegion(); + doWrite(logKey, logEdit, sync); this.numEntries++; updateLock.notifyAll(); } diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 9d65a675e3f..01b786f3947 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1707,7 +1707,8 @@ public class HRegion implements HConstants { try { if (writeToWAL) { this.log.append(regionInfo.getRegionName(), - regionInfo.getTableDesc().getName(), updatesByColumn); + regionInfo.getTableDesc().getName(), updatesByColumn, + (regionInfo.isMetaRegion() || regionInfo.isRootRegion())); } long size = 0; for (Map.Entry e: updatesByColumn.entrySet()) { diff --git a/src/test/org/apache/hadoop/hbase/regionserver/TestHLog.java b/src/test/org/apache/hadoop/hbase/regionserver/TestHLog.java index 04bb9d3b63b..26cc9915b83 100644 --- a/src/test/org/apache/hadoop/hbase/regionserver/TestHLog.java +++ b/src/test/org/apache/hadoop/hbase/regionserver/TestHLog.java @@ -77,7 +77,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { byte [] column = Bytes.toBytes(Integer.toString(j)); edit.put(new HStoreKey(rowName, column, System.currentTimeMillis()), column); - log.append(Bytes.toBytes(Integer.toString(i)), tableName, edit); + log.append(Bytes.toBytes(Integer.toString(i)), tableName, edit, false); } } log.rollWriter(); @@ -110,7 +110,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { cols.put(new HStoreKey(row, Bytes.toBytes(Integer.toString(i)), timestamp), new byte[] { (byte)(i + '0') }); } - log.append(regionName, tableName, cols); + log.append(regionName, tableName, cols, false); long logSeqId = log.startCacheFlush(); log.completeCacheFlush(regionName, tableName, logSeqId); log.close();