summaryrefslogtreecommitdiffstats
path: root/container-disc
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2019-10-26 23:25:21 +0200
committergjoranv <gv@verizonmedia.com>2019-10-26 23:31:53 +0200
commitcfa9a4fc4d3a210780b687040c34731e2596002d (patch)
treef9812cc55df0ee39019c8904f63f5bb162e33630 /container-disc
parent0ef572a1d9c36881450cf03ff7b6d095adb49bb0 (diff)
Deconstruct all components in one task.
The executor has only one thread, so this should not make a significant difference.
Diffstat (limited to 'container-disc')
-rw-r--r--container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java55
1 files changed, 29 insertions, 26 deletions
diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
index 4920051cbee..284e3a69b61 100644
--- a/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
+++ b/container-disc/src/main/java/com/yahoo/container/jdisc/component/Deconstructor.java
@@ -9,6 +9,7 @@ import com.yahoo.jdisc.SharedResource;
import com.yahoo.log.LogLevel;
import java.time.Duration;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.Executors;
@@ -35,17 +36,17 @@ public class Deconstructor implements ComponentDeconstructor {
this.delay = delayDeconstruction ? Duration.ofSeconds(60) : Duration.ZERO;
}
-
@Override
public void deconstruct(Collection<Object> components) {
+ Collection<AbstractComponent> destructibleComponents = new ArrayList<>();
for (var component : components) {
if (component instanceof AbstractComponent) {
AbstractComponent abstractComponent = (AbstractComponent) component;
if (abstractComponent.isDeconstructable()) {
- executor.schedule(new DestructComponentTask(abstractComponent), delay.getSeconds(), TimeUnit.SECONDS);
+ destructibleComponents.add(abstractComponent);
}
} else if (component instanceof Provider) {
- // TODO Providers should most likely be deconstructed similarily to AbstractComponent
+ // TODO Providers should most likely be deconstructed similarly to AbstractComponent
log.info("Starting deconstruction of provider " + component);
((Provider<?>) component).deconstruct();
log.info("Finished deconstruction of provider " + component);
@@ -55,15 +56,17 @@ public class Deconstructor implements ComponentDeconstructor {
((SharedResource) component).release();
}
}
+ if (! destructibleComponents.isEmpty())
+ executor.schedule(new DestructComponentTask(destructibleComponents), delay.getSeconds(), TimeUnit.SECONDS);
}
private static class DestructComponentTask implements Runnable {
private final Random random = new Random(System.nanoTime());
- private final AbstractComponent component;
+ private final Collection<AbstractComponent> components;
- DestructComponentTask(AbstractComponent component) {
- this.component = component;
+ DestructComponentTask(Collection<AbstractComponent> components) {
+ this.components = components;
}
/**
@@ -77,29 +80,29 @@ public class Deconstructor implements ComponentDeconstructor {
@Override
public void run() {
- log.info("Starting deconstruction of component " + component);
- try {
- component.deconstruct();
- log.info("Finished deconstructing of component " + component);
- }
- catch (Exception | NoClassDefFoundError e) { // May get class not found due to it being already unloaded
- log.log(WARNING, "Exception thrown when deconstructing component " + component, e);
- }
- catch (Error e) {
+ log.info("Starting deconstruction of " + components.size() + " components");
+ for (var component : components) {
+ log.info("Starting deconstruction of component " + component);
try {
- Duration shutdownDelay = getRandomizedShutdownDelay();
- log.log(LogLevel.FATAL, "Error when deconstructing component " + component + ". Will sleep for " +
- shutdownDelay.getSeconds() + " seconds then restart", e);
- Thread.sleep(shutdownDelay.toMillis());
+ component.deconstruct();
+ log.info("Finished deconstructing of component " + component);
+ } catch (Exception | NoClassDefFoundError e) { // May get class not found due to it being already unloaded
+ log.log(WARNING, "Exception thrown when deconstructing component " + component, e);
+ } catch (Error e) {
+ try {
+ Duration shutdownDelay = getRandomizedShutdownDelay();
+ log.log(LogLevel.FATAL, "Error when deconstructing component " + component + ". Will sleep for " +
+ shutdownDelay.getSeconds() + " seconds then restart", e);
+ Thread.sleep(shutdownDelay.toMillis());
+ } catch (InterruptedException exception) {
+ log.log(WARNING, "Randomized wait before dying disrupted. Dying now.");
+ }
+ com.yahoo.protect.Process.logAndDie("Shutting down due to error when deconstructing component " + component);
+ } catch (Throwable e) {
+ log.log(WARNING, "Non-error not exception throwable thrown when deconstructing component " + component, e);
}
- catch (InterruptedException exception) {
- log.log(WARNING, "Randomized wait before dying disrupted. Dying now.");
- }
- com.yahoo.protect.Process.logAndDie("Shutting down due to error when deconstructing component " + component);
- }
- catch (Throwable e) {
- log.log(WARNING, "Non-error not exception throwable thrown when deconstructing component " + component, e);
}
+ log.info("Finished deconstructing " + components.size() + " components");
}
}