HBASE-13333 Renew Scanner Lease without advancing the RegionScanner.
This commit is contained in:
parent
e13ca3c61b
commit
0e76cf5be4
|
@ -124,4 +124,11 @@ public abstract class AbstractClientScanner implements ResultScanner {
|
|||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Allow the client to renew the scanner's lease on the server.
|
||||
* @return true if the lease was successfully renewed, false otherwise.
|
||||
*/
|
||||
// Note that this method should be on ResultScanner, but that is marked stable.
|
||||
// Callers have to cast their instance of ResultScanner to AbstractClientScanner to use this.
|
||||
public abstract boolean renewLease();
|
||||
}
|
||||
|
|
|
@ -752,4 +752,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,4 +109,9 @@ public class ClientSideRegionScanner extends AbstractClientScanner {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renewLease() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -201,4 +201,9 @@ public class TableSnapshotScanner extends AbstractClientScanner {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renewLease() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -428,4 +429,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.add(FAMILY, COL_QUAL, VAL_BYTES);
|
||||
table.put(p);
|
||||
p = new Put(ANOTHERROW);
|
||||
p.add(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(((AbstractClientScanner)rs).renewLease());
|
||||
assertTrue(Arrays.equals(rs.next().getRow(), ANOTHERROW));
|
||||
assertTrue(((AbstractClientScanner)rs).renewLease());
|
||||
assertTrue(Arrays.equals(rs.next().getRow(), ROW_BYTES));
|
||||
assertTrue(((AbstractClientScanner)rs).renewLease());
|
||||
assertNull(rs.next());
|
||||
assertFalse(((AbstractClientScanner)rs).renewLease());
|
||||
rs.close();
|
||||
table.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue