HBASE-13333 Renew Scanner Lease without advancing the RegionScanner.

This commit is contained in:
Lars Hofhansl 2015-05-02 17:48:32 -07:00
parent 807eba3e1a
commit a4799acd6b
6 changed files with 64 additions and 0 deletions

View File

@ -754,4 +754,21 @@ public class ClientScanner extends AbstractClientScanner {
return closestFrontRow;
}
}
@Override
public boolean renewLease() {
if (callable != null) {
// do not return any rows, do not advance the scanner
callable.setCaching(0);
try {
this.caller.callWithoutRetries(callable, this.scannerTimeout);
} catch (Exception e) {
return false;
} finally {
callable.setCaching(this.caching);
}
return true;
}
return false;
}
}

View File

@ -52,4 +52,10 @@ public interface ResultScanner extends Closeable, Iterable<Result> {
*/
@Override
void close();
/**
* Allow the client to renew the scanner's lease on the server.
* @return true if the lease was successfully renewed, false otherwise.
*/
boolean renewLease();
}

View File

@ -643,6 +643,11 @@ public class RemoteHTable implements Table {
LOG.warn(StringUtils.stringifyException(e));
}
}
@Override
public boolean renewLease() {
throw new RuntimeException("renewLease() not supported");
}
}
@Override

View File

@ -109,4 +109,9 @@ public class ClientSideRegionScanner extends AbstractClientScanner {
}
}
}
@Override
public boolean renewLease() {
throw new UnsupportedOperationException();
}
}

View File

@ -201,4 +201,9 @@ public class TableSnapshotScanner extends AbstractClientScanner {
}
}
@Override
public boolean renewLease() {
throw new UnsupportedOperationException();
}
}

View File

@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.client;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.util.ArrayList;
@ -429,4 +430,29 @@ public class TestFromClientSide3 {
assertTrue(Arrays.equals(res.getValue(FAMILY, COL_QUAL), VAL_BYTES));
table.close();
}
@Test
public void testLeaseRenewal() throws Exception {
HTable table = TEST_UTIL.createTable(
Bytes.toBytes("testLeaseRenewal"), FAMILY);
Put p = new Put(ROW_BYTES);
p.addColumn(FAMILY, COL_QUAL, VAL_BYTES);
table.put(p);
p = new Put(ANOTHERROW);
p.addColumn(FAMILY, COL_QUAL, VAL_BYTES);
table.put(p);
Scan s = new Scan();
s.setCaching(1);
ResultScanner rs = table.getScanner(s);
// make sure that calling renewLease does not impact the scan results
assertTrue(rs.renewLease());
assertTrue(Arrays.equals(rs.next().getRow(), ANOTHERROW));
assertTrue(rs.renewLease());
assertTrue(Arrays.equals(rs.next().getRow(), ROW_BYTES));
assertTrue(rs.renewLease());
assertNull(rs.next());
assertFalse(rs.renewLease());
rs.close();
table.close();
}
}