diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java index 5e28859..78a3376 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java @@ -18,7 +18,17 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; +import java.io.InterruptedIOException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,16 +38,22 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.NotServingRegionException; +import org.apache.hadoop.hbase.RegionLocations; +import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.UnknownScannerException; +import org.apache.hadoop.hbase.client.ClientScanner.ScannerCallableWithReplicas.ScannerCallablePerReplica; import org.apache.hadoop.hbase.exceptions.OutOfOrderScannerNextException; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.MapReduceProtos; import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException; +import org.apache.hadoop.hbase.util.BoundedCompletionService; import org.apache.hadoop.hbase.util.Bytes; /** @@ -54,18 +70,46 @@ public class ClientScanner extends AbstractClientScanner { // Current region scanner is against. Gets cleared if current region goes // wonky: e.g. if it splits on us. protected HRegionInfo currentRegion = null; - protected ScannerCallable callable = null; + protected ScannerCallableWithReplicas callable = null; protected final LinkedList cache = new LinkedList(); protected final int caching; protected long lastNext; // Keep lastResult returned successfully in case we have to reset scanner. protected Result lastResult = null; protected final long maxScannerResultSize; - private final HConnection connection; + private final ClusterConnection connection; private final TableName tableName; private final int scannerTimeout; protected boolean scanMetricsPublished = false; protected RpcRetryingCaller caller; + private int retries; + protected final int primaryOperationTimeout; + protected final ExecutorService pool; + + /** + * Create a new ClientScanner for the specified table. An HConnection will be + * retrieved using the passed Configuration. + * Note that the passed {@link Scan}'s start row maybe changed changed. + * + * @param conf The {@link Configuration} to use. + * @param scan {@link Scan} to use in this scanner + * @param tableName The table that we wish to scan + * @throws IOException + */ + public ClientScanner(final Configuration conf, final Scan scan, + final TableName tableName, ClusterConnection connection, + ExecutorService pool, int primaryOperationTimeout) + throws IOException { + this(conf, scan, tableName, connection, + new RpcRetryingCallerFactory(conf), pool, primaryOperationTimeout); + } + + public ClientScanner(final Configuration conf, final Scan scan, + final TableName tableName, ClusterConnection connection, + RpcRetryingCallerFactory rpcFactory) + throws IOException { + this(conf, scan, tableName, connection, rpcFactory, null, 0); + } /** * Create a new ClientScanner for the specified table. An HConnection will be @@ -79,7 +123,7 @@ public class ClientScanner extends AbstractClientScanner { */ public ClientScanner(final Configuration conf, final Scan scan, final TableName tableName) throws IOException { - this(conf, scan, tableName, HConnectionManager.getConnection(conf)); + this(conf, scan, tableName, ConnectionManager.getConnectionInternal(conf));//HConnectionManager.getConnection(conf)); } /** @@ -103,8 +147,8 @@ public class ClientScanner extends AbstractClientScanner { * @throws IOException */ public ClientScanner(final Configuration conf, final Scan scan, final TableName tableName, - HConnection connection) throws IOException { - this(conf, scan, tableName, connection, new RpcRetryingCallerFactory(conf)); + ClusterConnection connection) throws IOException { + this(conf, scan, tableName, connection, new RpcRetryingCallerFactory(conf), null, 0); } /** @@ -112,8 +156,9 @@ public class ClientScanner extends AbstractClientScanner { */ @Deprecated public ClientScanner(final Configuration conf, final Scan scan, final byte [] tableName, - HConnection connection) throws IOException { - this(conf, scan, TableName.valueOf(tableName), connection, new RpcRetryingCallerFactory(conf)); + ClusterConnection connection) throws IOException { + this(conf, scan, TableName.valueOf(tableName), connection, new RpcRetryingCallerFactory(conf), + null, 0); } /** @@ -126,7 +171,8 @@ public class ClientScanner extends AbstractClientScanner { * @throws IOException */ public ClientScanner(final Configuration conf, final Scan scan, final TableName tableName, - HConnection connection, RpcRetryingCallerFactory rpcFactory) throws IOException { + ClusterConnection connection, RpcRetryingCallerFactory rpcFactory, ExecutorService pool, + int primaryOperationTimeout) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace("Scan table=" + tableName + ", startRow=" + Bytes.toStringBinary(scan.getStartRow())); @@ -135,6 +181,10 @@ public class ClientScanner extends AbstractClientScanner { this.tableName = tableName; this.lastNext = System.currentTimeMillis(); this.connection = connection; + this.pool = pool; + this.primaryOperationTimeout = primaryOperationTimeout; + this.retries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, + HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); if (scan.getMaxResultSize() > 0) { this.maxScannerResultSize = scan.getMaxResultSize(); } else { @@ -169,7 +219,7 @@ public class ClientScanner extends AbstractClientScanner { nextScanner(this.caching, false); } - protected HConnection getConnection() { + protected ClusterConnection getConnection() { return this.connection; } @@ -224,7 +274,7 @@ public class ClientScanner extends AbstractClientScanner { // Close the previous scanner if it's open if (this.callable != null) { this.callable.setClose(); - this.caller.callWithRetries(callable); + call(scan, callable, caller); this.callable = null; } @@ -261,7 +311,7 @@ public class ClientScanner extends AbstractClientScanner { callable = getScannerCallable(localStartKey, nbRows); // Open a scanner on the region server starting at the // beginning of the region - this.caller.callWithRetries(callable); + call(scan, callable, caller); this.currentRegion = callable.getHRegionInfo(); if (this.scanMetrics != null) { this.scanMetrics.countOfRegions.incrementAndGet(); @@ -273,14 +323,251 @@ public class ClientScanner extends AbstractClientScanner { return true; } + static Result[] call(Scan scan, ScannerCallableWithReplicas callable, + RpcRetryingCaller caller) + throws IOException, RuntimeException { + if (scan.getConsistency() == Consistency.STRONG) { + return caller.callWithRetries(callable); + } else { + return caller.callWithoutRetries(callable); + } + } + + protected final HashMap callableMap = + new HashMap(); + class ScannerCallableWithReplicas implements RetryingCallable { + final ClusterConnection cConnection; + protected final ExecutorService pool; + protected final int timeBeforeReplicas; + protected final ScannerCallable baseCallable; + + public ScannerCallableWithReplicas (ClusterConnection cConnection, ScannerCallable baseCallable, + ExecutorService pool, int timeBeforeReplicas) { + this.baseCallable = baseCallable; + this.cConnection = cConnection; + this.pool = pool; + this.timeBeforeReplicas = timeBeforeReplicas; + } + + public void setClose() { + baseCallable.setClose(); + } + + public void setCaching(int caching) { + baseCallable.setCaching(caching); + } + + public int getCaching() { + return baseCallable.getCaching(); + } + + public HRegionInfo getHRegionInfo() { + return baseCallable.getHRegionInfo(); + } + + @Override + public Result [] call() throws IOException { + if (scan.getConsistency() == Consistency.STRONG) return baseCallable.call(); + RegionLocations rl = getRegionLocations(true, RegionReplicaUtil.DEFAULT_REPLICA_ID); + BoundedCompletionService cs = new BoundedCompletionService(pool, rl.size()); + + List exceptions = null; + int submitted = 0, completed = 0; + // submit call for the primary replica. + submitted += addCallsForReplica(cs, rl, 0, 0); + try { + // wait for the timeout to see whether the primary responds back + Future f = cs.poll(timeBeforeReplicas, TimeUnit.MICROSECONDS); // Yes, microseconds + if (f != null) { + return f.get(); //great we got a response + } + } catch (ExecutionException e) { + // the primary call failed with RetriesExhaustedException or DoNotRetryIOException + // but the secondaries might still succeed. Continue on the replica RPCs. + exceptions = new ArrayList(rl.size()); + exceptions.add(e); + completed++; + } catch (CancellationException e) { + throw new InterruptedIOException(); + } catch (InterruptedException e) { + throw new InterruptedIOException(); + } + + // submit call for the all of the secondaries at once + // TODO: this may be an overkill for large region replication + submitted += addCallsForReplica(cs, rl, 1, rl.size() - 1); + try { + while (completed < submitted) { + try { + Future f = cs.take(); + if (f != null) { + return f.get(); // great we got an answer + } + } catch (ExecutionException e) { + // if not cancel or interrupt, wait until all RPC's are done + // one of the tasks failed. Save the exception for later. + if (exceptions == null) exceptions = new ArrayList(rl.size()); + exceptions.add(e); + completed++; + } + } + } catch (CancellationException e) { + throw new InterruptedIOException(); + } catch (InterruptedException e) { + throw new InterruptedIOException(); + } finally { + // We get there because we were interrupted or because one or more of the + // calls succeeded or failed. In all case, we stop all our tasks. + cs.cancelAll(true); + } + + if (exceptions != null && !exceptions.isEmpty()) { + RpcRetryingCallerWithReadReplicas.throwEnrichedException(exceptions.get(0), + retries, toString()); // just rethrow the first exception for now. + } + return null; // unreachable + } + + private int addCallsForReplica(BoundedCompletionService cs, + RegionLocations rl, int min, int max) { + for (int id = min; id <= max; id++) { + HRegionLocation hrl = rl.getRegionLocation(id); + String key = hrl.getRegionInfo().toString() + + hrl.getServerName().toString(); + ScannerCallablePerReplica s = callableMap.get(key); + if (s == null) { + s = new ScannerCallablePerReplica(id, hrl); + callableMap.put(key, s); + } + RetryingRPC retryingOnReplica = new RetryingRPC(s); + cs.submit(retryingOnReplica); + } + return max - min + 1; + } + + private RegionLocations getRegionLocations(boolean useCache, int replicaId) + throws RetriesExhaustedException, DoNotRetryIOException, InterruptedIOException { + RegionLocations rl; + try { + rl = cConnection.locateRegion(tableName, baseCallable.getRow(), useCache, true, replicaId); + } catch (DoNotRetryIOException e) { + throw e; + } catch (RetriesExhaustedException e) { + throw e; + } catch (InterruptedIOException e) { + throw e; + } catch (IOException e) { + throw new RetriesExhaustedException("Can't get the location", e); + } + if (rl == null) { + throw new RetriesExhaustedException("Can't get the locations"); + } + + return rl; + } + + class ScannerCallablePerReplica extends RegionServerCallable { + // need to inherit from RegionServerCallable since we'd like to manage the + // location for replicas + final int id; + public ScannerCallablePerReplica(int id, HRegionLocation location) { + super(ScannerCallableWithReplicas.this.baseCallable.connection, + ScannerCallableWithReplicas.this.baseCallable.tableName, + ScannerCallableWithReplicas.this.baseCallable.getRow()); + this.id = id; + this.location = location; + } + + @Override + public void prepare(boolean reload) throws IOException { + if (Thread.interrupted()) { + throw new InterruptedIOException(); + } + if (reload || location == null) { + RegionLocations rl = getRegionLocations(false, id); + location = id < rl.size() ? rl.getRegionLocation(id) : null; + } + + if (location == null || location.getServerName() == null) { + // With this exception, there will be a retry. The location can be null for a replica + // when the table is created or after a split. + throw new HBaseIOException("There is no location for replica id #" + id); + } + ServerName dest = location.getServerName(); + assert dest != null; + ScannerCallableWithReplicas.this.baseCallable.prepare(reload); + // overwrite the location + setStub(connection.getClient(dest)); + } + + @Override + public Result[] call() throws IOException { + if (Thread.interrupted()) { + throw new InterruptedIOException(); + } + return ScannerCallableWithReplicas.this.baseCallable.call(); + } + + @Override + public void throwable(Throwable t, boolean retrying) { + ScannerCallableWithReplicas.this.throwable(t, retrying); + } + + @Override + public String getExceptionMessageAdditionalDetail() { + return ScannerCallableWithReplicas.this.getExceptionMessageAdditionalDetail(); + } + + @Override + public long sleep(long pause, int tries) { + return ScannerCallableWithReplicas.this.sleep(pause, tries); + } + } + + @Override + public void prepare(boolean reload) throws IOException { + baseCallable.prepare(reload); + } + + @Override + public void throwable(Throwable t, boolean retrying) { + baseCallable.throwable(t, retrying); + } + + @Override + public String getExceptionMessageAdditionalDetail() { + return baseCallable.getExceptionMessageAdditionalDetail(); + } + + @Override + public long sleep(long pause, int tries) { + return baseCallable.sleep(pause, tries); + } + } + + class RetryingRPC implements Callable { + final RetryingCallable callable; + + RetryingRPC(RetryingCallable callable) { + this.callable = callable; + } + + @Override + public Result[] call() throws IOException { + return caller.callWithRetries(callable, scannerTimeout); + } + } + @InterfaceAudience.Private - protected ScannerCallable getScannerCallable(byte [] localStartKey, + protected ScannerCallableWithReplicas getScannerCallable(byte [] localStartKey, int nbRows) { scan.setStartRow(localStartKey); ScannerCallable s = new ScannerCallable(getConnection(), getTable(), scan, this.scanMetrics); s.setCaching(nbRows); - return s; + ScannerCallableWithReplicas sr = new ScannerCallableWithReplicas(getConnection(), s, + pool, primaryOperationTimeout); + return sr; } /** @@ -326,17 +613,17 @@ public class ClientScanner extends AbstractClientScanner { // Skip only the first row (which was the last row of the last // already-processed batch). callable.setCaching(1); - values = this.caller.callWithRetries(callable); + values = call(scan, callable, caller); callable.setCaching(this.caching); skipFirst = false; } // Server returns a null values if scanning is to stop. Else, // returns an empty array if scanning is to go on and we've just // exhausted current region. - values = this.caller.callWithRetries(callable); + values = call(scan, callable, caller); if (skipFirst && values != null && values.length == 1) { skipFirst = false; // Already skipped, unset it before scanning again - values = this.caller.callWithRetries(callable); + values = call(scan, callable, caller); } retryAfterOutOfOrderException = true; } catch (DoNotRetryIOException e) { @@ -428,7 +715,7 @@ public class ClientScanner extends AbstractClientScanner { if (callable != null) { callable.setClose(); try { - this.caller.callWithRetries(callable); + call(scan, callable, caller); } catch (IOException e) { // We used to catch this error, interpret, and rethrow. However, we // have since decided that it's not nice for a scanner's close to diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java index a17be55..6445cbd 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientSmallScanner.java @@ -70,7 +70,7 @@ public class ClientSmallScanner extends ClientScanner { */ public ClientSmallScanner(final Configuration conf, final Scan scan, final TableName tableName) throws IOException { - this(conf, scan, tableName, HConnectionManager.getConnection(conf)); + this(conf, scan, tableName, ConnectionManager.getConnectionInternal(conf)); } /** @@ -84,7 +84,7 @@ public class ClientSmallScanner extends ClientScanner { * @throws IOException */ public ClientSmallScanner(final Configuration conf, final Scan scan, - final TableName tableName, HConnection connection) throws IOException { + final TableName tableName, ClusterConnection connection) throws IOException { this(conf, scan, tableName, connection, new RpcRetryingCallerFactory(conf)); } @@ -100,7 +100,7 @@ public class ClientSmallScanner extends ClientScanner { * @throws IOException */ public ClientSmallScanner(final Configuration conf, final Scan scan, - final TableName tableName, HConnection connection, + final TableName tableName, ClusterConnection connection, RpcRetryingCallerFactory rpcFactory) throws IOException { super(conf, scan, tableName, connection, rpcFactory); } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index b81b5ba..e94621d 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -767,7 +767,7 @@ public class HTable implements HTableInterface { this.connection); } return new ClientScanner(getConfiguration(), scan, - getName(), this.connection); + getName(), this.connection, pool, primaryCallTimeoutMicroSecond); } /** diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ReversedClientScanner.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ReversedClientScanner.java index 618b3b3..8376c55 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ReversedClientScanner.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ReversedClientScanner.java @@ -28,6 +28,7 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ClientScanner.ScannerCallableWithReplicas; import org.apache.hadoop.hbase.util.Bytes; /** @@ -50,7 +51,7 @@ public class ReversedClientScanner extends ClientScanner { * @throws IOException */ public ReversedClientScanner(Configuration conf, Scan scan, - TableName tableName, HConnection connection) throws IOException { + TableName tableName, ClusterConnection connection) throws IOException { super(conf, scan, tableName, connection); } @@ -120,13 +121,15 @@ public class ReversedClientScanner extends ClientScanner { return true; } - protected ScannerCallable getScannerCallable(byte[] localStartKey, + protected ScannerCallableWithReplicas getScannerCallable(byte[] localStartKey, int nbRows, byte[] locateStartRow) { scan.setStartRow(localStartKey); ScannerCallable s = new ReversedScannerCallable(getConnection(), getTable(), scan, this.scanMetrics, locateStartRow); s.setCaching(nbRows); - return s; + ScannerCallableWithReplicas sr = new ScannerCallableWithReplicas(getConnection(), s, + pool, primaryOperationTimeout); + return sr; } @Override diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerWithReadReplicas.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerWithReadReplicas.java index c26629d..cba6ff1 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerWithReadReplicas.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RpcRetryingCallerWithReadReplicas.java @@ -225,7 +225,7 @@ public class RpcRetryingCallerWithReadReplicas { } if (exceptions != null && !exceptions.isEmpty()) { - throwEnrichedException(exceptions.get(0)); // just rethrow the first exception for now. + throwEnrichedException(exceptions.get(0), retries, toString()); // just rethrow the first exception for now. } return null; // unreachable } @@ -234,7 +234,7 @@ public class RpcRetryingCallerWithReadReplicas { * Extract the real exception from the ExecutionException, and throws what makes more * sense. */ - private void throwEnrichedException(ExecutionException e) + static void throwEnrichedException(ExecutionException e, int retries, String str) throws RetriesExhaustedException, DoNotRetryIOException { Throwable t = e.getCause(); assert t != null; // That's what ExecutionException is about: holding an exception @@ -249,7 +249,7 @@ public class RpcRetryingCallerWithReadReplicas { RetriesExhaustedException.ThrowableWithExtraContext qt = new RetriesExhaustedException.ThrowableWithExtraContext(t, - EnvironmentEdgeManager.currentTimeMillis(), toString()); + EnvironmentEdgeManager.currentTimeMillis(), str); List exceptions = Collections.singletonList(qt); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java index f7d1c51..a5c6622 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java @@ -115,7 +115,7 @@ public class Scan extends Query { private Map> familyMap = new TreeMap>(Bytes.BYTES_COMPARATOR); private Boolean loadColumnFamiliesOnDemand = null; - private Consistency consistency = null; + private Consistency consistency = Consistency.STRONG; /** * Set it true for small scan to get better performance diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index ebf1325..b1801d8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -89,6 +89,7 @@ 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.RegionReplicaUtil; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.RowMutations; import org.apache.hadoop.hbase.client.Scan; @@ -3152,6 +3153,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa try { int i = 0; synchronized(scanner) { + boolean stale = (region.getRegionInfo().getReplicaId() != 0); for (; i < rows && currentScanResultSize < maxResultSize; ) { // Collect values to be returned here @@ -3162,7 +3164,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa currentScanResultSize += KeyValueUtil.ensureKeyValue(kv).heapSize(); } } - results.add(Result.create(values)); + results.add(Result.create(values, null, stale)); i++; } if (!moreRows) { @@ -3189,7 +3191,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa moreResults = false; results = null; } else { - addResults(builder, results, controller); + addResults(builder, results, controller, region.getRegionInfo().getReplicaId() == 0); } } finally { // We're done. On way out re-add the above removed lease. @@ -3235,7 +3237,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa } private void addResults(final ScanResponse.Builder builder, final List results, - final RpcController controller) { + final RpcController controller, boolean isDefaultRegion) { if (results == null || results.isEmpty()) return; if (isClientCellBlockSupport()) { for (Result res : results) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java index f8d7cf5..ef3d771 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestReplicasClient.java @@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.protobuf.RequestConverter; import org.apache.hadoop.hbase.protobuf.generated.AdminProtos; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.regionserver.StorefileRefresherChore; +import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.zookeeper.ZKAssign; import org.apache.zookeeper.KeeperException; import org.junit.After; @@ -50,6 +51,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import java.io.IOException; +import java.util.Iterator; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -464,4 +466,51 @@ public class TestReplicasClient { closeRegion(hriSecondary); } } + + @Test + public void testScanWithReplicas() throws Exception { + openRegion(hriSecondary); + int NUMROWS = 100; + + try { + for (int i = 0; i < NUMROWS; i++) { + byte[] b1 = Bytes.toBytes("testUseRegionWithReplica" + i); + Put p = new Put(b1); + p.add(f, b1, b1); + table.put(p); + } + LOG.info("Put done"); + byte[] start = Bytes.toBytes("testUseRegionWithReplica" + 0); + Scan scan = new Scan(start); + scan.setConsistency(Consistency.TIMELINE); + ResultScanner scanner = table.getScanner(scan); + Iterator iter = scanner.iterator(); + Assert.assertTrue (iter.hasNext() == true); + int count = 0; + while (iter.hasNext()) { + count++; + Assert.assertTrue(iter.next().isStale() == false); + } + Assert.assertTrue(count == NUMROWS); + +// SlowMeCopro.cdl.set(new CountDownLatch(1)); +// g = new Get(b1); +// g.setConsistency(Consistency.TIMELINE); +// r = table.get(g); +// Assert.assertTrue(r.isStale()); +// Assert.assertFalse(r.isEmpty()); +// SlowMeCopro.cdl.get().countDown(); +// LOG.info("stale done"); + + } finally { + SlowMeCopro.cdl.get().countDown(); + SlowMeCopro.sleepTime.set(0); + for (int i = 0; i < 1000; i++) { + byte[] b1 = Bytes.toBytes("testUseRegionWithReplica" + i); + Delete d = new Delete(b1); + table.delete(d); + } + closeRegion(hriSecondary); + } + } } diff --git a/pom.xml.hadoop2 b/pom.xml.hadoop2 index 25c0079..830f9bc 100644 --- a/pom.xml.hadoop2 +++ b/pom.xml.hadoop2 @@ -949,7 +949,7 @@ org.apache.hadoop.hbase.SmallTests org.apache.hadoop.hbase.MediumTests true - 900 + 90000