use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class HadoopShuffleJob method close.
/** {@inheritDoc} */
@Override
public void close() throws IgniteCheckedException {
if (snd != null) {
snd.cancel();
try {
snd.join();
} catch (InterruptedException e) {
throw new IgniteInterruptedCheckedException(e);
}
}
close(locMaps);
close(rmtMaps);
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class HadoopV2SetupTask method run0.
/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override
protected void run0(HadoopV2TaskContext taskCtx) throws IgniteCheckedException {
try {
JobContextImpl jobCtx = taskCtx.jobContext();
OutputFormat outputFormat = getOutputFormat(jobCtx);
outputFormat.checkOutputSpecs(jobCtx);
OutputCommitter committer = outputFormat.getOutputCommitter(hadoopContext());
if (committer != null)
committer.setupJob(jobCtx);
} catch (ClassNotFoundException | IOException e) {
throw new IgniteCheckedException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInterruptedCheckedException(e);
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class HadoopV2Splitter method splitJob.
/**
* @param ctx Job context.
* @return Collection of mapped splits.
* @throws IgniteCheckedException If mapping failed.
*/
public static Collection<HadoopInputSplit> splitJob(JobContext ctx) throws IgniteCheckedException {
try {
InputFormat<?, ?> format = ReflectionUtils.newInstance(ctx.getInputFormatClass(), ctx.getConfiguration());
assert format != null;
List<InputSplit> splits = format.getSplits(ctx);
Collection<HadoopInputSplit> res = new ArrayList<>(splits.size());
int id = 0;
for (InputSplit nativeSplit : splits) {
if (nativeSplit instanceof FileSplit) {
FileSplit s = (FileSplit) nativeSplit;
res.add(new HadoopFileBlock(s.getLocations(), s.getPath().toUri(), s.getStart(), s.getLength()));
} else
res.add(HadoopUtils.wrapSplit(id, nativeSplit, nativeSplit.getLocations()));
id++;
}
return res;
} catch (IOException | ClassNotFoundException e) {
throw new IgniteCheckedException(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInterruptedCheckedException(e);
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class IgniteCacheQueryNodeRestartSelfTest2 method testRestarts.
/**
* @throws Exception If failed.
*/
public void testRestarts() throws Exception {
int duration = 90 * 1000;
int qryThreadNum = 4;
// 4 + 2 = 6 nodes
int restartThreadsNum = 2;
final int nodeLifeTime = 2 * 1000;
final int logFreq = 10;
startGridsMultiThreaded(GRID_CNT);
final AtomicIntegerArray locks = new AtomicIntegerArray(GRID_CNT);
fillCaches();
final List<List<?>> pRes = grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll();
Thread.sleep(3000);
assertEquals(pRes, grid(0).cache("pu").query(new SqlFieldsQuery(PARTITIONED_QRY)).getAll());
final List<List<?>> rRes = grid(0).cache("co").query(new SqlFieldsQuery(REPLICATED_QRY)).getAll();
assertFalse(pRes.isEmpty());
assertFalse(rRes.isEmpty());
final AtomicInteger qryCnt = new AtomicInteger();
final AtomicBoolean qrysDone = new AtomicBoolean();
IgniteInternalFuture<?> fut1 = multithreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
GridRandom rnd = new GridRandom();
while (!qrysDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, 1));
try {
if (rnd.nextBoolean()) {
// Partitioned query.
IgniteCache<?, ?> cache = grid(g).cache("pu");
SqlFieldsQuery qry = new SqlFieldsQuery(PARTITIONED_QRY);
boolean smallPageSize = rnd.nextBoolean();
if (smallPageSize)
qry.setPageSize(3);
try {
assertEquals(pRes, cache.query(qry).getAll());
} catch (CacheException e) {
// Interruptions are expected here.
if (e.getCause() instanceof IgniteInterruptedCheckedException)
continue;
if (e.getCause() instanceof QueryCancelledException)
fail("Retry is expected");
if (!smallPageSize)
e.printStackTrace();
assertTrue("On large page size must retry.", smallPageSize);
boolean failedOnRemoteFetch = false;
boolean failedOnInterruption = false;
for (Throwable th = e; th != null; th = th.getCause()) {
if (th instanceof InterruptedException) {
failedOnInterruption = true;
break;
}
if (!(th instanceof CacheException))
continue;
if (th.getMessage() != null && th.getMessage().startsWith("Failed to fetch data from node:")) {
failedOnRemoteFetch = true;
break;
}
}
// Interruptions are expected here.
if (failedOnInterruption)
continue;
if (!failedOnRemoteFetch) {
e.printStackTrace();
fail("Must fail inside of GridResultPage.fetchNextPage or subclass.");
}
}
} else {
// Replicated query.
IgniteCache<?, ?> cache = grid(g).cache("co");
assertEquals(rRes, cache.query(new SqlFieldsQuery(REPLICATED_QRY)).getAll());
}
} finally {
// Clearing lock in final handler to avoid endless loop if exception is thrown.
locks.set(g, 0);
int c = qryCnt.incrementAndGet();
if (c % logFreq == 0)
info("Executed queries: " + c);
}
}
}
}, qryThreadNum, "query-thread");
final AtomicInteger restartCnt = new AtomicInteger();
final AtomicBoolean restartsDone = new AtomicBoolean();
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@SuppressWarnings({ "BusyWait" })
@Override
public Object call() throws Exception {
GridRandom rnd = new GridRandom();
while (!restartsDone.get()) {
int g;
do {
g = rnd.nextInt(locks.length());
} while (!locks.compareAndSet(g, 0, -1));
try {
log.info("Stop node: " + g);
stopGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
log.info("Start node: " + g);
startGrid(g);
Thread.sleep(rnd.nextInt(nodeLifeTime));
} finally {
locks.set(g, 0);
int c = restartCnt.incrementAndGet();
if (c % logFreq == 0)
info("Node restarts: " + c);
}
}
return true;
}
}, restartThreadsNum, "restart-thread");
Thread.sleep(duration);
info("Stopping..");
restartsDone.set(true);
fut2.get();
info("Restarts stopped.");
qrysDone.set(true);
// Query thread can stuck in next page waiting loop because all nodes are left.
try {
fut1.get(5_000);
} catch (IgniteFutureTimeoutCheckedException ignored) {
fut1.cancel();
}
info("Queries stopped.");
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridJobExecutionSingleNodeSemaphoreLoadTest method main.
/**
* @param args Command line arguments:
* 1-st: Number of worker threads. Default equals to available CPU number / 2.
* 2-nd: Concurrent tasks count. Default: 1024.
* 3-rd: Test duration in seconds. 0 means infinite. Default: 0.
* 4-th: File to output test results to.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
GridFileLock fileLock = GridLoadTestUtils.fileLock();
fileLock.lock();
try {
// Command line arguments.
//
// NOTE: on MacOS better numbers are shown if public pool core and max sizes are
// equal to CPU count. And producer threads count is equal to CPU count.
//
int threadCnt = args.length > 0 ? Integer.parseInt(args[0]) : Runtime.getRuntime().availableProcessors() / 2;
int taskCnt = args.length > 1 ? Integer.parseInt(args[1]) : 1024;
final int duration = args.length > 2 ? Integer.parseInt(args[2]) : 0;
final String outputFileName = args.length > 3 ? args[3] : null;
final LongAdder8 execCnt = new LongAdder8();
try {
final Ignite g = G.start("modules/tests/config/grid-job-load.xml");
X.println("Thread count: " + threadCnt);
X.println("Task count: " + taskCnt);
X.println("Duration: " + duration);
X.println("Warming up...");
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
runTest(g, threadCnt, taskCnt, WARM_UP_DURATION, execCnt);
System.gc();
execCnt.reset();
X.println("Running main test.");
IgniteInternalFuture<Void> collectorFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
try {
while (!Thread.currentThread().isInterrupted()) {
U.sleep(UPDATE_INTERVAL_SEC * 1000);
long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
X.println(">>> Tasks/s: " + curTasksPerSec);
avgTasksPerSec.update(curTasksPerSec);
}
} catch (IgniteInterruptedCheckedException ignored) {
X.println(">>> Interrupted.");
Thread.currentThread().interrupt();
}
X.println(">>> Average tasks/s: " + avgTasksPerSec);
if (outputFileName != null) {
X.println("Writing test results to a file: " + outputFileName);
try {
GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
} catch (IOException e) {
X.error("Failed to output to a file", e);
}
}
return null;
}
});
runTest(g, threadCnt, taskCnt, duration * 1000, execCnt);
X.println("All done, stopping.");
collectorFut.cancel();
} finally {
G.stopAll(true);
}
} finally {
fileLock.close();
}
}
Aggregations