Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
<suppress checks="(?&lt;!Missing)JavadocMethod"
files="[\\/]tests[\\/]"/>

<suppress checks="(?&lt;!Missing)JavadocMethod"
files="[\\/]ml[\\/]"/>

<suppress checks="(?&lt;!Missing)JavadocMethod"
files="[\\/]yardstick[\\/]"/>

Expand All @@ -54,6 +51,9 @@
<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="[\\/]internal[\\/]thread[\\/]"/>

<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="org[\\/]apache[\\/]ignite[\\/]thread[\\/]"/>

<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="[\\/]internal[\\/]jdbc[\\/]thin[\\/]"/>

Expand All @@ -64,11 +64,14 @@
files="[\\/]io[\\/]opencensus[\\/]"/>

<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="[\\/]test[\\/]|[\\/]tests[\\/]"/>
files="[\\/]test[\\/]|[\\/]tests[\\/]||[\\/]testframework[\\/]"/>

<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="DumpReader\.java|CacheLoadOnlyStoreAdapter\.java"/>

<suppress checks="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule"
files="CdcCommandLineStartup\.java"/>

<suppress-xpath checks="AnnotationOnSameLine"
query="//ANNOTATION[.//IDENT[not(@text='Override')]]"/>
</suppressions>
5 changes: 5 additions & 0 deletions checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
<property name="factoryMethods" value="allOf, anyOf, supplyAsync, runAsync, completedFuture"/>
<property name="substitutionClassName" value="org.apache.ignite.internal.thread.context.concurrent.IgniteCompletableFuture"/>
</module>

<module name="org.apache.ignite.tools.checkstyle.ClassUsageRestrictionRule">
<property name="className" value="java.lang.Thread"/>
<property name="substitutionClassName" value="org.apache.ignite.thread.IgniteThread"/>
</module>
</module>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.apache.ignite.lang.IgniteFutureCancelledException;
import org.apache.ignite.lang.IgniteFutureTimeoutException;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.thread.IgniteThread;
import org.jetbrains.annotations.Nullable;

