Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 78E8018450 for ; Tue, 27 Oct 2015 23:29:00 +0000 (UTC) Received: (qmail 66722 invoked by uid 500); 27 Oct 2015 23:29:00 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 66656 invoked by uid 500); 27 Oct 2015 23:29:00 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 66646 invoked by uid 99); 27 Oct 2015 23:29:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2015 23:29:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 293CCE0286; Tue, 27 Oct 2015 23:29:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: syuanjiang@apache.org To: commits@hbase.apache.org Date: Tue, 27 Oct 2015 23:29:00 -0000 Message-Id: <896bcc20810341d198a03fe835a6c560@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [01/17] hbase git commit: HBASE-14689 Addendum and unit test for HBASE-13471 Repository: hbase Updated Branches: refs/heads/hbase-12439 899857609 -> d5d81d675 HBASE-14689 Addendum and unit test for HBASE-13471 Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/4c04e806 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/4c04e806 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/4c04e806 Branch: refs/heads/hbase-12439 Commit: 4c04e8065f205a89b84670a9865149237499dd86 Parents: 8998576 Author: Enis Soztutar Authored: Mon Oct 26 11:56:51 2015 -0700 Committer: Enis Soztutar Committed: Mon Oct 26 11:56:51 2015 -0700 ---------------------------------------------------------------------- .../hadoop/hbase/regionserver/HRegion.java | 14 ++--- .../hadoop/hbase/regionserver/TestHRegion.java | 56 +++++++++++++++++++- 2 files changed, 62 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/4c04e806/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 34738de..07924e6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2961,11 +2961,12 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi } catch (IOException ioe) { LOG.warn("Failed getting lock in batch put, row=" + Bytes.toStringBinary(mutation.getRow()), ioe); + throw ioe; } if (rowLock == null) { // We failed to grab another lock - assert false: "Should never fail to get lock when blocking"; - break; // stop acquiring more rows for this batch + throw new IOException("Failed getting lock in batch put, row=" + + Bytes.toStringBinary(mutation.getRow())); } else { acquiredRowLocks.add(rowLock); } @@ -5055,6 +5056,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi * @param readLock is the lock reader or writer. True indicates that a non-exlcusive * lock is requested */ + @Override public RowLock getRowLock(byte[] row, boolean readLock) throws IOException { // Make sure the row is inside of this region before getting the lock for it. checkRow(row, "row lock"); @@ -6947,7 +6949,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi */ private static List carryForwardTags(final Cell cell, final List tags) { if (cell.getTagsLength() <= 0) return tags; - List newTags = tags == null? new ArrayList(): /*Append Tags*/tags; + List newTags = tags == null? new ArrayList(): /*Append Tags*/tags; Iterator i = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength()); while (i.hasNext()) newTags.add(i.next()); @@ -7228,7 +7230,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi // They are subtley different in quiet a few ways. This came out only // after study. I am not sure that many of the differences are intentional. - // TODO: St.Ack 20150907 + // TODO: St.Ack 20150907 @Override public Result increment(Increment mutation, long nonceGroup, long nonce) @@ -7242,7 +7244,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi boolean writeToWAL = durability != Durability.SKIP_WAL; WALEdit walEdits = null; List allKVs = new ArrayList(mutation.size()); - + Map> tempMemstore = new HashMap>(); long size = 0; long txid = 0; @@ -8045,7 +8047,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi WALKey key = new HLogKey(getRegionInfo().getEncodedNameAsBytes(), getRegionInfo().getTable(), WALKey.NO_SEQUENCE_ID, 0, null, HConstants.NO_NONCE, HConstants.NO_NONCE, getMVCC()); - + // Call append but with an empty WALEdit. The returned sequence id will not be associated // with any edit and we can be sure it went in after all outstanding appends. try { http://git-wip-us.apache.org/repos/asf/hbase/blob/4c04e806/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index ed45c2d..06517d7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -56,7 +56,11 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import java.util.UUID; +import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -99,6 +103,7 @@ import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Durability; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Increment; +import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.RowMutations; @@ -6166,7 +6171,7 @@ public class TestHRegion { key.setWriteEntry(we); return 1L; } - + }); return wal; } @@ -6189,7 +6194,7 @@ public class TestHRegion { // capture append() calls WAL wal = mockWAL(); when(rss.getWAL((HRegionInfo) any())).thenReturn(wal); - + // open a region first so that it can be closed later region = HRegion.openHRegion(hri, htd, rss.getWAL(hri), @@ -6529,6 +6534,53 @@ public class TestHRegion { qual2, 0, qual2.length)); } + @Test(timeout = 30000) + public void testBatchMutateWithWrongRegionException() throws IOException, InterruptedException { + final byte[] a = Bytes.toBytes("a"); + final byte[] b = Bytes.toBytes("b"); + final byte[] c = Bytes.toBytes("c"); // exclusive + + int prevLockTimeout = CONF.getInt("hbase.rowlock.wait.duration", 30000); + CONF.setInt("hbase.rowlock.wait.duration", 3000); + final HRegion region = initHRegion(tableName, a, c, name.getMethodName(), CONF, false, fam1); + + Mutation[] mutations = new Mutation[] { + new Put(a).addImmutable(fam1, null, null), + new Put(c).addImmutable(fam1, null, null), // this is outside the region boundary + new Put(b).addImmutable(fam1, null, null), + }; + + OperationStatus[] status = region.batchMutate(mutations); + assertEquals(status[0].getOperationStatusCode(), OperationStatusCode.SUCCESS); + assertEquals(status[1].getOperationStatusCode(), OperationStatusCode.SANITY_CHECK_FAILURE); + assertEquals(status[2].getOperationStatusCode(), OperationStatusCode.SUCCESS); + + // test with a leaked row lock + ExecutorService exec = Executors.newSingleThreadExecutor(); + exec.submit(new Callable() { + @Override + public Void call() throws Exception { + region.getRowLock(b); + return null; + } + }); + exec.shutdown(); + exec.awaitTermination(30, TimeUnit.SECONDS); + + mutations = new Mutation[] { + new Put(a).addImmutable(fam1, null, null), + new Put(b).addImmutable(fam1, null, null), + }; + + try { + status = region.batchMutate(mutations); + fail("Failed to throw exception"); + } catch (IOException expected) { + } + + CONF.setInt("hbase.rowlock.wait.duration", prevLockTimeout); + } + static HRegion initHRegion(TableName tableName, String callingMethod, byte[]... families) throws IOException { return initHRegion(tableName, callingMethod, HBaseConfiguration.create(),