@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != LocateRequest.class) { return false; } LocateRequest that = (LocateRequest) obj; return locateType.equals(that.locateType) && Bytes.equals(row, that.row); } }
@Override public int hashCode() { return Bytes.hashCode(row) ^ locateType.hashCode(); }
@Test public void testNoTable() throws InterruptedException { for (RegionLocateType locateType : RegionLocateType.values()) { try { getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
CompletableFuture<RegionLocations> getRegionLocations(TableName tableName, byte[] row, int replicaId, RegionLocateType locateType, boolean reload) { // as we know the exact row after us, so we can just create the new row, and use the same // algorithm to locate it. if (locateType.equals(RegionLocateType.AFTER)) { row = createClosestRowAfter(row); locateType = RegionLocateType.CURRENT; } return getRegionLocationsInternal(tableName, row, replicaId, locateType, reload); }
@Override public int hashCode() { return Bytes.hashCode(row) ^ locateType.hashCode(); }
@Test public void testDisableTable() throws IOException, InterruptedException { createSingleRegionTable(); TEST_UTIL.getAdmin().disableTable(TABLE_NAME); for (RegionLocateType locateType : RegionLocateType.values()) { try { getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
private RegionLocations locateInCache(TableCache tableCache, TableName tableName, byte[] row, int replicaId, RegionLocateType locateType) { return locateType.equals(RegionLocateType.BEFORE) ? locateRowBeforeInCache(tableCache, tableName, row, replicaId) : locateRowInCache(tableCache, tableName, row, replicaId); }
@Override public int hashCode() { return Bytes.hashCode(row) ^ locateType.hashCode(); }
@Test public void testSingleRegionTable() throws IOException, InterruptedException, ExecutionException { createSingleRegionTable(); ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); } byte[] randKey = new byte[ThreadLocalRandom.current().nextInt(128)]; ThreadLocalRandom.current().nextBytes(randKey); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, randKey, locateType, false).get()); } }
private CompletableFuture<RegionLocations> getRegionLocationsInternal(TableName tableName, byte[] row, int replicaId, RegionLocateType locateType, boolean reload) { assert !locateType.equals(RegionLocateType.AFTER); TableCache tableCache = getTableCache(tableName); if (!reload) {
createSingleRegionTable(); ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, true).get()); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName, getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
if (req.locateType.equals(RegionLocateType.BEFORE)) {
@Test public void testNoTable() throws InterruptedException { for (RegionLocateType locateType : RegionLocateType.values()) { try { LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
if (req.locateType.equals(RegionLocateType.BEFORE)) { if (isEmptyStopRow(req.row)) { byte[] binaryTableName = tableName.getName();
@Test public void testDisableTable() throws IOException, InterruptedException { createSingleRegionTable(); TEST_UTIL.getAdmin().disableTable(TABLE_NAME); for (RegionLocateType locateType : RegionLocateType.values()) { try { LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(TableNotFoundException.class)); } } }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != LocateRequest.class) { return false; } LocateRequest that = (LocateRequest) obj; return locateType.equals(that.locateType) && Bytes.equals(row, that.row); } }
@Test public void testSingleRegionTable() throws IOException, InterruptedException, ExecutionException { createSingleRegionTable(); ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); } byte[] randKey = new byte[ThreadLocalRandom.current().nextInt(128)]; ThreadLocalRandom.current().nextBytes(randKey); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, randKey, locateType, false).get()); } }
CompletableFuture<HRegionLocation> getRegionLocation(TableName tableName, byte[] row, RegionLocateType locateType, boolean reload) { if (locateType.equals(RegionLocateType.BEFORE)) { return getRegionLocationInternal(tableName, row, locateType, reload); } else { // as we know the exact row after us, so we can just create the new row, and use the same // algorithm to locate it. if (locateType.equals(RegionLocateType.AFTER)) { row = createClosestRowAfter(row); } return getRegionLocationInternal(tableName, row, RegionLocateType.CURRENT, reload); } }
createSingleRegionTable(); ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName(); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get()); LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, true).get()); for (RegionLocateType locateType : RegionLocateType.values()) { assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
private HRegionLocation locateInCache(TableCache tableCache, TableName tableName, byte[] row, RegionLocateType locateType) { return locateType.equals(RegionLocateType.BEFORE) ? locateRowBeforeInCache(tableCache, tableName, row) : locateRowInCache(tableCache, tableName, row); }