import static java.util.Objects.isNull;
Expand Down Expand Up @@ -541,27 +542,27 @@ public static long currentTimeMillis() {

/**
* Starts clock timer if grid is first.
*
* @param igniteInstanceName Ignite instance name.
*/
public static void onGridStart() {
@SuppressWarnings({"BusyWait"})
public static void onGridStart(String igniteInstanceName) {
synchronized (mux) {
if (gridCnt == 0) {
assert timer == null;

timer = new Thread(new Runnable() {
@SuppressWarnings({"BusyWait"})
@Override public void run() {
while (true) {
curTimeMillis = System.currentTimeMillis();

try {
Thread.sleep(10);
}
catch (InterruptedException ignored) {
break;
}
timer = new IgniteThread(igniteInstanceName, "ignite-clock", () -> {
while (!IgniteThread.currentThread().isInterrupted()) {
curTimeMillis = System.currentTimeMillis();

try {
Thread.sleep(10);
}
catch (InterruptedException ignored) {
break;
}
}
}, "ignite-clock");
});

timer.setDaemon(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ public static String createName(long num, String threadName, String igniteInstan
return threadName + "-#" + num + (igniteInstanceName != null ? '%' + igniteInstanceName + '%' : "");
}

/**
* @param threadId Thread ID.
* @return Thread name if found.
*/
public static String resolveName(long threadId) {
Thread[] threads = new Thread[Thread.activeCount()];

int cnt = Thread.enumerate(threads);

for (int i = 0; i < cnt; i++)
if (threads[i].getId() == threadId)
return threads[i].getName();

return "<failed to find active thread " + threadId + '>';
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(IgniteThread.class, this, "name", getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.thread.IgniteThread;

/**
* This handler could be used only with ignite.(sh|bat) script.
Expand All @@ -30,16 +31,11 @@
public class RestartProcessFailureHandler extends AbstractFailureHandler {
/** {@inheritDoc} */
@Override protected boolean handle(Ignite ignite, FailureContext failureCtx) {
new Thread(
new Runnable() {
@Override public void run() {
U.error(ignite.log(), "Restarting JVM on Ignite failure: [failureCtx=" + failureCtx + ']');
new IgniteThread(ignite.name(), "node-restarter", () -> {
U.error(ignite.log(), "Restarting JVM on Ignite failure: [failureCtx=" + failureCtx + ']');

G.restart(true);
}
},
"node-restarter"
).start();
G.restart(true);
}).start();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,19 @@
import org.apache.ignite.internal.IgnitionEx;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.thread.IgniteThread;

/**
* Handler will stop node in case of critical error using {@code IgnitionEx.stop(nodeName, true, true)} call.
*/
public class StopNodeFailureHandler extends AbstractFailureHandler {
/** {@inheritDoc} */
@Override public boolean handle(Ignite ignite, FailureContext failureCtx) {
new Thread(
new Runnable() {
@Override public void run() {
U.error(ignite.log(), "Stopping local node on Ignite failure: [failureCtx=" + failureCtx + ']');
new IgniteThread(ignite.name(), "node-stopper", () -> {
U.error(ignite.log(), "Stopping local node on Ignite failure: [failureCtx=" + failureCtx + ']');

IgnitionEx.stop(ignite.name(), true, null, true);
}
},
"node-stopper"
).start();
IgnitionEx.stop(ignite.name(), true, null, true);
}).start();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.ignite.internal.IgnitionEx;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.thread.IgniteThread;

/**
* Handler will try to stop node if {@code tryStop} value is {@code true}.
Expand Down Expand Up @@ -61,36 +62,26 @@ public StopNodeOrHaltFailureHandler(boolean tryStop, long timeout) {
if (tryStop) {
final CountDownLatch latch = new CountDownLatch(1);

new Thread(
new Runnable() {
@Override public void run() {
U.error(log, "Stopping local node on Ignite failure: [failureCtx=" + failureCtx + ']');
new IgniteThread(ignite.name(), "node-stopper", () -> {
U.error(log, "Stopping local node on Ignite failure: [failureCtx=" + failureCtx + ']');

IgnitionEx.stop(ignite.name(), true, null, true);
IgnitionEx.stop(ignite.name(), true, null, true);

latch.countDown();
}
},
"node-stopper"
).start();

new Thread(
new Runnable() {
@Override public void run() {
try {
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
U.error(log, "Stopping local node timeout, JVM will be halted.");

Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
}
}
catch (InterruptedException e) {
// No-op.
}
latch.countDown();
}).start();

new IgniteThread(ignite.name(), "jvm-halt-on-stop-timeout", () -> {
try {
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
U.error(log, "Stopping local node timeout, JVM will be halted.");

Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
}
},
"jvm-halt-on-stop-timeout"
).start();
}
catch (InterruptedException e) {
// No-op.
}
}).start();
}
else {
U.error(log, "JVM will be halted immediately due to the failure: [failureCtx=" + failureCtx + ']');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
import org.apache.ignite.spi.discovery.isolated.IsolatedDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode;
import org.apache.ignite.spi.tracing.TracingConfigurationManager;
import org.apache.ignite.thread.IgniteThread;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -902,7 +903,7 @@ public void start(
log = (GridLoggerProxy)cfg.getGridLogger().getLogger(
getClass().getName() + (igniteInstanceName != null ? '%' + igniteInstanceName : ""));

longJVMPauseDetector = new LongJVMPauseDetector(log);
longJVMPauseDetector = new LongJVMPauseDetector(igniteInstanceName, log);

longJVMPauseDetector.start();

Expand Down Expand Up @@ -946,7 +947,7 @@ public void start(

startProcessor(clusterProc);

U.onGridStart();
U.onGridStart(igniteInstanceName);

// Start and configure resource processor first as it contains resources used
// by all other managers and processors.
Expand Down Expand Up @@ -3182,11 +3183,11 @@ public void onReconnected(final boolean clusterRestarted) {

reconnectState.firstReconnectFut.onDone(e);

new Thread(() -> {
new IgniteThread(igniteInstanceName, "node-stopper", () -> {
U.error(log, "Stopping the node after a failed reconnect attempt.");

close();
}, "node-stopper").start();
}).start();
}
else {
assert ctx.discovery().reconnectSupported();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1753,17 +1753,17 @@ private void start0(GridStartContext startCtx, IgniteConfiguration cfg, TimeBag
// Do NOT set it up only if IGNITE_NO_SHUTDOWN_HOOK=TRUE is provided.
if (!IgniteSystemProperties.getBoolean(IGNITE_NO_SHUTDOWN_HOOK, false)) {
try {
Runtime.getRuntime().addShutdownHook(shutdownHook = new Thread("shutdown-hook") {
@Override public void run() {
if (log.isInfoEnabled())
log.info("Invoking shutdown hook...");
shutdownHook = new IgniteThread(cfg.getIgniteInstanceName(), "shutdown-hook", () -> {
if (log.isInfoEnabled())
log.info("Invoking shutdown hook...");

IgniteNamedInstance ignite = IgniteNamedInstance.this;
IgniteNamedInstance ignite = IgniteNamedInstance.this;

ignite.stop(true, null);
}
ignite.stop(true, null);
});

Runtime.getRuntime().addShutdownHook(shutdownHook);

if (log.isDebugEnabled())
log.debug("Shutdown hook is installed.");
}
Expand Down
Loading
Loading