From 39d7828814c761d0636776b8da012913b4b5c0b1 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Sat, 19 Nov 2011 18:27:51 +0000 Subject: [PATCH] HBASE-4789 On split, parent region is sticking around in oldest sequenceid to region map though not online; we don't cleanup WALs git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1204034 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/HRegion.java | 4 ++-- .../hadoop/hbase/regionserver/LogRoller.java | 11 +++++---- .../hadoop/hbase/regionserver/wal/HLog.java | 24 ++++++++++++------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 5160ae17461..8b896610c21 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1286,7 +1286,7 @@ public class HRegion implements HeapSize { // , Writable{ w = mvcc.beginMemstoreInsert(); mvcc.advanceMemstore(w); - sequenceId = (wal == null)? myseqid : + sequenceId = (wal == null)? myseqid: wal.startCacheFlush(this.regionInfo.getEncodedNameAsBytes()); completeSequenceId = this.getCompleteCacheFlushSequenceId(sequenceId); @@ -1302,7 +1302,7 @@ public class HRegion implements HeapSize { // , Writable{ this.updatesLock.writeLock().unlock(); } status.setStatus("Waiting for mvcc"); - LOG.debug("Finished snapshotting, commencing waiting for mvcc"); + LOG.debug("Finished snapshotting " + this + ", commencing wait for mvcc"); // wait for all in-progress transactions to commit to HLog before // we can start the flush. This prevents diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java b/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java index 63379599248..74429a19bea 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/LogRoller.java @@ -115,11 +115,11 @@ class LogRoller extends HasThread implements WALActionsListener { } /** - * @param region Encoded name of region to flush. + * @param encodedRegionName Encoded name of region to flush. */ - private void scheduleFlush(final byte [] region) { + private void scheduleFlush(final byte [] encodedRegionName) { boolean scheduled = false; - HRegion r = this.services.getFromOnlineRegions(Bytes.toString(region)); + HRegion r = this.services.getFromOnlineRegions(Bytes.toString(encodedRegionName)); FlushRequester requester = null; if (r != null) { requester = this.services.getFlushRequester(); @@ -129,8 +129,9 @@ class LogRoller extends HasThread implements WALActionsListener { } } if (!scheduled) { - LOG.warn("Failed to schedule flush of " + - Bytes.toString(region) + "r=" + r + ", requester=" + requester); + LOG.warn("Failed to schedule flush of " + + Bytes.toString(encodedRegionName) + ", region=" + r + ", requester=" + + requester); } } 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 85c8cb1c6dd..5adb5b37b26 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 @@ -187,8 +187,8 @@ public class HLog implements Syncable { Collections.synchronizedSortedMap(new TreeMap()); /* - * Map of regions to most recent sequence/edit id in their memstore. - * Key is encoded region name. + * Map of encoded region names to their most recent sequence/edit id in their + * memstore. */ private final ConcurrentSkipListMap lastSeqWritten = new ConcurrentSkipListMap(Bytes.BYTES_COMPARATOR); @@ -745,9 +745,8 @@ public class HLog implements Syncable { // If too many log files, figure which regions we need to flush. // Array is an array of encoded region names. byte [][] regions = null; - int logCount = this.outputfiles.size(); - if (logCount > this.maxLogs && this.outputfiles != null && - this.outputfiles.size() > 0) { + int logCount = this.outputfiles == null? 0: this.outputfiles.size(); + if (logCount > this.maxLogs && logCount > 0) { // This is an array of encoded region names. regions = findMemstoresWithEditsEqualOrOlderThan(this.outputfiles.firstKey(), this.lastSeqWritten); @@ -769,7 +768,7 @@ public class HLog implements Syncable { * Return regions (memstores) that have edits that are equal or less than * the passed oldestWALseqid. * @param oldestWALseqid - * @param regionsToSeqids + * @param regionsToSeqids Encoded region names to sequence ids * @return All regions whose seqid is < than oldestWALseqid (Not * necessarily in order). Null if no regions found. */ @@ -780,6 +779,7 @@ public class HLog implements Syncable { for (Map.Entry e: regionsToSeqids.entrySet()) { if (e.getValue().longValue() <= oldestWALseqid) { if (regions == null) regions = new ArrayList(); + // Key is encoded region name. regions.add(e.getKey()); } } @@ -802,6 +802,7 @@ public class HLog implements Syncable { byte [] oldestRegion = null; for (Map.Entry e: this.lastSeqWritten.entrySet()) { if (e.getValue().longValue() == oldestOutstandingSeqNum.longValue()) { + // Key is encoded region name. oldestRegion = e.getKey(); break; } @@ -1092,9 +1093,9 @@ public class HLog implements Syncable { // is greater than or equal to the value in lastSeqWritten. // Use encoded name. Its shorter, guaranteed unique and a subset of // actual name. - byte [] hriKey = info.getEncodedNameAsBytes(); - this.lastSeqWritten.putIfAbsent(hriKey, seqNum); - HLogKey logKey = makeKey(hriKey, tableName, seqNum, now, clusterId); + byte [] encodedRegionName = info.getEncodedNameAsBytes(); + this.lastSeqWritten.putIfAbsent(encodedRegionName, seqNum); + HLogKey logKey = makeKey(encodedRegionName, tableName, seqNum, now, clusterId); doWrite(info, logKey, edits, htd); this.numEntries.incrementAndGet(); txid = this.unflushedEntries.incrementAndGet(); @@ -1537,6 +1538,11 @@ public class HLog implements Syncable { // Cleaning up of lastSeqWritten is in the finally clause because we // don't want to confuse getOldestOutstandingSeqNum() this.lastSeqWritten.remove(getSnapshotName(encodedRegionName)); + Long l = this.lastSeqWritten.remove(encodedRegionName); + if (l != null) { + LOG.warn("Why is there a raw encodedRegionName in lastSeqWritten? name=" + + Bytes.toString(encodedRegionName) + ", seqid=" + l); + } this.cacheFlushLock.unlock(); } }