@Override public long sleep(long pause, int tries) { return ConnectionUtils.getPauseTime(pause, tries); }
@Before public void setUp() throws Exception { byte[] ROW_BEFORE = ConnectionUtils.createCloseRowBefore(ROW); Configuration conf = Mockito.mock(Configuration.class); HRegionLocation regionLocation = Mockito.mock(HRegionLocation.class); ServerName serverName = Mockito.mock(ServerName.class); Mockito.when(connection.getConfiguration()).thenReturn(conf); Mockito.when(regionLocations.size()).thenReturn(1); Mockito.when(regionLocations.getRegionLocation(0)).thenReturn(regionLocation); Mockito.when(regionLocation.getHostname()).thenReturn("localhost"); Mockito.when(regionLocation.getServerName()).thenReturn(serverName); Mockito.when(scan.includeStartRow()).thenReturn(true); Mockito.when(scan.getStartRow()).thenReturn(ROW); }
static boolean noMoreResultsForReverseScan(Scan scan, RegionInfo info) { if (isEmptyStartRow(info.getStartKey())) { return true; } if (isEmptyStopRow(scan.getStopRow())) { return false; } // no need to test the inclusive of the stop row as the start key of a region is included in // the region. return Bytes.compareTo(info.getStartKey(), scan.getStopRow()) <= 0; }
@Override protected ScannerCallable createScannerCallable() { if (!scan.includeStartRow() && !isEmptyStartRow(scan.getStartRow())) { // we have not implemented locate to next row for sync client yet, so here we change the // inclusive of start row to true. scan.withStartRow(createClosestRowAfter(scan.getStartRow()), true); } return new ScannerCallable(getConnection(), getTable(), scan, this.scanMetrics, this.rpcControllerFactory); } }
private void getProcedureResult(long procId, CompletableFuture<Void> future, int retries) { addListener( this.<GetProcedureResultResponse> newMasterCaller() .action((controller, stub) -> this .<GetProcedureResultRequest, GetProcedureResultResponse, GetProcedureResultResponse> call( controller, stub, GetProcedureResultRequest.newBuilder().setProcId(procId).build(), (s, c, req, done) -> s.getProcedureResult(c, req, done), (resp) -> resp)) .call(), (response, error) -> { if (error != null) { LOG.warn("failed to get the procedure result procId={}", procId, ConnectionUtils.translateException(error)); retryTimer.newTimeout(t -> getProcedureResult(procId, future, retries + 1), ConnectionUtils.getPauseTime(pauseNs, retries), TimeUnit.NANOSECONDS); return; } if (response.getState() == GetProcedureResultResponse.State.RUNNING) { retryTimer.newTimeout(t -> getProcedureResult(procId, future, retries + 1), ConnectionUtils.getPauseTime(pauseNs, retries), TimeUnit.NANOSECONDS); return; } if (response.hasException()) { IOException ioe = ForeignExceptionUtil.toIOException(response.getException()); future.completeExceptionally(ioe); } else { future.complete(null); } }); }
@Override public long sleep(long pause, int tries) { long sleep = ConnectionUtils.getPauseTime(pause, tries + 1); if (sleep < MIN_WAIT_DEAD_SERVER && (location == null || connection.isDeadServer(location.getServerName()))) { sleep = ConnectionUtils.addJitter(MIN_WAIT_DEAD_SERVER, 0.10f); } return sleep; }
if (scan.includeStartRow() && !isEmptyStartRow(getRow())) { byte[] locateStartRow = createCloseRowBefore(getRow()); List<HRegionLocation> locatedRegions = locateRegionsInRange( locateStartRow, getRow(), reload); incRPCRetriesMetrics(scanMetrics, isRegionServerRemote);
private boolean locateFinished(RegionInfo region, byte[] endKey, boolean endKeyInclusive) { if (isEmptyStopRow(endKey)) { if (isEmptyStopRow(region.getEndKey())) { return true; } return false; } else { if (isEmptyStopRow(region.getEndKey())) { return true; } int c = Bytes.compareTo(endKey, region.getEndKey()); // 1. if the region contains endKey // 2. endKey is equal to the region's endKey and we do not want to include endKey. return c < 0 || c == 0 && !endKeyInclusive; } }
/** * A simple version for batch exists. It will fail if there are any failures and you will get the * whole result boolean list at once if the operation is succeeded. * @param gets the Gets * @return A {@link CompletableFuture} that wrapper the result boolean list. */ default CompletableFuture<List<Boolean>> existsAll(List<Get> gets) { return allOf(exists(gets)); }
private void addToCache(Result result) { queue.add(result); cacheSize += calcEstimatedSize(result); }
static RegionLocateType getLocateType(Scan scan) { if (scan.isReversed()) { if (isEmptyStartRow(scan.getStartRow())) { return RegionLocateType.BEFORE; } else { return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.BEFORE; } } else { return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.AFTER; } }
private void onError(Throwable error) { error = translateException(error); if (tries > startLogErrorsCnt) { LOG.warn("Call to " + loc.getServerName() + " for scanner id = " + scannerId + " for " + return; delayNs = Math.min(maxDelayNs, getPauseTime(pauseNs, tries - 1)); } else { delayNs = getPauseTime(pauseNs, tries - 1);
@Override public long sleep(long pause, int tries) { // Tries hasn't been bumped up yet so we use "tries + 1" to get right pause time long sleep = ConnectionUtils.getPauseTime(pause, tries + 1); if (sleep < MIN_WAIT_DEAD_SERVER && (location == null || getConnection().isDeadServer(location.getServerName()))) { sleep = ConnectionUtils.addJitter(MIN_WAIT_DEAD_SERVER, 0.10f); } return sleep; }
if (scan.includeStartRow() && !isEmptyStartRow(getRow())) { byte[] locateStartRow = createCloseRowBefore(getRow()); List<HRegionLocation> locatedRegions = locateRegionsInRange( locateStartRow, getRow(), reload); incRPCRetriesMetrics(scanMetrics, isRegionServerRemote);
static boolean noMoreResultsForScan(Scan scan, RegionInfo info) { if (isEmptyStopRow(info.getEndKey())) { return true; } if (isEmptyStopRow(scan.getStopRow())) { return false; } int c = Bytes.compareTo(info.getEndKey(), scan.getStopRow()); // 1. if our stop row is less than the endKey of the region // 2. if our stop row is equal to the endKey of the region and we do not include the stop row // for scan. return c > 0 || (c == 0 && !scan.includeStopRow()); }
@Override protected ScannerCallable createScannerCallable() { if (!scan.includeStartRow() && !isEmptyStartRow(scan.getStartRow())) { // we have not implemented locate to next row for sync client yet, so here we change the // inclusive of start row to true. scan.withStartRow(createClosestRowAfter(scan.getStartRow()), true); } return new ScannerCallable(getConnection(), getTable(), scan, this.scanMetrics, this.rpcControllerFactory); } }
/** * A simple version of batch put. It will fail if there are any failures. * @param puts The list of mutations to apply. * @return A {@link CompletableFuture} that always returns null when complete normally. */ default CompletableFuture<Void> putAll(List<Put> puts) { return allOf(put(puts)).thenApply(r -> null); }
private Result pollCache() { Result res = cache.poll(); long estimatedSize = calcEstimatedSize(res); addEstimatedSize(-estimatedSize); return res; }
static RegionLocateType getLocateType(Scan scan) { if (scan.isReversed()) { if (isEmptyStartRow(scan.getStartRow())) { return RegionLocateType.BEFORE; } else { return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.BEFORE; } } else { return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.AFTER; } }
@Override public long sleep(long pause, int tries) { return ConnectionUtils.getPauseTime(pause, tries); }