/** * Return the start keys of all of the regions in this table, * as a list of ImmutableBytesWritable. */ private static List<ImmutableBytesWritable> getRegionStartKeys(RegionLocator table) throws IOException { byte[][] byteKeys = table.getStartKeys(); ArrayList<ImmutableBytesWritable> ret = new ArrayList<ImmutableBytesWritable>(byteKeys.length); for (byte[] byteKey : byteKeys) { ret.add(new ImmutableBytesWritable(byteKey)); } return ret; }
@Override public void configure(JobConf job) { try { this.connection = ConnectionFactory.createConnection(HBaseConfiguration.create(job)); TableName tableName = TableName.valueOf(job.get(TableOutputFormat.OUTPUT_TABLE)); this.locator = this.connection.getRegionLocator(tableName); } catch (IOException e) { LOG.error(e.toString(), e); } try { this.startKeys = this.locator.getStartKeys(); } catch (IOException e) { LOG.error(e.toString(), e); } }
/** * Sets the configuration. This is used to determine the start keys for the * given table. * * @param configuration The configuration to set. * @see org.apache.hadoop.conf.Configurable#setConf( * org.apache.hadoop.conf.Configuration) */ @Override public void setConf(Configuration configuration) { this.conf = HBaseConfiguration.create(configuration); try { this.connection = ConnectionFactory.createConnection(HBaseConfiguration.create(conf)); TableName tableName = TableName.valueOf(conf.get(TableOutputFormat.OUTPUT_TABLE)); this.locator = this.connection.getRegionLocator(tableName); } catch (IOException e) { LOG.error(e.toString(), e); } try { this.startKeys = this.locator.getStartKeys(); } catch (IOException e) { LOG.error(e.toString(), e); } } }
private byte[][] getTableSplits(final TableName tableName) throws IOException { byte[][] splits = null; try (RegionLocator locator = getConnection().getRegionLocator(tableName)) { byte[][] startKeys = locator.getStartKeys(); if (startKeys.length == 1) { return splits; } splits = new byte[startKeys.length - 1][]; for (int i = 1; i < startKeys.length; i++) { splits[i - 1] = startKeys[i]; } } return splits; }
private void setupMockStartKeys(RegionLocator table) throws IOException { byte[][] mockKeys = new byte[][] { HConstants.EMPTY_BYTE_ARRAY, Bytes.toBytes("aaa"), Bytes.toBytes("ggg"), Bytes.toBytes("zzz") }; Mockito.doReturn(mockKeys).when(table).getStartKeys(); }
@Override public void setup(Context context) throws IOException { cfRenameMap = createCfRenameMap(context.getConfiguration()); filter = instantiateFilter(context.getConfiguration()); int reduceNum = context.getNumReduceTasks(); Configuration conf = context.getConfiguration(); TableName tableName = TableName.valueOf(context.getConfiguration().get(TABLE_NAME)); try (Connection conn = ConnectionFactory.createConnection(conf); RegionLocator regionLocator = conn.getRegionLocator(tableName)) { byte[][] startKeys = regionLocator.getStartKeys(); if (startKeys.length != reduceNum) { throw new IOException("Region split after job initialization"); } CellWritableComparable[] startKeyWraps = new CellWritableComparable[startKeys.length - 1]; for (int i = 1; i < startKeys.length; ++i) { startKeyWraps[i - 1] = new CellWritableComparable(KeyValueUtil.createFirstOnRow(startKeys[i])); } CellWritableComparablePartitioner.START_KEYS = startKeyWraps; } } }
/** * Return the start keys of all of the regions in this table, * as a list of ImmutableBytesWritable. */ private static List<ImmutableBytesWritable> getRegionStartKeys(List<RegionLocator> regionLocators, boolean writeMultipleTables) throws IOException { ArrayList<ImmutableBytesWritable> ret = new ArrayList<>(); for(RegionLocator regionLocator : regionLocators) { TableName tableName = regionLocator.getName(); LOG.info("Looking up current regions for table " + tableName); byte[][] byteKeys = regionLocator.getStartKeys(); for (byte[] byteKey : byteKeys) { byte[] fullKey = byteKey; //HFileOutputFormat2 use case if (writeMultipleTables) { //MultiTableHFileOutputFormat use case fullKey = combineTableNameSuffix(tableName.getName(), byteKey); } if (LOG.isDebugEnabled()) { LOG.debug("SplitPoint startkey for table [" + tableName + "]: [" + Bytes.toStringBinary (fullKey) + "]"); } ret.add(new ImmutableBytesWritable(fullKey)); } } return ret; }
fs.deleteOnExit(partitionsPath); job.setPartitionerClass(CellWritableComparablePartitioner.class); job.setNumReduceTasks(regionLocator.getStartKeys().length); TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(), org.apache.hbase.thirdparty.com.google.common.base.Preconditions.class);
byte [][] startKeys = this.regionLocator.getStartKeys(); if (startKeys == null || startKeys.length == 0) { throw new IOException("Expecting at least one region");
@Override protected byte[][] getStartKeys(TableName tableName) throws IOException { try (RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) { return locator.getStartKeys(); } }
int numRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) { numRegions = r.getStartKeys().length;
numOfRegions = r.getStartKeys().length;
tableLength = locator.getStartKeys().length; tableLength = locator.getStartKeys().length;
/** * Start up a mini cluster and put a small table of many empty regions into it. * @throws Exception */ @BeforeClass public static void beforeAllTests() throws Exception { TEST_UTIL.startMiniCluster(2); // Create a table of three families. This will assign a region. TEST_UTIL.createMultiRegionTable(TABLENAME, FAMILIES); Table t = TEST_UTIL.getConnection().getTable(TABLENAME); int countOfRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(TABLENAME)) { countOfRegions = r.getStartKeys().length; } TEST_UTIL.waitUntilAllRegionsAssigned(TABLENAME); addToEachStartKey(countOfRegions); t.close(); }
int numOfRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) { numOfRegions = r.getStartKeys().length;
int regionCount = -1; try (RegionLocator r = UTIL.getConnection().getRegionLocator(tableName)) { regionCount = r.getStartKeys().length;
int numRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(table)) { numRegions = r.getStartKeys().length;
int numRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) { numRegions = r.getStartKeys().length;
int numRegions = -1; try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(tableName)) { numRegions = r.getStartKeys().length;
this.regionLocator.getStartKeys().length);