Skip to content

Commit 6eeddcb

Browse files
authored
Merge pull request #556 from oracle/fix-take9
Continuing to squash possible timing issues and add diagnosability
2 parents d175b7c + 9f9df83 commit 6eeddcb

File tree

5 files changed

+74
-23
lines changed

5 files changed

+74
-23
lines changed

operator/src/main/java/oracle/kubernetes/operator/DomainProcessorImpl.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import oracle.kubernetes.operator.work.Fiber;
5050
import oracle.kubernetes.operator.work.Fiber.CompletionCallback;
5151
import oracle.kubernetes.operator.work.FiberGate;
52+
import oracle.kubernetes.operator.work.FiberGateFactory;
5253
import oracle.kubernetes.operator.work.NextAction;
5354
import oracle.kubernetes.operator.work.Packet;
5455
import oracle.kubernetes.operator.work.Step;
@@ -62,7 +63,15 @@ public class DomainProcessorImpl implements DomainProcessor {
6263

6364
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");
6465

65-
private static final FiberGate FIBER_GATE = new FiberGate(Main.engine);
66+
private static final FiberGateFactory FACTORY =
67+
() -> {
68+
return new FiberGate(Main.engine);
69+
};
70+
private static final ConcurrentMap<String, FiberGate> fiberGates = new ConcurrentHashMap<>();
71+
72+
private static FiberGate getFiberGate(String ns) {
73+
return fiberGates.computeIfAbsent(ns, k -> FACTORY.get());
74+
}
6675

6776
// Map from namespace to map of domainUID to Domain
6877
private static final ConcurrentMap<String, ConcurrentMap<String, DomainPresenceInfo>> domains =
@@ -754,6 +763,7 @@ void runDomainPlan(
754763
Step.StepAndPacket plan,
755764
boolean isDeleting,
756765
boolean isWillInterrupt) {
766+
FiberGate gate = getFiberGate(ns);
757767
CompletionCallback cc =
758768
new CompletionCallback() {
759769
@Override
@@ -765,7 +775,7 @@ public void onCompletion(Packet packet) {
765775
public void onThrowable(Packet packet, Throwable throwable) {
766776
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
767777

768-
FIBER_GATE.startFiberIfLastFiberMatches(
778+
gate.startFiberIfLastFiberMatches(
769779
domainUID,
770780
Fiber.getCurrentIfSet(),
771781
DomainStatusUpdater.createFailedStep(throwable, null),
@@ -782,8 +792,7 @@ public void onThrowable(Packet packet, Throwable throwable) {
782792
}
783793
});
784794

785-
FIBER_GATE
786-
.getExecutor()
795+
gate.getExecutor()
787796
.schedule(
788797
() -> {
789798
DomainPresenceInfo existing = getExisting(ns, domainUID);
@@ -798,9 +807,9 @@ public void onThrowable(Packet packet, Throwable throwable) {
798807
};
799808

800809
if (isWillInterrupt) {
801-
FIBER_GATE.startFiber(domainUID, plan.step, plan.packet, cc);
810+
gate.startFiber(domainUID, plan.step, plan.packet, cc);
802811
} else {
803-
FIBER_GATE.startFiberIfNoCurrentFiber(domainUID, plan.step, plan.packet, cc);
812+
gate.startFiberIfNoCurrentFiber(domainUID, plan.step, plan.packet, cc);
804813
}
805814
}
806815

operator/src/main/java/oracle/kubernetes/operator/work/Fiber.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ private synchronized void addBreadCrumb(BreadCrumb bc) {
808808

809809
private synchronized void recordBreadCrumb() {
810810
if (breadCrumbs != null) {
811-
if (parent == null || parent.isDone()) {
811+
if (parent == null) {
812812
StringBuilder sb = new StringBuilder();
813813
writeBreadCrumb(sb);
814814

@@ -822,22 +822,20 @@ private synchronized void recordBreadCrumb() {
822822

823823
private synchronized void writeBreadCrumb(StringBuilder sb) {
824824
if (breadCrumbs != null) {
825-
if (parent == null || parent.isDone()) {
826-
sb.append('[');
827-
Iterator<BreadCrumb> it = breadCrumbs.iterator();
828-
BreadCrumb previous = null;
829-
while (it.hasNext()) {
830-
BreadCrumb bc = it.next();
831-
if (!bc.isMarker()) {
832-
if (previous != null) {
833-
sb.append(previous.isMarker() ? "][" : ",");
834-
}
835-
bc.writeTo(sb);
825+
sb.append('[');
826+
Iterator<BreadCrumb> it = breadCrumbs.iterator();
827+
BreadCrumb previous = null;
828+
while (it.hasNext()) {
829+
BreadCrumb bc = it.next();
830+
if (!bc.isMarker()) {
831+
if (previous != null) {
832+
sb.append(previous.isMarker() ? "][" : ",");
836833
}
837-
previous = bc;
834+
bc.writeTo(sb);
838835
}
839-
sb.append(']');
836+
previous = bc;
840837
}
838+
sb.append(']');
841839
}
842840
}
843841

@@ -887,7 +885,15 @@ public ChildFiberBreadCrumb(Fiber child) {
887885

888886
@Override
889887
public void writeTo(StringBuilder sb) {
890-
child.writeBreadCrumb(sb);
888+
sb.append("{child-");
889+
sb.append(child.id);
890+
sb.append(": ");
891+
if (child.status.get() == NOT_COMPLETE) {
892+
sb.append("not-complete");
893+
} else {
894+
child.writeBreadCrumb(sb);
895+
}
896+
sb.append("}");
891897
}
892898
}
893899

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.work;
6+
7+
import java.util.function.Supplier;
8+
9+
public interface FiberGateFactory extends Supplier<FiberGate> {}

operator/src/test/java/oracle/kubernetes/operator/DomainPresenceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
5050
import oracle.kubernetes.operator.helpers.LegalNames;
5151
import oracle.kubernetes.operator.helpers.ServerKubernetesObjects;
52+
import oracle.kubernetes.operator.work.FiberGateFactoryStub;
5253
import oracle.kubernetes.operator.work.ThreadFactorySingleton;
5354
import oracle.kubernetes.weblogic.domain.v2.Domain;
5455
import oracle.kubernetes.weblogic.domain.v2.DomainList;
@@ -83,8 +84,7 @@ public void setUp() throws Exception {
8384
mementos.add(ClientFactoryStub.install());
8485
mementos.add(StubWatchFactory.install());
8586
mementos.add(installStub(ThreadFactorySingleton.class, "INSTANCE", this));
86-
mementos.add(
87-
installStub(DomainProcessorImpl.class, "FIBER_GATE", testSupport.createFiberGateStub()));
87+
mementos.add(FiberGateFactoryStub.install(testSupport));
8888
testSupport.addContainerComponent("TF", ThreadFactory.class, this);
8989

9090
getStartedVariable();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.work;
6+
7+
import com.meterware.simplestub.Memento;
8+
import com.meterware.simplestub.StaticStubSupport;
9+
import oracle.kubernetes.operator.DomainProcessorImpl;
10+
11+
public class FiberGateFactoryStub implements FiberGateFactory {
12+
public static Memento install(FiberTestSupport testSupport) throws NoSuchFieldException {
13+
return StaticStubSupport.install(
14+
DomainProcessorImpl.class, "FACTORY", new FiberGateFactoryStub(testSupport));
15+
}
16+
17+
private final FiberTestSupport testSupport;
18+
19+
public FiberGateFactoryStub(FiberTestSupport testSupport) {
20+
this.testSupport = testSupport;
21+
}
22+
23+
@Override
24+
public FiberGate get() {
25+
return testSupport.createFiberGateStub();
26+
}
27+
}

0 commit comments

Comments
 (0)