RegionLocations locations = null; if (useCache) { locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations;
.getCachedLocation(tableName, currentScannerCallable.getRow()); if (rl == null) { throw e;
@Test public void testRegionCache() throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); htd.addFamily(fam); byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd, KEYS); HRegionLocator locator = (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName()); List<HRegionLocation> results = locator.getAllRegionLocations(); int number = ((ConnectionImplementation)admin.getConnection()) .getNumberOfCachedRegionLocations(htd.getTableName()); assertEquals(results.size(), number); ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection()); assertNotNull("Can't get cached location for row aaa", conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa"))); for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){ assertNotNull("Can't get cached location for row "+ Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey))); } }
rl = ((ConnectionImplementation)cConnection).getCachedLocation(tableName, get.getRow()); if (rl == null) {
final RegionLocations oldLocations = getCachedLocation(tableName, rowkey); HRegionLocation oldLocation = null; if (oldLocations != null) {
RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; try { if (useCache) {// re-check cache after get lock RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations;
assertNull(conn.getCachedLocation(TABLE_NAME, row)); } else if (success) { assertNotNull(conn.getCachedLocation(TABLE_NAME, row));
ConnectionImplementation conn = (ConnectionImplementation) TEST_UTIL.getConnection(); HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); assertNotNull(location); conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() + 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort - 1, location.getPort()); table.close();
assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW)); HRegionLocation loc = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation(); final int nextPort = loc.getPort() + 1; conn.updateCachedLocation(loc.getRegionInfo(), loc.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, HConstants.LATEST_TIMESTAMP), HConstants.LATEST_TIMESTAMP); Assert.assertEquals(conn.getCachedLocation(TABLE_NAME, ROW) .getRegionLocation().getPort(), nextPort); RegionLocations rl = conn.getCachedLocation(TABLE_NAME, ROW); assertNull("What is this location?? " + rl, rl); put2.addColumn(FAM_NAM, ROW, ROW); table.put(put2); assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW)); assertNotNull(conn.getCachedLocation(TableName.valueOf(TABLE_NAME.getName()), ROW.clone())); HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation(); byte[] regionName = toMove.getRegionInfo().getRegionName(); byte[] encodedRegionNameBytes = toMove.getRegionInfo().getEncodedNameAsBytes(); conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation() .getPort() == destServerName.getPort()); Assert.assertNotNull("Cached connection is null", conn.getCachedLocation(TABLE_NAME, ROW)); Assert.assertEquals( "Previous server was " + curServer.getServerName().getHostAndPort(), destServerName.getPort(),
HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME3, ROW_X).getRegionLocation(); byte[] regionName = toMove.getRegionInfo().getRegionName(); byte[] encodedRegionNameBytes = toMove.getRegionInfo().getEncodedNameAsBytes(); conn.getCachedLocation(TABLE_NAME3, ROW_X).getRegionLocation() .getPort() == destServerName.getPort());
RegionLocations locations = null; if (useCache) { locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations;
.getCachedLocation(tableName, currentScannerCallable.getRow()); if (rl == null) { throw e;
rl = ((ConnectionImplementation)cConnection).getCachedLocation(tableName, get.getRow()); if (rl == null) {
final RegionLocations oldLocations = getCachedLocation(tableName, rowkey); HRegionLocation oldLocation = null; if (oldLocations != null) {
RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; try { if (useCache) {// re-check cache after get lock RegionLocations locations = getCachedLocation(tableName, row); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations;
RegionLocations locations = null; if (useCache) { locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations; locations = getCachedLocation(tableName, metaCacheKey); if (locations != null && locations.getRegionLocation(replicaId) != null) { return locations;
@Test public void testRegionCache() throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HColumnDescriptor fam = new HColumnDescriptor(FAMILY); htd.addFamily(fam); byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd, KEYS); HRegionLocator locator = (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName()); List<HRegionLocation> results = locator.getAllRegionLocations(); int number = ((ConnectionImplementation)admin.getConnection()) .getNumberOfCachedRegionLocations(htd.getTableName()); assertEquals(results.size(), number); ConnectionImplementation conn = ((ConnectionImplementation)admin.getConnection()); assertNotNull("Can't get cached location for row aaa", conn.getCachedLocation(htd.getTableName(),Bytes.toBytes("aaa"))); for(byte[] startKey:HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE){ assertNotNull("Can't get cached location for row "+ Bytes.toString(startKey),(conn.getCachedLocation(htd.getTableName(),startKey))); } }
final RegionLocations oldLocations = getCachedLocation(tableName, rowkey); HRegionLocation oldLocation = null; if (oldLocations != null) {
assertNull(conn.getCachedLocation(TABLE_NAME, row)); } else if (success) { assertNotNull(conn.getCachedLocation(TABLE_NAME, row));
ConnectionImplementation conn = (ConnectionImplementation) TEST_UTIL.getConnection(); HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); assertNotNull(location); conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() + 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort, location.getPort()); conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1); location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation(); Assert.assertEquals(nextPort - 1, location.getPort()); table.close();