Skip to content

Commit

Permalink
Revert "[DROOLS-7522] Alyways use AbstractLeftTuple instead of LeftTu…
Browse files Browse the repository at this point in the history
…ple (Fix the secondary super cache problem in Drools) (apache#5443)"

This reverts commit fb7e4da
  • Loading branch information
lucamolteni committed Sep 13, 2023
1 parent 21371f2 commit 069c1b1
Show file tree
Hide file tree
Showing 59 changed files with 910 additions and 818 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public void rowAdded(RuleImpl rule, LeftTuple tuple, ReteEvaluator reteEvaluator
entry = entry.getParent();
}

QueryTerminalNode node = (QueryTerminalNode) tuple.getTupleSink();
QueryTerminalNode node = tuple.getTupleSink();
this.results.add( new QueryRowWithSubruleIndex(handles, node.getSubruleIndex()) );
}

public void rowRemoved(RuleImpl rule, LeftTuple tuple, ReteEvaluator reteEvaluator ) {
public void rowRemoved( RuleImpl rule, LeftTuple tuple, ReteEvaluator reteEvaluator ) {
}

public void rowUpdated(RuleImpl rule, LeftTuple tuple, ReteEvaluator reteEvaluator ) {
public void rowUpdated( RuleImpl rule, LeftTuple tuple, ReteEvaluator reteEvaluator ) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.drools.base.rule.EntryPointId;
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.impl.InternalRuleBase;
import org.drools.core.reteoo.AbstractLeftTuple;
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.ObjectTypeNode;
import org.drools.core.reteoo.RightTuple;
Expand Down Expand Up @@ -675,19 +676,19 @@ public void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer) {
}

@Override
public void forEachLeftTuple(Consumer<LeftTuple> leftTupleConsumer) {
public void forEachLeftTuple(Consumer<AbstractLeftTuple> leftTupleConsumer) {
for ( LeftTuple leftTuple = firstLeftTuple; leftTuple != null; ) {
LeftTuple nextLeftTuple = leftTuple.getHandleNext();
leftTupleConsumer.accept( leftTuple );
leftTupleConsumer.accept( (AbstractLeftTuple) leftTuple );
leftTuple = nextLeftTuple;
}
}

public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public AbstractLeftTuple findFirstLeftTuple(Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
for ( LeftTuple leftTuple = firstLeftTuple; leftTuple != null; ) {
LeftTuple nextLeftTuple = leftTuple.getHandleNext();
if (lefttTuplePredicate.test( leftTuple )) {
return leftTuple;
if (lefttTuplePredicate.test( (AbstractLeftTuple) leftTuple )) {
return (AbstractLeftTuple) leftTuple;
}
leftTuple = nextLeftTuple;
}
Expand Down Expand Up @@ -837,18 +838,18 @@ public void forEachRightTuple( int partition, Consumer<RightTuple> rightTupleCon
}

@Override
public void forEachLeftTuple( Consumer<LeftTuple> leftTupleConsumer ) {
public void forEachLeftTuple( Consumer<AbstractLeftTuple> leftTupleConsumer ) {
for (int i = 0; i < partitionedTuples.length; i++) {
forEachLeftTuple( i, leftTupleConsumer );
}
}

public void forEachLeftTuple( int partition, Consumer<LeftTuple> leftTupleConsumer ) {
public void forEachLeftTuple( int partition, Consumer<AbstractLeftTuple> leftTupleConsumer ) {
getPartitionedTuple(partition).forEachLeftTuple( leftTupleConsumer );
}

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public AbstractLeftTuple findFirstLeftTuple( Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
return Stream.of( partitionedTuples )
.map( t -> t.findFirstLeftTuple( lefttTuplePredicate ) )
.filter( Objects::nonNull )
Expand Down Expand Up @@ -931,10 +932,10 @@ public void clearRightTuples() { }
public void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer) { }

@Override
public void forEachLeftTuple(Consumer<LeftTuple> leftTupleConsumer) { }
public void forEachLeftTuple(Consumer<AbstractLeftTuple> leftTupleConsumer) { }

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> leftTuplePredicate) {
public AbstractLeftTuple findFirstLeftTuple(Predicate<AbstractLeftTuple> leftTuplePredicate) {
return null;
}

Expand All @@ -955,12 +956,12 @@ public void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer) {
}

@Override
public void forEachLeftTuple(Consumer<LeftTuple> leftTupleConsumer) {
public void forEachLeftTuple(Consumer<AbstractLeftTuple> leftTupleConsumer) {
linkedTuples.forEachLeftTuple( leftTupleConsumer );
}

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public LeftTuple findFirstLeftTuple(Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
return linkedTuples.findFirstLeftTuple( lefttTuplePredicate );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.base.ArrayElements;
import org.drools.core.base.DroolsQueryImpl;
import org.drools.core.reteoo.AbstractLeftTuple;
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.Tuple;
Expand Down Expand Up @@ -174,10 +175,10 @@ public boolean isPendingRemoveFromStore() {
public void forEachRightTuple( Consumer<RightTuple> rightTupleConsumer ) { }

@Override
public void forEachLeftTuple( Consumer<LeftTuple> leftTupleConsumer) { }
public void forEachLeftTuple( Consumer<AbstractLeftTuple> leftTupleConsumer) { }

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public AbstractLeftTuple findFirstLeftTuple( Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.drools.base.factmodel.traits.TraitTypeEnum;
import org.drools.base.rule.EntryPointId;
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.reteoo.AbstractLeftTuple;
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.Tuple;
Expand Down Expand Up @@ -121,9 +122,9 @@ default String getEntryPointName() {
boolean isPendingRemoveFromStore();

void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer );
void forEachLeftTuple(Consumer<LeftTuple> leftTupleConsumer);
void forEachLeftTuple(Consumer<AbstractLeftTuple> leftTupleConsumer);

LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate );
LeftTuple findFirstLeftTuple(Predicate<AbstractLeftTuple> lefttTuplePredicate );

LinkedTuples detachLinkedTuples();
LinkedTuples detachLinkedTuplesForPartition(int i);
Expand Down Expand Up @@ -157,10 +158,10 @@ interface LinkedTuples extends Serializable {

void forEachRightTuple(Consumer<RightTuple> rightTupleConsumer);

void forEachLeftTuple(Consumer<LeftTuple> leftTupleConsumer);
LeftTuple findFirstLeftTuple(Predicate<LeftTuple> leftTuplePredicate );
void forEachLeftTuple(Consumer<AbstractLeftTuple> leftTupleConsumer);
AbstractLeftTuple findFirstLeftTuple(Predicate<AbstractLeftTuple> leftTuplePredicate );

LeftTuple getFirstLeftTuple(int partition);
LeftTuple getFirstLeftTuple( int partition);

default LeftTuple getFirstLeftTuple(RuleBasePartitionId partitionId) {
return getFirstLeftTuple( partitionId.getParallelEvaluationSlot() );
Expand Down Expand Up @@ -381,12 +382,12 @@ public void forEachRightTuple( Consumer<RightTuple> rightTupleConsumer ) {
}

@Override
public void forEachLeftTuple( Consumer<LeftTuple> leftTupleConsumer ) {
public void forEachLeftTuple( Consumer<AbstractLeftTuple> leftTupleConsumer ) {
throw new UnsupportedOperationException();
}

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public LeftTuple findFirstLeftTuple( Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.drools.base.factmodel.traits.TraitTypeEnum;
import org.drools.base.rule.EntryPointId;
import org.drools.core.WorkingMemoryEntryPoint;
import org.drools.core.reteoo.AbstractLeftTuple;
import org.drools.core.reteoo.LeftTuple;
import org.drools.core.reteoo.RightTuple;
import org.drools.core.reteoo.Tuple;
Expand Down Expand Up @@ -273,10 +274,10 @@ public boolean isPendingRemoveFromStore() {
public void forEachRightTuple( Consumer<RightTuple> rightTupleConsumer ) { }

@Override
public void forEachLeftTuple( Consumer<LeftTuple> leftTupleConsumer) { }
public void forEachLeftTuple( Consumer<AbstractLeftTuple> leftTupleConsumer) { }

@Override
public LeftTuple findFirstLeftTuple(Predicate<LeftTuple> lefttTuplePredicate ) {
public AbstractLeftTuple findFirstLeftTuple( Predicate<AbstractLeftTuple> lefttTuplePredicate ) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ private static void visitChild(InternalWorkingMemory wm, boolean insert, Termina

private static void visitChild(LeftTuple lt, boolean insert, InternalWorkingMemory wm, TerminalNode tn) {
LeftTuple prevLt = null;
LeftTupleSinkNode sink = (LeftTupleSinkNode) lt.getTupleSink();
LeftTupleSinkNode sink = lt.getTupleSink();

for ( ; sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
if ( lt != null ) {
Expand Down Expand Up @@ -1190,10 +1190,10 @@ private static void visitChild(LeftTuple lt, boolean insert, InternalWorkingMemo
}
}

private static void insertPeerRightTuple(LeftTuple lt, InternalWorkingMemory wm, TerminalNode tn, boolean insert ) {
private static void insertPeerRightTuple( LeftTuple lt, InternalWorkingMemory wm, TerminalNode tn, boolean insert ) {
// There's a shared RightInputAdapterNode, so check if one of its sinks is associated only to the new rule
LeftTuple prevLt = null;
RightInputAdapterNode rian = (RightInputAdapterNode) lt.getTupleSink();
RightInputAdapterNode rian = lt.getTupleSink();

for (ObjectSink sink : rian.getObjectSinkPropagator().getSinks()) {
if (lt != null) {
Expand Down Expand Up @@ -1304,7 +1304,7 @@ static void deleteLeftTuple(LeftTuple removingLt, LeftTuple removingLt2, LeftTup
LeftTuple rightPrevious = removingLt.getRightParentPrevious();
LeftTuple rightNext = removingLt.getRightParentNext();

LeftTuple leftParent = removingLt.getLeftParent();
LeftTuple leftParent = removingLt.getLeftParent();
RightTuple rightParent = removingLt.getRightParent();

// This tuple is the first peer and thus is linked into the left parent LT.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ private static void visitLeftTuple(InternalWorkingMemory wm, boolean insert, Rul

private static void visitChild(LeftTuple lt, boolean insert, InternalWorkingMemory wm, Rule rule) {
LeftTuple prevLt = null;
LeftTupleSinkNode sink = (LeftTupleSinkNode) lt.getTupleSink();
LeftTupleSinkNode sink = lt.getTupleSink();

for ( ; sink != null; sink = sink.getNextLeftTupleSinkNode() ) {

Expand Down Expand Up @@ -946,7 +946,7 @@ private static void visitChild(LeftTuple lt, boolean insert, InternalWorkingMemo
private static void insertPeerRightTuple( LeftTuple lt, InternalWorkingMemory wm, Rule rule, boolean insert ) {
// There's a shared RightInputAdaterNode, so check if one of its sinks is associated only to the new rule
LeftTuple prevLt = null;
RightInputAdapterNode rian = (RightInputAdapterNode) lt.getTupleSink();
RightInputAdapterNode rian = lt.getTupleSink();

for (ObjectSink sink : rian.getObjectSinkPropagator().getSinks()) {
if (lt != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.drools.core.common.PropagationContext;

public class LeftTupleEntry implements TupleEntry {
private final LeftTuple lt;
private final LeftTuple lt;
private final PropagationContext pctx;
private final Memory nodeMemory;
private final int propagationType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ private static void doPropagateChildLeftTuples(AsyncReceiveNode node,
ContextEntry[] context = betaConstraints.createContext();

TupleList leftTuples = memory.getInsertOrUpdateLeftTuples();
for ( LeftTuple leftTuple = (LeftTuple) leftTuples.getFirst(); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
for ( LeftTuple leftTuple = (LeftTuple) leftTuples.getFirst(); leftTuple != null; leftTuple = ( LeftTuple ) leftTuple.getNext() ) {

betaConstraints.updateFromTuple(context, reteEvaluator, leftTuple);

for (Object message : memory.getMessages()) {
InternalFactHandle factHandle = reteEvaluator.getFactHandleFactory().newFactHandle( message, node.getObjectTypeConf( reteEvaluator ), reteEvaluator, null );
if ( isAllowed( factHandle, node.getAlphaConstraints(), reteEvaluator ) ) {
if (betaConstraints.isAllowedCachedLeft(context, factHandle)) {
LeftTuple childLeftTuple = sink.createLeftTuple(factHandle, leftTuple, sink );
LeftTuple childLeftTuple = sink.createLeftTuple( factHandle, leftTuple, sink );
childLeftTuple.setPropagationContext( leftTuple.getPropagationContext() );
trgLeftTuples.addInsert( childLeftTuple );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public void doLeftInserts(AsyncSendNode node,
betaConstraints.resetTuple(context);
}

private void fetchAndSendResults(AsyncSendNode node, AsyncSendMemory memory, ReteEvaluator reteEvaluator,
ContextEntry[] context, BetaConstraints betaConstraints, AlphaNodeFieldConstraint[] alphaConstraints,
DataProvider dataProvider, Class<?> resultClass, LeftTuple leftTuple, PropagationContext propagationContext ) {
private void fetchAndSendResults( AsyncSendNode node, AsyncSendMemory memory, ReteEvaluator reteEvaluator,
ContextEntry[] context, BetaConstraints betaConstraints, AlphaNodeFieldConstraint[] alphaConstraints,
DataProvider dataProvider, Class<?> resultClass, LeftTuple leftTuple, PropagationContext propagationContext ) {
for (final java.util.Iterator<?> it = dataProvider.getResults(leftTuple,
reteEvaluator,
memory.providerContext); it.hasNext(); ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void doLeftUpdates(ConditionalBranchNode branchNode,

RuleTerminalNode oldRtn = null;
if (branchTuples.rtnLeftTuple != null) {
oldRtn = (RuleTerminalNode) branchTuples.rtnLeftTuple.getTupleSink();
oldRtn = branchTuples.rtnLeftTuple.getTupleSink();
}

ConditionalExecution conditionalExecution = branchEvaluator.evaluate(leftTuple, activationsManager.getReteEvaluator(), cbm.context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ public void doRightInserts(ExistsNode existsNode,
reteEvaluator,
rightTuple.getFactHandleForEvaluation() );

for ( LeftTuple leftTuple = existsNode.getFirstLeftTuple(rightTuple, ltm, it ); leftTuple != null; ) {
for ( LeftTuple leftTuple = existsNode.getFirstLeftTuple( rightTuple, ltm, it ); leftTuple != null; ) {
// preserve next now, in case we remove this leftTuple
LeftTuple temp = (LeftTuple) it.next(leftTuple );
LeftTuple temp = (LeftTuple) it.next( leftTuple );

if ( leftTuple.getStagedType() == LeftTuple.UPDATE ) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
Expand Down Expand Up @@ -307,7 +307,7 @@ public void doRightUpdates(ExistsNode existsNode,
if ( ltm != null && ltm.size() > 0 ) {
FastIterator leftIt = existsNode.getLeftIterator( ltm );

LeftTuple firstLeftTuple = existsNode.getFirstLeftTuple(rightTuple, ltm, leftIt );
LeftTuple firstLeftTuple = existsNode.getFirstLeftTuple( rightTuple, ltm, leftIt );

constraints.updateFromFactHandle( contextEntry,
reteEvaluator,
Expand All @@ -317,7 +317,7 @@ public void doRightUpdates(ExistsNode existsNode,
// first process non-blocked tuples, as we know only those ones are in the left memory.
for ( LeftTuple leftTuple = firstLeftTuple; leftTuple != null; ) {
// preserve next now, in case we remove this leftTuple
LeftTuple temp = (LeftTuple) leftIt.next(leftTuple );
LeftTuple temp = (LeftTuple) leftIt.next( leftTuple );

if ( leftTuple.getStagedType() == LeftTuple.UPDATE ) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
Expand Down Expand Up @@ -504,7 +504,7 @@ public void doRightDeletes(ExistsNode existsNode,
}
}

private static void insertChildLeftTuple(LeftTupleSink sink, TupleSets<LeftTuple> trgLeftTuples, LeftTuple leftTuple, PropagationContext pctx, boolean useLeftMemory ) {
private static void insertChildLeftTuple( LeftTupleSink sink, TupleSets<LeftTuple> trgLeftTuples, LeftTuple leftTuple, PropagationContext pctx, boolean useLeftMemory ) {
if (!leftTuple.isExpired()) {
trgLeftTuples.addInsert( sink.createLeftTuple( leftTuple, sink, pctx, useLeftMemory ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void reaccumulateForLeftTuple(final AccumulateNode accNode,
for (LeftTuple childMatch = (LeftTuple) tupleList.getFirst(); childMatch != null; childMatch = (LeftTuple) childMatch.getNext()) {
RightTuple rightTuple = childMatch.getRightParent();
FactHandle childHandle = rightTuple.getFactHandle();
LeftTuple tuple = leftTuple;
LeftTuple tuple = leftTuple;
if (accNode.isRightInputIsRiaNode()) {
// if there is a subnetwork, handle must be unwrapped
tuple = (LeftTuple) rightTuple;
Expand Down Expand Up @@ -133,7 +133,7 @@ protected void reaccumulateForLeftTuple(final AccumulateNode accNode,
}

@Override
protected void propagateDelete(TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples, Object accctx ) {
protected void propagateDelete( TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples, Object accctx ) {
GroupByContext groupByContext = (GroupByContext)accctx;
for ( TupleList<AccumulateContextEntry> tupleList : groupByContext.getGroups().values()) {
super.propagateDelete(trgLeftTuples, stagedLeftTuples, tupleList.getContext());
Expand Down
Loading

0 comments on commit 069c1b1

Please sign in to comment.