use of java.util.concurrent.ExecutionException in project hbase by apache.
the class RegionMover method load.
/**
* Loads the specified {@link #hostname} with regions listed in the {@link #filename} RegionMover
* Object has to be created using {@link #RegionMover(RegionMoverBuilder)}
* @return true if loading succeeded, false otherwise
* @throws ExecutionException
* @throws InterruptedException if the loader thread was interrupted
* @throws TimeoutException
*/
public boolean load() throws ExecutionException, InterruptedException, TimeoutException {
setConf();
ExecutorService loadPool = Executors.newFixedThreadPool(1);
Future<Boolean> loadTask = loadPool.submit(new Load(this));
loadPool.shutdown();
try {
if (!loadPool.awaitTermination((long) this.timeout, TimeUnit.SECONDS)) {
LOG.warn("Timed out before finishing the loading operation. Timeout:" + this.timeout + "sec");
loadPool.shutdownNow();
}
} catch (InterruptedException e) {
loadPool.shutdownNow();
Thread.currentThread().interrupt();
}
try {
return loadTask.get(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOG.warn("Interrupted while loading Regions on " + this.hostname, e);
throw e;
} catch (ExecutionException e) {
LOG.error("Error while loading regions on RegionServer " + this.hostname, e);
throw e;
}
}
use of java.util.concurrent.ExecutionException in project hbase by apache.
the class HBaseFsck method processRegionServers.
/**
* Contacts each regionserver and fetches metadata about regions.
* @param regionServerList - the list of region servers to connect to
* @throws IOException if a remote or network exception occurs
*/
void processRegionServers(Collection<ServerName> regionServerList) throws IOException, InterruptedException {
List<WorkItemRegion> workItems = new ArrayList<>(regionServerList.size());
List<Future<Void>> workFutures;
// loop to contact each region server in parallel
for (ServerName rsinfo : regionServerList) {
workItems.add(new WorkItemRegion(this, rsinfo, errors, connection));
}
workFutures = executor.invokeAll(workItems);
for (int i = 0; i < workFutures.size(); i++) {
WorkItemRegion item = workItems.get(i);
Future<Void> f = workFutures.get(i);
try {
f.get();
} catch (ExecutionException e) {
LOG.warn("Could not process regionserver " + item.rsinfo.getHostAndPort(), e.getCause());
}
}
}
use of java.util.concurrent.ExecutionException in project hbase by apache.
the class TestAsyncTableGetMultiThreaded method test.
@Test
public void test() throws IOException, InterruptedException, ExecutionException {
int numThreads = 20;
AtomicBoolean stop = new AtomicBoolean(false);
ExecutorService executor = Executors.newFixedThreadPool(numThreads, Threads.newDaemonThreadFactory("TestAsyncGet-"));
List<Future<?>> futures = new ArrayList<>();
IntStream.range(0, numThreads).forEach(i -> futures.add(executor.submit(() -> {
run(stop);
return null;
})));
Collections.shuffle(Arrays.asList(SPLIT_KEYS), new Random(123));
Admin admin = TEST_UTIL.getAdmin();
for (byte[] splitPoint : SPLIT_KEYS) {
admin.split(TABLE_NAME, splitPoint);
for (HRegion region : TEST_UTIL.getHBaseCluster().getRegions(TABLE_NAME)) {
region.compact(true);
}
Thread.sleep(5000);
admin.balancer(true);
Thread.sleep(5000);
ServerName metaServer = TEST_UTIL.getHBaseCluster().getServerHoldingMeta();
ServerName newMetaServer = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer().getServerName()).filter(s -> !s.equals(metaServer)).findAny().get();
admin.move(HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), Bytes.toBytes(newMetaServer.getServerName()));
Thread.sleep(5000);
}
stop.set(true);
executor.shutdown();
for (Future<?> future : futures) {
future.get();
}
}
use of java.util.concurrent.ExecutionException in project hbase by apache.
the class TestAsyncTableBatch method test.
@Test
public void test() throws InterruptedException, ExecutionException, IOException {
AsyncTableBase table = tableGetter.apply(TABLE_NAME);
table.putAll(IntStream.range(0, COUNT).mapToObj(i -> new Put(getRow(i)).addColumn(FAMILY, CQ, Bytes.toBytes(i))).collect(Collectors.toList())).get();
List<Result> results = table.getAll(IntStream.range(0, COUNT).mapToObj(i -> Arrays.asList(new Get(getRow(i)), new Get(Arrays.copyOf(getRow(i), 4)))).flatMap(l -> l.stream()).collect(Collectors.toList())).get();
assertEquals(2 * COUNT, results.size());
for (int i = 0; i < COUNT; i++) {
assertEquals(i, Bytes.toInt(results.get(2 * i).getValue(FAMILY, CQ)));
assertTrue(results.get(2 * i + 1).isEmpty());
}
Admin admin = TEST_UTIL.getAdmin();
admin.flush(TABLE_NAME);
TEST_UTIL.getHBaseCluster().getRegions(TABLE_NAME).forEach(r -> {
byte[] startKey = r.getRegionInfo().getStartKey();
int number = startKey.length == 0 ? 55 : Integer.parseInt(Bytes.toString(startKey));
byte[] splitPoint = Bytes.toBytes(String.format("%03d", number + 55));
try {
admin.splitRegion(r.getRegionInfo().getRegionName(), splitPoint);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
// we are not going to test the function of split so no assertion here. Just wait for a while
// and then start our work.
Thread.sleep(5000);
table.deleteAll(IntStream.range(0, COUNT).mapToObj(i -> new Delete(getRow(i))).collect(Collectors.toList())).get();
results = table.getAll(IntStream.range(0, COUNT).mapToObj(i -> new Get(getRow(i))).collect(Collectors.toList())).get();
assertEquals(COUNT, results.size());
results.forEach(r -> assertTrue(r.isEmpty()));
}
use of java.util.concurrent.ExecutionException in project hbase by apache.
the class TestAsyncTableBatch method testPartialSuccess.
@Test
public void testPartialSuccess() throws IOException, InterruptedException, ExecutionException {
Admin admin = TEST_UTIL.getAdmin();
HTableDescriptor htd = admin.getTableDescriptor(TABLE_NAME);
htd.addCoprocessor(ErrorInjectObserver.class.getName());
admin.modifyTable(TABLE_NAME, htd);
AsyncTableBase table = tableGetter.apply(TABLE_NAME);
table.putAll(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Put(k).addColumn(FAMILY, CQ, k)).collect(Collectors.toList())).get();
List<CompletableFuture<Result>> futures = table.get(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Get(k)).collect(Collectors.toList()));
for (int i = 0; i < SPLIT_KEYS.length - 1; i++) {
assertArrayEquals(SPLIT_KEYS[i], futures.get(i).get().getValue(FAMILY, CQ));
}
try {
futures.get(SPLIT_KEYS.length - 1).get();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class));
}
}
Aggregations