Author: stack Date: Sat Apr 24 17:13:50 2010 New Revision: 937649 URL: http://svn.apache.org/viewvc?rev=937649&view=rev Log: HBASE-2481 Client is not getting UnknownScannerExceptions; they are being eaten
Added: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java Modified: hadoop/hbase/trunk/CHANGES.txt hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/HTable.java hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java Modified: hadoop/hbase/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=937649&r1=937648&r2=937649&view=diff ============================================================================== --- hadoop/hbase/trunk/CHANGES.txt (original) +++ hadoop/hbase/trunk/CHANGES.txt Sat Apr 24 17:13:50 2010 @@ -285,6 +285,8 @@ Release 0.21.0 - Unreleased (Todd Lipcon via Stack) HBASE-2447 LogSyncer.addToSyncQueue doesn't check if syncer is still running before waiting (Todd Lipcon via Stack) + HBASE-2481 Client is not getting UnknownScannerExceptions; they are + being eaten (Jean-Daniel Cryans via Stack) IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/HTable.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/HTable.java?rev=937649&r1=937648&r2=937649&view=diff ============================================================================== --- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/HTable.java (original) +++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/HTable.java Sat Apr 24 17:13:50 2010 @@ -916,6 +916,16 @@ public class HTable implements HTableInt values = getConnection().getRegionServerWithRetries(callable); } } catch (DoNotRetryIOException e) { + long timeout = lastNext + scannerTimeout; + if (e instanceof UnknownScannerException && + timeout < System.currentTimeMillis()) { + long elapsed = System.currentTimeMillis() - lastNext; + ScannerTimeoutException ex = new ScannerTimeoutException( + elapsed + "ms passed since the last invocation, " + + "timeout is currently set to " + scannerTimeout); + ex.initCause(e); + throw ex; + } Throwable cause = e.getCause(); if (cause == null || !(cause instanceof NotServingRegionException)) { throw e; @@ -931,14 +941,6 @@ public class HTable implements HTableInt // Clear region this.currentRegion = null; continue; - } catch (IOException e) { - if (e instanceof UnknownScannerException && - lastNext + scannerTimeout < System.currentTimeMillis()) { - ScannerTimeoutException ex = new ScannerTimeoutException(); - ex.initCause(e); - throw ex; - } - throw e; } lastNext = System.currentTimeMillis(); if (values != null && values.length > 0) { Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java?rev=937649&r1=937648&r2=937649&view=diff ============================================================================== --- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java (original) +++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/client/ScannerCallable.java Sat Apr 24 17:13:50 2010 @@ -80,11 +80,15 @@ public class ScannerCallable extends Ser if (e instanceof RemoteException) { ioe = RemoteExceptionHandler.decodeRemoteException((RemoteException)e); } - if (ioe != null && ioe instanceof NotServingRegionException) { + if (ioe != null) { + if (ioe instanceof NotServingRegionException) { // Throw a DNRE so that we break out of cycle of calling NSRE // when what we need is to open scanner against new location. // Attach NSRE to signal client that it needs to resetup scanner. throw new DoNotRetryIOException("Reset scanner", ioe); + } else if (ioe instanceof DoNotRetryIOException) { + throw ioe; + } } } return rrs; Added: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java?rev=937649&view=auto ============================================================================== --- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java (added) +++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/client/TestScannerTimeout.java Sat Apr 24 17:13:50 2010 @@ -0,0 +1,91 @@ +package org.apache.hadoop.hbase.client; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Test various scanner timeout issues. + */ +public class TestScannerTimeout { + + private final static HBaseTestingUtility + TEST_UTIL = new HBaseTestingUtility(); + + final Log LOG = LogFactory.getLog(getClass()); + private final byte[] someBytes = Bytes.toBytes("f"); + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + HBaseConfiguration c = TEST_UTIL.getConfiguration(); + c.setInt("hbase.regionserver.lease.period", 1000); + TEST_UTIL.startMiniCluster(1); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test that we do get a ScannerTimeoutException + * @throws Exception + */ + @Test + public void test2481() throws Exception { + int initialCount = 10; + HTable t = TEST_UTIL.createTable(Bytes.toBytes("t"), someBytes); + for (int i = 0; i < initialCount; i++) { + Put put = new Put(Bytes.toBytes(i)); + put.add(someBytes, someBytes, someBytes); + t.put(put); + } + Scan scan = new Scan(); + ResultScanner r = t.getScanner(scan); + int count = 0; + try { + Result res = r.next(); + while (res != null) { + count++; + if (count == 5) { + Thread.sleep(1500); + } + res = r.next(); + } + } catch (ScannerTimeoutException e) { + LOG.info("Got the timeout " + e.getMessage(), e); + return; + } + fail("We should be timing out"); + } +}