use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class IgniteCacheGroupsWithRestartsTest method executeTask.
/**
* @param ignite Ignite to execute task on.
* @param deleteFoundGarbage If clearing mode should be used.
* @return Result of task run.
*/
private VisorFindAndDeleteGarbageInPersistenceTaskResult executeTask(IgniteEx ignite, boolean deleteFoundGarbage) {
VisorFindAndDeleteGarbageInPersistenceTaskArg group = new VisorFindAndDeleteGarbageInPersistenceTaskArg(Collections.singleton(GROUP), deleteFoundGarbage, null);
UUID id = ignite.localNode().id();
VisorTaskArgument arg = new VisorTaskArgument(id, group, true);
VisorFindAndDeleteGarbageInPersistenceTaskResult result = ignite.compute().execute(VisorFindAndDeleteGarbageInPersistenceTask.class, arg);
return result;
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class GridIndexRebuildTest method testFullIndexRebuild.
/**
* We start several nodes, populate caches, then start replacing values. After that one node is killed, their
* index.bin files would be removed. Finally, we restart the node, index rebuild starting after recovery. And we
* checke indexes by "validate indexes" task.
*/
@Test
public void testFullIndexRebuild() throws Exception {
long start = System.currentTimeMillis();
IgniteEx grid1 = startGrids(4);
grid1.cluster().active(true);
final int accountCnt = 2048;
try (IgniteDataStreamer streamer = grid1.dataStreamer(FIRST_CACHE)) {
for (long i = 0; i < accountCnt; i++) {
streamer.addData(i, new Account(i));
}
streamer.flush();
}
try (IgniteDataStreamer streamer = grid1.dataStreamer(SECOND_CACHE)) {
for (long i = 0; i < accountCnt; i++) {
streamer.addData(i, new Account(i));
}
streamer.flush();
}
AtomicBoolean stop = new AtomicBoolean();
IgniteCache<Object, Object> cache1 = grid1.cache(FIRST_CACHE);
IgniteCache<Object, Object> cache2 = grid1.cache(SECOND_CACHE);
new Thread(new Runnable() {
@Override
public void run() {
long i = 0;
while (!stop.get()) {
try {
cache1.put(i, new Account(i));
if (i % 13 == 7)
cache2.put(i, new Account2(i));
else
cache2.put(i, new Account(i));
i++;
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}).start();
File workDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
long diff = System.currentTimeMillis() - start;
U.sleep(7500 - (diff % 5000));
stopGrid(3);
stop.set(true);
for (File grp : new File(workDir, U.maskForFileName(getTestIgniteInstanceName(3))).listFiles()) {
new File(grp, "index.bin").delete();
}
startGrid(3);
awaitPartitionMapExchange();
U.sleep(3_000);
ImmutableSet<UUID> nodes = ImmutableSet.of(grid(2).localNode().id(), grid(3).localNode().id());
VisorValidateIndexesTaskArg arg = new VisorValidateIndexesTaskArg(null, null, 10000, 1, true, true);
VisorTaskArgument<VisorValidateIndexesTaskArg> visorTaskArg = new VisorTaskArgument<>(nodes, arg, true);
ComputeTaskInternalFuture<VisorValidateIndexesTaskResult> exec = grid1.context().task().execute(new VisorValidateIndexesTask(), visorTaskArg);
VisorValidateIndexesTaskResult res = exec.get();
Map<UUID, VisorValidateIndexesJobResult> results = res.results();
boolean hasIssue = false;
for (VisorValidateIndexesJobResult jobResult : results.values()) {
System.err.println(jobResult);
hasIssue |= jobResult.hasIssues();
}
assertFalse(hasIssue);
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class GridIndexRebuildTest method testPartialIndexRebuild.
/**
* We start several nodes, populate caches, then start replacing values. After that one node is killed, new index
* created. Finally, we restart the node, index rebuild starting after recovery. And we checke indexes by "validate
* indexes" task.
*/
@SuppressWarnings("unchecked")
@Test
public void testPartialIndexRebuild() throws Exception {
LogListener lsnr = LogListener.matches("B+Tree is corrupted").build();
listeningLog.registerListener(lsnr);
long start = System.currentTimeMillis();
IgniteEx grid1 = startGrids(4);
grid1.cluster().active(true);
final int accountCnt = 2048;
try (IgniteDataStreamer streamer = grid1.dataStreamer(SECOND_CACHE)) {
for (long i = 0; i < accountCnt; i++) streamer.addData(i, new Account(i));
streamer.flush();
}
AtomicBoolean stop = new AtomicBoolean();
IgniteCache<Object, Object> cache2 = grid1.cache(SECOND_CACHE);
new Thread(new Runnable() {
@Override
public void run() {
long i = 0;
while (!stop.get()) {
try {
if (i % 13 == 7)
cache2.put(i, new Account2(i));
else
cache2.put(i, new Account(i));
i++;
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}).start();
long diff = System.currentTimeMillis() - start;
U.sleep(7500 - (diff % 5000));
stopGrid(3);
stop.set(true);
cache2.query(new SqlFieldsQuery("CREATE INDEX idx" + UUID.randomUUID().toString().replaceAll("-", "_") + " on Account (amount)")).getAll();
startGrid(3);
awaitPartitionMapExchange();
U.sleep(3_000);
ImmutableSet<UUID> nodes = ImmutableSet.of(grid(2).localNode().id(), grid(3).localNode().id());
VisorValidateIndexesTaskArg arg = new VisorValidateIndexesTaskArg(null, null, 10000, 1, true, true);
VisorTaskArgument<VisorValidateIndexesTaskArg> visorTaskArg = new VisorTaskArgument<>(nodes, arg, true);
ComputeTaskInternalFuture<VisorValidateIndexesTaskResult> execute = grid1.context().task().execute(new VisorValidateIndexesTask(), visorTaskArg);
VisorValidateIndexesTaskResult res = execute.get();
Map<UUID, VisorValidateIndexesJobResult> results = res.results();
boolean hasIssue = false;
for (VisorValidateIndexesJobResult jobResult : results.values()) {
System.err.println(jobResult);
hasIssue |= jobResult.hasIssues();
}
assertFalse(hasIssue);
assertFalse("B+Tree is corrupted.", lsnr.check());
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class GridTaskProcessor method startTask.
/**
* @param taskName Task name.
* @param taskCls Task class.
* @param task Task.
* @param sesId Task session ID.
* @param arg Optional task argument.
* @param sys If {@code true}, then system pool will be used.
* @param execName Name of the custom executor.
* @return Task future.
*/
private <T, R> ComputeTaskInternalFuture<R> startTask(@Nullable String taskName, @Nullable Class<?> taskCls, @Nullable ComputeTask<T, R> task, IgniteUuid sesId, @Nullable T arg, boolean sys, @Nullable String execName) {
assert sesId != null;
String taskClsName;
if (task != null) {
if (task instanceof GridPeerDeployAware)
taskClsName = ((GridPeerDeployAware) task).deployClass().getName();
else
taskClsName = task.getClass().getName();
} else
taskClsName = taskCls != null ? taskCls.getName() : taskName;
// Get values from thread-local context.
Map<GridTaskThreadContextKey, Object> map = thCtx.get();
if (map == null)
map = EMPTY_ENUM_MAP;
else
// Reset thread-local context.
thCtx.set(null);
if (map.get(TC_SKIP_AUTH) == null)
ctx.security().authorize(taskClsName, SecurityPermission.TASK_EXECUTE);
Long timeout = (Long) map.get(TC_TIMEOUT);
long timeout0 = timeout == null || timeout == 0 ? Long.MAX_VALUE : timeout;
long startTime = U.currentTimeMillis();
long endTime = timeout0 + startTime;
// Account for overflow.
if (endTime < 0)
endTime = Long.MAX_VALUE;
IgniteCheckedException deployEx = null;
GridDeployment dep = null;
// User provided task name.
if (taskName != null) {
assert taskCls == null;
assert task == null;
try {
dep = ctx.deploy().getDeployment(taskName);
if (dep == null)
throw new IgniteDeploymentCheckedException("Unknown task name or failed to auto-deploy " + "task (was task (re|un)deployed?): " + taskName);
IgniteBiTuple<Class<?>, Throwable> cls = dep.deployedClass(taskName);
if (cls.get1() == null)
throw new IgniteDeploymentCheckedException("Unknown task name or failed to auto-deploy " + "task (was task (re|un)deployed?) [taskName=" + taskName + ", dep=" + dep + ']', cls.get2());
taskCls = cls.get1();
if (!ComputeTask.class.isAssignableFrom(taskCls))
throw new IgniteCheckedException("Failed to auto-deploy task (deployed class is not a task) " + "[taskName=" + taskName + ", depCls=" + taskCls + ']');
} catch (IgniteCheckedException e) {
deployEx = e;
}
} else // Deploy user task class.
if (taskCls != null) {
assert task == null;
try {
// Implicit deploy.
dep = ctx.deploy().deploy(taskCls, U.detectClassLoader(taskCls));
if (dep == null)
throw new IgniteDeploymentCheckedException("Failed to auto-deploy task " + "(was task (re|un)deployed?): " + taskCls);
taskName = taskName(dep, taskCls, map);
} catch (IgniteCheckedException e) {
taskName = taskCls.getName();
deployEx = e;
}
} else // Deploy user task.
if (task != null) {
try {
ClassLoader ldr;
Class<?> cls;
if (task instanceof GridPeerDeployAware) {
GridPeerDeployAware depAware = (GridPeerDeployAware) task;
cls = depAware.deployClass();
ldr = depAware.classLoader();
// Set proper class name to make peer-loading possible.
taskCls = cls;
} else {
taskCls = task.getClass();
assert ComputeTask.class.isAssignableFrom(taskCls);
cls = task.getClass();
ldr = U.detectClassLoader(cls);
}
// Explicit deploy.
dep = ctx.deploy().deploy(cls, ldr);
if (dep == null)
throw new IgniteDeploymentCheckedException("Failed to auto-deploy task " + "(was task (re|un)deployed?): " + cls);
taskName = taskName(dep, taskCls, map);
} catch (IgniteCheckedException e) {
taskName = task.getClass().getName();
deployEx = e;
}
}
assert taskName != null;
if (log.isDebugEnabled())
log.debug("Task deployment: " + dep);
boolean fullSup = dep != null && taskCls != null && dep.annotation(taskCls, ComputeTaskSessionFullSupport.class) != null;
Collection<UUID> top = null;
final IgnitePredicate<ClusterNode> topPred = (IgnitePredicate<ClusterNode>) map.get(TC_SUBGRID_PREDICATE);
if (topPred == null) {
final Collection<ClusterNode> nodes = (Collection<ClusterNode>) map.get(TC_SUBGRID);
top = nodes != null ? F.nodeIds(nodes) : null;
}
boolean internal = false;
if (dep == null || taskCls == null)
assert deployEx != null;
else
internal = dep.internalTask(task, taskCls);
// Creates task session with task name and task version.
GridTaskSessionImpl ses = ctx.session().createTaskSession(sesId, ctx.localNodeId(), taskName, dep, taskCls == null ? null : taskCls.getName(), top, topPred, startTime, endTime, Collections.emptyList(), emptyMap(), fullSup, internal, execName, ctx.security().enabled() ? ctx.security().securityContext().subject().login() : null);
ComputeTaskInternalFuture<R> fut = new ComputeTaskInternalFuture<>(ses, ctx);
IgniteCheckedException securityEx = null;
if (ctx.security().enabled() && deployEx == null && !dep.internalTask(task, taskCls)) {
try {
saveTaskMetadata(taskName);
} catch (IgniteCheckedException e) {
securityEx = e;
}
}
if (deployEx == null && securityEx == null) {
if (dep == null || !dep.acquire())
handleException(new IgniteDeploymentCheckedException("Task not deployed: " + ses.getTaskName()), fut);
else {
GridTaskWorker<?, ?> taskWorker = new GridTaskWorker<>(ctx, arg, ses, fut, taskCls, task, dep, new TaskEventListener(), map, securitySubjectId(ctx));
GridTaskWorker<?, ?> taskWorker0 = tasks.putIfAbsent(sesId, taskWorker);
assert taskWorker0 == null : "Session ID is not unique: " + sesId;
if (ctx.event().isRecordable(EVT_MANAGEMENT_TASK_STARTED) && dep.visorManagementTask(task, taskCls)) {
VisorTaskArgument visorTaskArgument = (VisorTaskArgument) arg;
Event evt = new TaskEvent(ctx.discovery().localNode(), visorTaskArgument != null && visorTaskArgument.getArgument() != null ? visorTaskArgument.getArgument().toString() : "[]", EVT_MANAGEMENT_TASK_STARTED, ses.getId(), taskCls == null ? null : taskCls.getSimpleName(), "VisorManagementTask", false, securitySubjectId(ctx));
ctx.event().record(evt);
}
if (!ctx.clientDisconnected()) {
if (dep.annotation(taskCls, ComputeTaskMapAsync.class) != null) {
try {
// Start task execution in another thread.
if (sys)
ctx.pools().getSystemExecutorService().execute(taskWorker);
else
ctx.pools().getExecutorService().execute(taskWorker);
} catch (RejectedExecutionException e) {
tasks.remove(sesId);
release(dep);
handleException(new ComputeExecutionRejectedException("Failed to execute task " + "due to thread pool execution rejection: " + taskName, e), fut);
}
} else
taskWorker.run();
} else
taskWorker.finishTask(null, disconnectedError(null));
}
} else {
if (deployEx != null)
handleException(deployEx, fut);
else
handleException(securityEx, fut);
}
return fut;
}
use of org.apache.ignite.internal.visor.VisorTaskArgument in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testRebalanceProgressUnderLoad.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalanceProgressUnderLoad() throws Exception {
Ignite ignite = startGrids(4);
IgniteCache<Object, Object> cache1 = ignite.cache(CACHE1);
Random r = new Random();
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100_000; i++) {
int next = r.nextInt();
cache1.put(next, CACHE1 + "-" + next);
}
}
});
IgniteEx ig = startGrid(4);
GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100_000; i++) {
int next = r.nextInt();
cache1.put(next, CACHE1 + "-" + next);
}
}
});
CountDownLatch latch = new CountDownLatch(1);
ig.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
latch.countDown();
return false;
}
}, EventType.EVT_CACHE_REBALANCE_STOPPED);
latch.await();
VisorNodeDataCollectorTaskArg taskArg = new VisorNodeDataCollectorTaskArg();
taskArg.setCacheGroups(Collections.emptySet());
VisorTaskArgument<VisorNodeDataCollectorTaskArg> arg = new VisorTaskArgument<>(Collections.singletonList(ignite.cluster().localNode().id()), taskArg, false);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
VisorNodeDataCollectorTaskResult res = ignite.compute().execute(VisorNodeDataCollectorTask.class, arg);
CacheMetrics snapshot = ig.cache(CACHE1).metrics();
return snapshot.getRebalancedKeys() > snapshot.getEstimatedRebalancingKeys() && Double.compare(res.getRebalance().get(ignite.cluster().localNode().id()), 1.0) == 0 && snapshot.getRebalancingPartitionsCount() == 0;
}
}, 5000);
}
Aggregations