Skip to content

Commit

Permalink
[DROOLS-7529] Alyways use RightTupleImpl instead of RightTuple (Fix t… (
Browse files Browse the repository at this point in the history
apache#5452)

* [DROOLS-7529] Alyways use RightTupleImpl instead of RightTuple (Fix the secondary super cache problem in Drools)

* Use specific iterator for TMS, everything else iterates over AbstractTuple instead of RighTuple

* Removed leftover

(cherry picked from commit bc0e069)
  • Loading branch information
lucamolteni committed Oct 11, 2023
1 parent 009812e commit e6a08ff
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.rule.EntryPointId;
import org.drools.core.spi.Tuple;
import org.drools.core.util.AbstractBaseLinkedListNode;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class DefaultFactHandle extends AbstractBaseLinkedListNode<DefaultFactHan
private int objectHashCode;
protected int identityHashCode;

protected EntryPointId entryPointId;
protected EntryPointId entryPointId;

private boolean disconnected;

Expand Down Expand Up @@ -680,8 +681,8 @@ public void addLastRightTuple( RightTuple rightTuple ) {
}

public void removeRightTuple( RightTuple rightTuple ) {
RightTuple previous = rightTuple.getHandlePrevious();
RightTuple next = rightTuple.getHandleNext();
RightTupleImpl previous = rightTuple.getHandlePrevious();
RightTupleImpl next = rightTuple.getHandleNext();

if ( previous != null && next != null ) {
// remove from middle
Expand Down Expand Up @@ -715,8 +716,8 @@ public void clearRightTuples() {
}

public void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer) {
for (RightTuple rightTuple = firstRightTuple; rightTuple != null; ) {
RightTuple nextRightTuple = rightTuple.getHandleNext();
for (RightTupleImpl rightTuple = (RightTupleImpl) firstRightTuple; rightTuple != null; ) {
RightTupleImpl nextRightTuple = rightTuple.getHandleNext();
rightTupleConsumer.accept( rightTuple );
rightTuple = nextRightTuple;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.core.reteoo.QueryElementNode;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.spi.Tuple;
import org.drools.core.util.FastIterator;
import org.drools.core.util.Iterator;
Expand Down Expand Up @@ -81,7 +82,7 @@ public LeftTuple getFirstLeftTuple(LeftTupleSource source,
BetaMemory memory = accmem.getBetaMemory();

FastIterator localIt = memory.getLeftTupleMemory().fullFastIterator();
Tuple leftTuple = BetaNode.getFirstTuple( memory.getLeftTupleMemory(), localIt );
Tuple leftTuple = BetaNode.getFirstTuple(memory.getLeftTupleMemory(), localIt );
if( leftTuple != null ) {
AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
return accctx.getResultLeftTuple();
Expand Down Expand Up @@ -158,7 +159,7 @@ public LeftTuple getFirstLeftTuple(LeftTupleSource source,
return leftTuple;
}
}

parentLeftTuple = getNextLeftTuple( source.getLeftTupleSource(),
(LeftTupleSink) source,
parentLeftTuple,
Expand Down Expand Up @@ -273,7 +274,7 @@ public LeftTuple getNextLeftTuple(LeftTupleSource source,
if ( source instanceof ExistsNode ) {
BetaMemory memory = (BetaMemory) wm.getNodeMemory( (MemoryFactory) source );
if (leftTuple != null) {
RightTuple rightTuple = leftTuple.getLeftParent().getBlocker();
RightTupleImpl rightTuple = (RightTupleImpl) leftTuple.getLeftParent().getBlocker();
FastIterator localIt = memory.getRightTupleMemory().fullFastIterator( rightTuple );

for ( LeftTuple childleftTuple = leftTuple.getHandleNext(); childleftTuple != null; childleftTuple = childleftTuple.getHandleNext() ) {
Expand Down Expand Up @@ -301,7 +302,7 @@ public LeftTuple getNextLeftTuple(LeftTupleSource source,
}

}
rightTuple = (RightTuple) localIt.next( rightTuple );
rightTuple = (RightTupleImpl) localIt.next( rightTuple );
}
}
} else if ( source instanceof EvalConditionNode || source instanceof QueryElementNode ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.LeftTupleSink;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.reteoo.TupleMemory;
import org.drools.core.rule.Accumulate;
import org.drools.core.rule.ContextEntry;
Expand Down Expand Up @@ -169,11 +170,11 @@ private void doLeftInserts(AccumulateNode accNode,

FastIterator rightIt = accNode.getRightIterator(rtm);

for (RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple,
for (RightTupleImpl rightTuple = accNode.getFirstRightTuple(leftTuple,
rtm,
null,
rightIt); rightTuple != null; ) {
RightTuple nextRightTuple = (RightTuple) rightIt.next(rightTuple);
RightTupleImpl nextRightTuple = (RightTupleImpl) rightIt.next(rightTuple);

if (constraints.isAllowedCachedLeft(contextEntry,
rightTuple.getFactHandleForEvaluation())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.LeftTupleSink;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.reteoo.TupleMemory;
import org.drools.core.rule.ContextEntry;
import org.drools.core.spi.AlphaNodeFieldConstraint;
Expand Down Expand Up @@ -145,8 +146,8 @@ public void doLeftUpdates(FromNode fromNode,

PropagationContext propagationContext = leftTuple.getPropagationContext();

final Map<Object, RightTuple> previousMatches = (Map<Object, RightTuple>) leftTuple.getContextObject();
final Map<Object, RightTuple> newMatches = new HashMap<Object, RightTuple>();
final Map<Object, RightTupleImpl> previousMatches = (Map<Object, RightTupleImpl>) leftTuple.getContextObject();
final Map<Object, RightTupleImpl> newMatches = new HashMap<>();
leftTuple.setContextObject( newMatches );

betaConstraints.updateFromTuple(context,
Expand All @@ -163,7 +164,7 @@ public void doLeftUpdates(FromNode fromNode,
continue; // skip anything if it not assignable
}

RightTuple rightTuple = previousMatches.remove(object);
RightTupleImpl rightTuple = previousMatches.remove(object);

if (rightTuple == null) {
// new match, propagate assert
Expand All @@ -175,8 +176,7 @@ public void doLeftUpdates(FromNode fromNode,
// previous match, so reevaluate and propagate modify
if (rightIt.next(rightTuple) != null) {
// handle the odd case where more than one object has the same hashcode/equals value
previousMatches.put(object,
(RightTuple) rightIt.next(rightTuple));
previousMatches.put(object, (RightTupleImpl) rightIt.next(rightTuple));
rightTuple.setNext(null);
}
}
Expand All @@ -189,8 +189,8 @@ public void doLeftUpdates(FromNode fromNode,
}
}

for (RightTuple rightTuple : previousMatches.values()) {
for (RightTuple current = rightTuple; current != null; current = (RightTuple) rightIt.next(current)) {
for (RightTupleImpl rightTuple : previousMatches.values()) {
for (RightTupleImpl current = rightTuple; current != null; current = (RightTupleImpl) rightIt.next(current)) {
deleteChildLeftTuple(propagationContext, trgLeftTuples, stagedLeftTuples, current.getFirstChild());
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public void doLeftDeletes(FromMemory fm,

// if matches == null, the deletion might be happening before the fact was even propagated. See BZ-1019473 for details.
if( matches != null ) {

// @TODO (mdp) is this really necessary? won't the entire FH and RightTuple chaines just et GC'd?
unlinkCreatedHandles(leftTuple);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.drools.core.reteoo.RiaPathMemory;
import org.drools.core.reteoo.RightInputAdapterNode;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.RightTupleImpl;
import org.drools.core.reteoo.SegmentMemory;
import org.drools.core.reteoo.SubnetworkTuple;
import org.drools.core.reteoo.TerminalNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,14 @@ public FastIterator getLeftIterator1(TupleMemory memory) {
}
}

public RightTuple getFirstRightTuple(final Tuple leftTuple,
public RightTupleImpl getFirstRightTuple(final Tuple leftTuple,
final TupleMemory memory,
final InternalFactHandle factHandle,
final FastIterator it) {
if ( !this.indexedUnificationJoin ) {
return (RightTuple) memory.getFirst(leftTuple);
return (RightTupleImpl) memory.getFirst(leftTuple);
} else {
return (RightTuple) it.next( null );
return (RightTupleImpl) it.next( null );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void networkUpdated(UpdateContext updateContext) {
}

@SuppressWarnings("unchecked")
public RightTuple createRightTuple( final LeftTuple leftTuple,
public RightTupleImpl createRightTuple( final LeftTuple leftTuple,
final PropagationContext context,
final InternalWorkingMemory workingMemory,
final Object object ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public void setMemory(TupleList memory) {
this.memory = memory;
}

public RightTuple getHandlePrevious() {
return (RightTuple) handlePrevious;
public RightTupleImpl getHandlePrevious() {
return (RightTupleImpl) handlePrevious;
}

public RightTuple getHandleNext() {
return (RightTuple) handleNext;
public RightTupleImpl getHandleNext() {
return (RightTupleImpl) handleNext;
}

public LeftTuple getFirstChild() {
Expand All @@ -152,12 +152,12 @@ public void setLastChild(LeftTuple lastChild) {
this.lastChild = lastChild;
}

public RightTuple getStagedNext() {
return (RightTuple) stagedNext;
public RightTupleImpl getStagedNext() {
return (RightTupleImpl) stagedNext;
}

public RightTuple getStagedPrevious() {
return (RightTuple) stagedPrevious;
public RightTupleImpl getStagedPrevious() {
return (RightTupleImpl) stagedPrevious;
}

public LeftTuple getTempBlocked() {
Expand Down

0 comments on commit e6a08ff

Please sign in to comment.