From 0abcfa0ed70db2a3ffc0b26237a774bb6ee30b0d Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Fri, 4 Jun 2010 16:08:41 +0000 Subject: [PATCH] HBASE-2667 TestHLog.testSplit failing in trunk git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@951471 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../hadoop/hbase/regionserver/wal/HLog.java | 10 +++++----- .../hadoop/hbase/regionserver/wal/HLogKey.java | 15 +++++++-------- .../hadoop/hbase/regionserver/wal/TestHLog.java | 15 +++++++++++---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7e6bd7d60cc..c0e6bf21363 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -372,6 +372,7 @@ Release 0.21.0 - Unreleased from web UI HBASE-2657 TestTableResource is broken in trunk HBASE-2662 TestScannerResource.testScannerResource broke in trunk + HBASE-2667 TestHLog.testSplit failing in trunk IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java index 9e2d75e9a80..9cf2a65e79c 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLog.java @@ -1552,10 +1552,11 @@ public class HLog implements HConstants, Syncable { try { int editsCount = 0; WriterAndPath wap = logWriters.get(region); - for (ListIterator iterator = entries.listIterator(); - iterator.hasNext();) { - Entry logEntry = iterator.next(); - + // We put edits onto the Stack ordered oldest sequence id to newest. + // Pop them off starting with the oldest. + for (ListIterator iterator = entries.listIterator(entries.size()); + iterator.hasPrevious();) { + Entry logEntry = iterator.previous(); if (wap == null) { Path logFile = getRegionLogPath(logEntry, rootDir); if (fs.exists(logFile)) { @@ -1570,7 +1571,6 @@ public class HLog implements HConstants, Syncable { LOG.debug("Creating writer path=" + logFile + " region=" + Bytes.toStringBinary(region)); } - wap.w.append(logEntry); editsCount++; } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java index 7c1184cd237..5d4cffe871a 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java @@ -19,13 +19,14 @@ */ package org.apache.hadoop.hbase.regionserver.wal; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.io.HeapSize; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.ClassSize; -import org.apache.hadoop.io.*; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.EOFException; +import java.io.IOException; -import java.io.*; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.io.WritableComparable; /** * A Key for an entry in the change log. @@ -46,8 +47,6 @@ public class HLogKey implements WritableComparable { private byte clusterId; private int scope; - private int HEAP_TAX = ClassSize.OBJECT + (2 * ClassSize.ARRAY) + - (2 * Bytes.SIZEOF_LONG) + Bytes.SIZEOF_BYTE + Bytes.SIZEOF_INT; /** Writable Consructor -- Do not use. */ public HLogKey() { diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java b/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java index 55ac3c4cf66..51c5ec6b811 100644 --- a/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java +++ b/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; @@ -38,6 +40,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; /** JUnit test case for HLog */ public class TestHLog extends HBaseTestCase implements HConstants { + static final Log LOG = LogFactory.getLog(TestHLog.class); private Path dir; private Path oldLogDir; private MiniDFSCluster cluster; @@ -56,7 +59,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { if (fs.exists(dir)) { fs.delete(dir, true); } - this.oldLogDir = new Path("/hbase", HConstants.HREGION_OLDLOGDIR_NAME); + this.oldLogDir = new Path(this.dir, HConstants.HREGION_OLDLOGDIR_NAME); } @@ -78,7 +81,8 @@ public class TestHLog extends HBaseTestCase implements HConstants { final byte [] tableName = Bytes.toBytes(getName()); final byte [] rowName = tableName; - HLog log = new HLog(this.fs, this.dir, this.oldLogDir, this.conf, null); + Path logdir = new Path(this.dir, HConstants.HREGION_LOGDIR_NAME); + HLog log = new HLog(this.fs, logdir, this.oldLogDir, this.conf, null); final int howmany = 3; HRegionInfo[] infos = new HRegionInfo[3]; for(int i = 0; i < howmany; i++) { @@ -97,7 +101,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { byte [] column = Bytes.toBytes("column:" + Integer.toString(j)); edit.add(new KeyValue(rowName, family, qualifier, System.currentTimeMillis(), column)); - System.out.println("Region " + i + ": " + edit); + LOG.info("Region " + i + ": " + edit); log.append(infos[i], tableName, edit, System.currentTimeMillis()); } @@ -105,8 +109,9 @@ public class TestHLog extends HBaseTestCase implements HConstants { log.hflush(); log.rollWriter(); } + Path splitsdir = new Path(this.dir, "splits"); List splits = - HLog.splitLog(this.testDir, this.dir, this.oldLogDir, this.fs, this.conf); + HLog.splitLog(splitsdir, logdir, this.oldLogDir, this.fs, this.conf); verifySplits(splits, howmany); log = null; } finally { @@ -228,6 +233,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { throws IOException { assertEquals(howmany, splits.size()); for (int i = 0; i < splits.size(); i++) { + LOG.info("Verifying=" + splits.get(i)); HLog.Reader reader = HLog.getReader(this.fs, splits.get(i), conf); try { int count = 0; @@ -242,6 +248,7 @@ public class TestHLog extends HBaseTestCase implements HConstants { if (previousRegion != null) { assertEquals(previousRegion, region); } + LOG.info("oldseqno=" + seqno + ", newseqno=" + key.getLogSeqNum()); assertTrue(seqno < key.getLogSeqNum()); seqno = key.getLogSeqNum(); previousRegion = region;