use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class ClientStartNodeTask method changeTopology.
/**
* Change topology.
*
* @param parent Grid to execute tasks on.
* @param add New nodes count.
* @param rmv Remove nodes count.
* @param type Type of nodes to manipulate.
*/
private static void changeTopology(Ignite parent, int add, int rmv, String type) {
Collection<ComputeTaskFuture<?>> tasks = new ArrayList<>();
// Start nodes in parallel.
while (add-- > 0) tasks.add(parent.compute().executeAsync(ClientStartNodeTask.class, type));
for (ComputeTaskFuture<?> task : tasks) task.get();
// Stop nodes in sequence.
while (rmv-- > 0) parent.compute().execute(ClientStopNodeTask.class, type);
// Wait for node stops.
//U.sleep(1000);
Collection<String> igniteInstanceNames = new ArrayList<>();
for (Ignite g : G.allGrids()) igniteInstanceNames.add(g.name());
parent.log().info(">>> Available Ignite instances: " + igniteInstanceNames);
}
use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridSessionLoadSelfTest method checkSessionLoad.
/**
* @throws Exception If failed.
*/
private void checkSessionLoad() throws Exception {
final Ignite ignite = grid(0);
assert ignite != null;
assert ignite.cluster().nodes().size() == 2;
info("Thread count: " + THREAD_CNT);
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
ComputeTaskFuture f = null;
try {
for (int i = 0; i < EXEC_CNT; i++) assertEquals(Boolean.TRUE, (f = executeAsync(ignite.compute().withName("task-name"), SessionLoadTestTask.class, ignite.cluster().nodes().size() * 2)).get(20000));
} catch (Exception e) {
U.error(log, "Task failed: " + f != null ? f.getTaskSession().getId() : "N/A", e);
throw e;
} finally {
info("Thread finished.");
}
return null;
}
}, THREAD_CNT, "grid-load-test-thread");
}
use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridTaskTimeoutSelfTest method testSynchronousTimeoutMultithreaded.
/**
* @throws Exception If failed.
*/
public void testSynchronousTimeoutMultithreaded() throws Exception {
final Ignite ignite = G.ignite(getTestIgniteInstanceName());
final AtomicBoolean finish = new AtomicBoolean();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch finishLatch = new CountDownLatch(N_THREADS);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(PERIOD);
info("Stopping test.");
finish.set(true);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}
}).start();
multithreaded(new Runnable() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
while (!finish.get()) {
try {
ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null);
fut.get();
assert false : "Task has not been timed out. Future: " + fut;
} catch (ComputeTaskTimeoutException ignored) {
// Expected.
} catch (IgniteCheckedException e) {
//shouldn't happen
throw new IllegalStateException(e);
} finally {
int cnt0 = cnt.incrementAndGet();
if (cnt0 % 100 == 0)
info("Tasks finished: " + cnt0);
}
}
info("Thread " + Thread.currentThread().getId() + " finishing.");
finishLatch.countDown();
}
}, N_THREADS);
finishLatch.await();
//Grid will be stopped automatically on tearDown().
}
use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridCheckpointManagerAbstractSelfTest method doMultiNodeTest.
/**
* @param igniteInstanceName Ignite instance name.
* @throws Exception If test failed.
*/
protected void doMultiNodeTest(String igniteInstanceName) throws Exception {
startLatch = new CountDownLatch(3);
read1Latch = new CountDownLatch(1);
read1FinishedLatch = new CountDownLatch(2);
read2Latch = new CountDownLatch(1);
read2FinishedLatch = new CountDownLatch(2);
read3Latch = new CountDownLatch(1);
read3FinishedLatch = new CountDownLatch(2);
rmvLatch = new CountDownLatch(1);
try {
startGrid(igniteInstanceName + 1);
Ignite ignite = startGrid(igniteInstanceName);
ComputeTaskFuture fut = executeAsync(ignite.compute(), new GridMultiNodeGlobalConsumerTask(), null);
executeAsync(ignite.compute(), GridMultiNodeTestCheckPointTask.class, null).get(2 * 60 * 1000);
fut.get();
for (Ignite g : G.allGrids()) {
assert checkCheckpointManager(g) : "Session IDs got stuck after task completion [igniteInstanceName=" + g.name() + ", sesIds=" + checkpoints(g).sessionIds() + ']';
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.
the class GridCachePutAllFailoverSelfTest method checkPutAllFailoverColocated.
/**
* Tests putAll() method along with failover and cache backup.
*
* Checks that the resulting primary cache size is the same as
* expected.
*
* @param near Near enabled.
* @param workerCnt Worker count.
* @param shutdownCnt Shutdown count.
* @throws Exception If failed.
*/
public void checkPutAllFailoverColocated(boolean near, int workerCnt, int shutdownCnt) throws Exception {
nearEnabled = near;
backups = shutdownCnt;
Collection<Integer> testKeys = generateTestKeys();
final Ignite master = startGrid(MASTER);
List<Ignite> workers = new ArrayList<>(workerCnt);
for (int i = 1; i <= workerCnt; i++) workers.add(startGrid("worker" + i));
info("Master: " + master.cluster().localNode().id());
List<Ignite> runningWorkers = new ArrayList<>(workerCnt);
for (int i = 1; i <= workerCnt; i++) {
UUID id = workers.get(i - 1).cluster().localNode().id();
info(String.format("Worker%d: %s", i, id));
runningWorkers.add(workers.get(i - 1));
}
try {
Map<UUID, Collection<Integer>> dataChunks = new HashMap<>();
int chunkCntr = 0;
final AtomicBoolean jobFailed = new AtomicBoolean(false);
int failoverPushGap = 0;
final CountDownLatch emptyLatch = new CountDownLatch(1);
final AtomicBoolean inputExhausted = new AtomicBoolean();
IgniteCompute comp = compute(master.cluster().forPredicate(workerNodesFilter));
for (Integer key : testKeys) {
ClusterNode mappedNode = master.affinity(CACHE_NAME).mapKeyToNode(key);
UUID nodeId = mappedNode.id();
Collection<Integer> data = dataChunks.get(nodeId);
if (data == null) {
data = new ArrayList<>(DATA_CHUNK_SIZE);
dataChunks.put(nodeId, data);
}
data.add(key);
if (data.size() == DATA_CHUNK_SIZE) {
// time to send data
chunkCntr++;
log.info("Pushing data chunk [chunkNo=" + chunkCntr + "]");
ComputeTaskFuture<Void> fut = comp.executeAsync(new GridCachePutAllTask(nodeId, CACHE_NAME), data);
// Blocks if queue is full.
resQueue.put(fut);
fut.listen(new CI1<IgniteFuture<Void>>() {
@Override
public void apply(IgniteFuture<Void> f) {
ComputeTaskFuture<?> taskFut = (ComputeTaskFuture<?>) f;
try {
//if something went wrong - we'll get exception here
taskFut.get();
} catch (IgniteException e) {
log.error("Job failed", e);
jobFailed.set(true);
}
// Remove complete future from queue to allow other jobs to proceed.
resQueue.remove(taskFut);
if (inputExhausted.get() && resQueue.isEmpty())
emptyLatch.countDown();
}
});
data = new ArrayList<>(DATA_CHUNK_SIZE);
dataChunks.put(nodeId, data);
if (chunkCntr >= FAIL_ON_CHUNK_NO) {
if (workerCnt - runningWorkers.size() < shutdownCnt) {
if (failoverPushGap > 0)
failoverPushGap--;
else {
Ignite victim = runningWorkers.remove(0);
info("Shutting down node: " + victim.cluster().localNode().id());
stopGrid(victim.name());
// Fail next node after some jobs have been pushed.
failoverPushGap = FAILOVER_PUSH_GAP;
}
}
}
}
}
for (Map.Entry<UUID, Collection<Integer>> entry : dataChunks.entrySet()) {
ComputeTaskFuture<Void> fut = comp.executeAsync(new GridCachePutAllTask(entry.getKey(), CACHE_NAME), entry.getValue());
// Blocks if queue is full.
resQueue.put(fut);
fut.listen(new CI1<IgniteFuture<Void>>() {
@Override
public void apply(IgniteFuture<Void> f) {
ComputeTaskFuture<?> taskFut = (ComputeTaskFuture<?>) f;
try {
//if something went wrong - we'll get exception here
taskFut.get();
} catch (IgniteException e) {
log.error("Job failed", e);
jobFailed.set(true);
}
// Remove complete future from queue to allow other jobs to proceed.
resQueue.remove(taskFut);
if (inputExhausted.get() && resQueue.isEmpty())
emptyLatch.countDown();
}
});
}
inputExhausted.set(true);
if (resQueue.isEmpty())
emptyLatch.countDown();
// Wait for queue to empty.
log.info("Waiting for empty queue...");
boolean failedWait = false;
if (!emptyLatch.await(AWAIT_TIMEOUT_SEC, TimeUnit.SECONDS)) {
info(">>> Failed to wait for queue to empty.");
failedWait = true;
}
if (!failedWait)
assertFalse("One or more jobs have failed.", jobFailed.get());
Collection<Integer> absentKeys = findAbsentKeys(runningWorkers.get(0), testKeys);
if (!failedWait && !absentKeys.isEmpty()) {
// Give some time to preloader.
U.sleep(15000);
absentKeys = findAbsentKeys(runningWorkers.get(0), testKeys);
}
info(">>> Absent keys: " + absentKeys);
assertTrue(absentKeys.isEmpty());
// Actual primary cache size.
int primaryCacheSize = 0;
for (Ignite g : runningWorkers) {
info("Cache size [node=" + g.name() + ", localSize=" + g.cache(CACHE_NAME).localSize() + ", localPrimarySize=" + g.cache(CACHE_NAME).localSize(PRIMARY) + ']');
primaryCacheSize += g.cache(CACHE_NAME).localSize(PRIMARY);
}
assertEquals(TEST_MAP_SIZE, primaryCacheSize);
for (Ignite g : runningWorkers) assertEquals(TEST_MAP_SIZE, g.cache(CACHE_NAME).size(PRIMARY));
} finally {
stopAllGrids();
}
}
Aggregations