use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.
the class GridDiagnostic method runBackgroundCheck.
/**
* @param igniteInstanceName Grid instance name. Can be {@code null}.
* @param exec Executor service.
* @param parentLog Parent logger.
*/
static void runBackgroundCheck(String igniteInstanceName, Executor exec, IgniteLogger parentLog) {
assert exec != null;
assert parentLog != null;
final IgniteLogger log = parentLog.getLogger(GridDiagnostic.class);
try {
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-1", log) {
@Override
public void body() {
try {
InetAddress locHost = U.getLocalHost();
if (!locHost.isReachable(REACH_TIMEOUT)) {
U.warn(log, "Default local host is unreachable. This may lead to delays on " + "grid network operations. Check your OS network setting to correct it.", "Default local host is unreachable.");
}
} catch (IOException ignore) {
U.warn(log, "Failed to perform network diagnostics. It is usually caused by serious " + "network configuration problem. Check your OS network setting to correct it.", "Failed to perform network diagnostics.");
}
}
});
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-2", log) {
@Override
public void body() {
try {
InetAddress locHost = U.getLocalHost();
if (locHost.isLoopbackAddress()) {
U.warn(log, "Default local host is a loopback address. This can be a sign of " + "potential network configuration problem.", "Default local host is a loopback address.");
}
} catch (IOException ignore) {
U.warn(log, "Failed to perform network diagnostics. It is usually caused by serious " + "network configuration problem. Check your OS network setting to correct it.", "Failed to perform network diagnostics.");
}
}
});
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-4", log) {
@Override
public void body() {
// Sufficiently tested OS.
if (!U.isSufficientlyTestedOs()) {
U.warn(log, "This operating system has been tested less rigorously: " + U.osString() + ". Our team will appreciate the feedback if you experience any problems running " + "ignite in this environment.", "This OS is tested less rigorously: " + U.osString());
}
}
});
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-5", log) {
@Override
public void body() {
// Fix for GG-1075.
if (F.isEmpty(U.allLocalMACs()))
U.warn(log, "No live network interfaces detected. If IP-multicast discovery is used - " + "make sure to add 127.0.0.1 as a local address.", "No live network interfaces. Add 127.0.0.1 as a local address.");
}
});
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-6", log) {
@Override
public void body() {
if (System.getProperty("com.sun.management.jmxremote") != null) {
String portStr = System.getProperty("com.sun.management.jmxremote.port");
if (portStr != null)
try {
Integer.parseInt(portStr);
return;
} catch (NumberFormatException ignore) {
// No-op.
}
U.warn(log, "JMX remote management is enabled but JMX port is either not set or invalid. " + "Check system property 'com.sun.management.jmxremote.port' to make sure it specifies " + "valid TCP/IP port.", "JMX remote port is invalid - JMX management is off.");
}
}
});
final long HALF_GB = 512 * /*MB*/
1024 * 1024;
exec.execute(new GridWorker(igniteInstanceName, "grid-diagnostic-7", log) {
@Override
public void body() {
long initBytes = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getInit();
long initMb = initBytes / 1024 / 1024;
if (initBytes < HALF_GB)
U.quietAndWarn(log, String.format("Initial heap size is %dMB (should be no less than 512MB, " + "use -Xms512m -Xmx512m).", initMb));
}
});
} catch (RejectedExecutionException e) {
U.error(log, "Failed to start background network diagnostics check due to thread pool execution " + "rejection. In most cases it indicates a severe configuration problem with Ignite.", "Failed to start background network diagnostics.", e);
}
}
use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.
the class DataStreamProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
if (ctx.config().isDaemon())
return;
marshErrBytes = U.marshal(marsh, new IgniteCheckedException("Failed to marshal response error, " + "see node log for details."));
flusher = new IgniteThread(new GridWorker(ctx.igniteInstanceName(), "grid-data-loader-flusher", log) {
@Override
protected void body() throws InterruptedException {
while (!isCancelled()) {
DataStreamerImpl<K, V> ldr = flushQ.take();
if (!busyLock.enterBusy())
return;
try {
if (ldr.isClosed())
continue;
ldr.tryFlush();
flushQ.offer(ldr);
} finally {
busyLock.leaveBusy();
}
}
}
});
flusher.start();
if (log.isDebugEnabled())
log.debug("Started data streamer processor.");
}
use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.
the class GridClosureProcessor method callLocal.
/**
* @param c Closure to execute.
* @param plc Whether to run on system or public pool.
* @param <R> Type of closure return value.
* @return Future.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public <R> IgniteInternalFuture<R> callLocal(@Nullable final Callable<R> c, byte plc) throws IgniteCheckedException {
if (c == null)
return new GridFinishedFuture<>();
busyLock.readLock();
try {
// Inject only if needed.
if (!(c instanceof GridPlainCallable))
ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
final ClassLoader ldr = Thread.currentThread().getContextClassLoader();
final GridWorkerFuture<R> fut = new GridWorkerFuture<>();
GridWorker w = new GridWorker(ctx.igniteInstanceName(), "closure-proc-worker", log) {
@Override
protected void body() {
try {
if (ldr != null)
fut.onDone(U.wrapThreadLoader(ldr, c));
else
fut.onDone(c.call());
} catch (Throwable e) {
if (e instanceof Error)
U.error(log, "Closure execution failed with error.", e);
fut.onDone(U.cast(e));
if (e instanceof Error)
throw (Error) e;
}
}
};
fut.setWorker(w);
try {
pools.poolForPolicy(plc).execute(w);
} catch (RejectedExecutionException e) {
U.error(log, "Failed to execute worker due to execution rejection " + "(increase upper bound on executor service) [policy=" + plc + ']', e);
w.run();
}
return fut;
} finally {
busyLock.readUnlock();
}
}
use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.
the class GridClosureProcessor method runLocal.
/**
* @param c Closure to execute.
* @param plc Whether to run on system or public pool.
* @return Future.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public IgniteInternalFuture<?> runLocal(@Nullable final Runnable c, byte plc) throws IgniteCheckedException {
if (c == null)
return new GridFinishedFuture();
busyLock.readLock();
try {
// Inject only if needed.
if (!(c instanceof GridPlainRunnable))
ctx.resource().inject(ctx.deploy().getDeployment(c.getClass().getName()), c.getClass(), c);
final ClassLoader ldr = Thread.currentThread().getContextClassLoader();
final GridWorkerFuture fut = new GridWorkerFuture();
GridWorker w = new GridWorker(ctx.igniteInstanceName(), "closure-proc-worker", log) {
@Override
protected void body() {
try {
if (ldr != null)
U.wrapThreadLoader(ldr, c);
else
c.run();
fut.onDone();
} catch (Throwable e) {
if (e instanceof Error)
U.error(log, "Closure execution failed with error.", e);
fut.onDone(U.cast(e));
if (e instanceof Error)
throw e;
}
}
};
fut.setWorker(w);
try {
pools.poolForPolicy(plc).execute(w);
} catch (RejectedExecutionException e) {
U.error(log, "Failed to execute worker due to execution rejection " + "(increase upper bound on executor service) [policy=" + plc + ']', e);
w.run();
}
return fut;
} finally {
busyLock.readUnlock();
}
}
use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.
the class GridQueryProcessor method rebuildIndexesFromHash.
/**
* @param cacheName Cache name.
* @param desc Type descriptor.
* @return Future that will be completed when rebuilding of all indexes is finished.
*/
private IgniteInternalFuture<Object> rebuildIndexesFromHash(@Nullable final String cacheName, @Nullable final QueryTypeDescriptorImpl desc) {
if (idx == null)
return new GridFinishedFuture<>(new IgniteCheckedException("Indexing is disabled."));
if (desc == null)
return new GridFinishedFuture<>();
final GridWorkerFuture<Object> fut = new GridWorkerFuture<>();
final String schemaName = idx.schema(cacheName);
final String typeName = desc.name();
idx.markForRebuildFromHash(schemaName, typeName);
GridWorker w = new GridWorker(ctx.igniteInstanceName(), "index-rebuild-worker", log) {
@Override
protected void body() {
try {
int cacheId = CU.cacheId(cacheName);
GridCacheContext cctx = ctx.cache().context().cacheContext(cacheId);
idx.rebuildIndexesFromHash(cctx, schemaName, typeName);
fut.onDone();
} catch (Exception e) {
fut.onDone(e);
} catch (Throwable e) {
log.error("Failed to rebuild indexes for type: " + typeName, e);
fut.onDone(e);
throw e;
}
}
};
fut.setWorker(w);
ctx.getExecutorService().execute(w);
return fut;
}
Aggregations