Skip to content

Commit d33a2ab

Browse files
committed
Enh 36422086 - [35884452->24.09] Improve filter re-ordering algorithm for composite filters (address threading issues)
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 107720]
1 parent 53a374a commit d33a2ab

File tree

5 files changed

+80
-89
lines changed

5 files changed

+80
-89
lines changed

prj/coherence-core/src/main/java/com/tangosol/util/filter/AllFilter.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.tangosol.util.QueryRecord;
1414

1515
import java.util.ArrayList;
16-
import java.util.HashSet;
16+
import java.util.LinkedHashSet;
1717
import java.util.List;
1818
import java.util.Map;
1919
import java.util.Set;
@@ -57,7 +57,7 @@ public AllFilter(Filter[] afilter)
5757
*/
5858
public boolean evaluate(Object o)
5959
{
60-
Filter[] afilter = m_aFilter;
60+
Filter[] afilter = getFilters();
6161
for (int i = 0, c = afilter.length; i < c; i++)
6262
{
6363
if (!afilter[i].evaluate(o))
@@ -77,7 +77,7 @@ public int calculateEffectiveness(Map mapIndexes, Set setKeys)
7777
{
7878
optimizeFilterOrder(mapIndexes, setKeys);
7979

80-
Filter[] aFilter = m_aFilter;
80+
Filter[] aFilter = getFilters();
8181
int cFilters = aFilter.length;
8282

8383
if (cFilters > 0)
@@ -102,7 +102,8 @@ public int calculateEffectiveness(Map mapIndexes, Set setKeys)
102102
protected boolean evaluateEntry(Map.Entry entry, QueryContext ctx,
103103
QueryRecord.PartialResult.TraceStep step)
104104
{
105-
for (Filter filter : m_aFilter)
105+
Filter<?>[] aFilter = getFilters();
106+
for (Filter<?> filter : aFilter)
106107
{
107108
if (!evaluateFilter(filter, entry, ctx,
108109
step == null ? null : step.ensureStep(filter)))
@@ -114,43 +115,43 @@ protected boolean evaluateEntry(Map.Entry entry, QueryContext ctx,
114115
}
115116

116117
@Override
117-
protected Set<Filter<?>> simplifyFilters()
118+
protected Filter<?>[] simplifyFilters(Filter<?>[] aFilter)
118119
{
119-
Set<Filter<?>> setFilters = new HashSet<>();
120-
for (Filter<?> filter : m_aFilter)
120+
Set<Filter<?>> setFilters = new LinkedHashSet<>();
121+
for (Filter<?> filter : aFilter)
121122
{
122-
if (filter instanceof AllFilter)
123+
if (filter instanceof AllFilter && !(filter instanceof BetweenFilter))
123124
{
124125
// pull nested AND/ALL filters to top level
125-
setFilters.addAll(((AllFilter) filter).simplifyFilters());
126+
setFilters.addAll(List.of(((AllFilter) filter).getFilters()));
126127
}
127128
else
128129
{
129130
// remove duplicates
130131
setFilters.add(filter);
131132
}
132133
}
133-
return setFilters;
134+
return setFilters.toArray(Filter[]::new);
134135
}
135136

136137
@Override
137-
protected Filter applyIndex(Map mapIndexes, Set setKeys,
138+
protected Filter<?> applyIndex(Map mapIndexes, Set setKeys,
138139
QueryContext ctx, QueryRecord.PartialResult.TraceStep step)
139140
{
140141
optimizeFilterOrder(mapIndexes, setKeys);
141142

142-
Filter[] aFilter = m_aFilter;
143-
int cFilters = aFilter.length;
144-
List listFilter = new ArrayList(cFilters);
143+
Filter<?>[] aFilter = getFilters();
144+
int cFilters = aFilter.length;
145+
List<Filter<?>> listFilter = new ArrayList<>(cFilters);
145146

146147
// listFilter is an array of filters that will have to be re-applied
147148

148149
for (int i = 0; i < cFilters; i++)
149150
{
150-
Filter filter = aFilter[i];
151+
Filter<?> filter = aFilter[i];
151152
if (filter instanceof IndexAwareFilter)
152153
{
153-
Filter filterNew = applyFilter(filter, i, mapIndexes, setKeys, ctx, step);
154+
Filter<?> filterNew = applyFilter(filter, i, mapIndexes, setKeys, ctx, step);
154155

155156
if (setKeys.isEmpty())
156157
{
@@ -175,21 +176,20 @@ else if (filter != null)
175176
}
176177
else if (cFilters == 1)
177178
{
178-
return (Filter) listFilter.get(0);
179+
return listFilter.get(0);
179180
}
180181
else
181182
{
182-
return new AllFilter((Filter[])
183-
listFilter.toArray(new Filter[cFilters]));
183+
return new AllFilter(listFilter.toArray(new Filter[cFilters]));
184184
}
185185
}
186186

187187
protected String getName()
188188
{
189-
switch (m_aFilter.length)
189+
switch (getFilters().length)
190190
{
191191
case 1:
192-
return m_aFilter[0].getClass().getSimpleName();
192+
return getFilters()[0].getClass().getSimpleName();
193193
case 2:
194194
return "AndFilter";
195195
default:

prj/coherence-core/src/main/java/com/tangosol/util/filter/AnyFilter.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.util.ArrayList;
1717
import java.util.HashSet;
18+
import java.util.LinkedHashSet;
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
@@ -58,7 +59,7 @@ public AnyFilter(Filter[] afilter)
5859
*/
5960
public boolean evaluate(Object o)
6061
{
61-
Filter[] afilter = m_aFilter;
62+
Filter[] afilter = getFilters();
6263
for (int i = 0, c = afilter.length; i < c; i++)
6364
{
6465
if (afilter[i].evaluate(o))
@@ -79,7 +80,7 @@ public int calculateEffectiveness(Map mapIndexes, Set setKeys)
7980
{
8081
optimizeFilterOrder(mapIndexes, setKeys);
8182

82-
Filter[] aFilter = m_aFilter;
83+
Filter[] aFilter = getFilters();
8384
int cFilters = aFilter.length;
8485

8586
if (cFilters > 0)
@@ -105,7 +106,7 @@ public int calculateEffectiveness(Map mapIndexes, Set setKeys)
105106
protected boolean evaluateEntry(Map.Entry entry, QueryContext ctx,
106107
QueryRecord.PartialResult.TraceStep step)
107108
{
108-
Filter[] afilter = m_aFilter;
109+
Filter[] afilter = getFilters();
109110
for (int i = 0, c = afilter.length; i < c; i++)
110111
{
111112
Filter filter = afilter[i];
@@ -123,23 +124,23 @@ protected boolean evaluateEntry(Map.Entry entry, QueryContext ctx,
123124
* {@inheritDoc}
124125
*/
125126
@Override
126-
protected Set<Filter<?>> simplifyFilters()
127+
protected Filter<?>[] simplifyFilters(Filter<?>[] aFilter)
127128
{
128-
Set<Filter<?>> setFilters = new HashSet<>();
129-
for (Filter<?> filter : m_aFilter)
129+
Set<Filter<?>> setFilters = new LinkedHashSet<>();
130+
for (Filter<?> filter : aFilter)
130131
{
131132
if (filter instanceof AnyFilter)
132133
{
133134
// pull nested OR/ANY filters to top level
134-
setFilters.addAll(((AnyFilter) filter).simplifyFilters());
135+
setFilters.addAll(List.of(((AnyFilter) filter).getFilters()));
135136
}
136137
else
137138
{
138139
// remove duplicates
139140
setFilters.add(filter);
140141
}
141142
}
142-
return setFilters;
143+
return setFilters.toArray(Filter[]::new);
143144
}
144145

145146
/**
@@ -151,7 +152,7 @@ protected Filter applyIndex(Map mapIndexes, Set setKeys, QueryContext ctx,
151152
{
152153
optimizeFilterOrder(mapIndexes, setKeys);
153154

154-
Filter[] aFilter = m_aFilter;
155+
Filter[] aFilter = getFilters();
155156
int cFilters = aFilter.length;
156157
List listFilter = new ArrayList(cFilters);
157158
Set setMatch = new HashSet(setKeys.size());
@@ -249,10 +250,10 @@ else if (cFilters == 1 && cMatches == 0)
249250

250251
protected String getName()
251252
{
252-
switch (m_aFilter.length)
253+
switch (getFilters().length)
253254
{
254255
case 1:
255-
return m_aFilter[0].getClass().getSimpleName();
256+
return getFilters()[0].getClass().getSimpleName();
256257
case 2:
257258
return "OrFilter";
258259
default:

0 commit comments

Comments
 (0)