Skip to content

Commit 779c97a

Browse files
madporunov
authored andcommitted
Fix NO_LIMIT handling for key-value stores
Without fix could not reindex store with more than Integer.MAX_VALUE entries because `KeySelector.limit` is integer Signed-off-by: Pavel Ershov <owner.mad.epa@gmail.com> (cherry picked from commit 9e26fd3) Signed-off-by: Oleksandr Porunov <alexandr.porunov@gmail.com>
1 parent 81fc93f commit 779c97a

7 files changed

Lines changed: 11 additions & 8 deletions

File tree

janusgraph-core/src/main/java/org/janusgraph/diskstorage/keycolumnvalue/keyvalue/KeySelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.common.base.Predicate;
1919
import com.google.common.base.Predicates;
2020
import org.janusgraph.diskstorage.StaticBuffer;
21+
import org.janusgraph.graphdb.query.Query;
2122

2223
/**
2324
* A {@link KeySelector} utility that can be generated out of a given {@link KVQuery}
@@ -50,7 +51,7 @@ public boolean include(StaticBuffer key) {
5051
}
5152

5253
public boolean reachedLimit() {
53-
return count >= limit;
54+
return Query.NO_LIMIT != limit && count >= limit;
5455
}
5556

5657
}

janusgraph-core/src/main/java/org/janusgraph/graphdb/query/LimitAdjustingIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public LimitAdjustingIterator(final int maxLimit, final int currentLimit) {
6767
@Override
6868
public boolean hasNext() {
6969
if (iterator ==null) iterator = getNewIterator(currentLimit);
70-
if (count < currentLimit)
70+
if (currentLimit == Query.NO_LIMIT || count < currentLimit)
7171
return iterator.hasNext();
7272
if (currentLimit>=maxLimit) return false;
7373

janusgraph-core/src/main/java/org/janusgraph/graphdb/query/ResultSetIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public boolean hasNext() {
5252

5353
private R nextInternal() {
5454
R r = null;
55-
if (count < limit && iterator.hasNext()) {
55+
if ((limit == Query.NO_LIMIT || count < limit) && iterator.hasNext()) {
5656
r = iterator.next();
5757
} else {
5858
close();

janusgraph-core/src/main/java/org/janusgraph/graphdb/query/graph/MultiKeySliceQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public List<EntryList> execute(final BackendTransaction tx) {
5151
EntryList next =tx.indexQuery(ksq.updateLimit(getLimit()-total));
5252
result.add(next);
5353
total+=next.size();
54-
if (total>=getLimit()) break;
54+
if (total>=getLimit() && hasLimit()) break;
5555
}
5656
return result;
5757
}

janusgraph-core/src/main/java/org/janusgraph/graphdb/query/vertex/BasicVertexCentricQueryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ public VertexList executeVertexIds(InternalVertex vertex, BaseVertexCentricQuery
383383
VertexListInternal merge = null;
384384

385385
for (InternalVertex rep : representatives) {
386-
if (merge!=null && merge.size()>=baseQuery.getLimit()) break;
386+
if (merge!=null && merge.size()>=baseQuery.getLimit() && baseQuery.hasLimit()) break;
387387
VertexList vertexList = executeIndividualVertexIds(rep,baseQuery);
388388
if (merge==null) merge = (VertexListInternal)vertexList;
389389
else merge.addAll(vertexList);
390390
}
391-
if (merge != null && merge.size()>baseQuery.getLimit()) {
391+
if (merge != null && merge.size()>baseQuery.getLimit() && baseQuery.hasLimit()) {
392392
merge = (VertexListInternal)merge.subList(0,baseQuery.getLimit());
393393
}
394394
return merge;

janusgraph-core/src/main/java/org/janusgraph/graphdb/util/MultiDistinctOrderedIterator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.tinkerpop.gremlin.structure.Element;
1919
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
2020
import org.apache.tinkerpop.gremlin.util.function.MultiComparator;
21+
import org.janusgraph.graphdb.query.Query;
2122
import org.janusgraph.graphdb.tinkerpop.optimize.step.HasStepFolder.OrderEntry;
2223

2324
import java.util.ArrayList;
@@ -58,7 +59,7 @@ public MultiDistinctOrderedIterator(final Integer lowLimit, final Integer highLi
5859

5960
@Override
6061
public boolean hasNext() {
61-
if (limit != null && count >= limit) {
62+
if (limit != null && limit != Query.NO_LIMIT && count >= limit) {
6263
return false;
6364
}
6465
for (int i = 0; i < iterators.size(); i++) {

janusgraph-core/src/main/java/org/janusgraph/graphdb/util/MultiDistinctUnorderedIterator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.apache.tinkerpop.gremlin.structure.Element;
1818
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
19+
import org.janusgraph.graphdb.query.Query;
1920

2021
import java.util.HashSet;
2122
import java.util.Iterator;
@@ -44,7 +45,7 @@ public MultiDistinctUnorderedIterator(final int lowLimit, final int highLimit, f
4445

4546
@Override
4647
protected E computeNext() {
47-
if (count < limit) {
48+
if (limit == Query.NO_LIMIT || count < limit) {
4849
while (iterator.hasNext()) {
4950
E elem = iterator.next();
5051
if (allElements.add(elem.id())) {

0 commit comments

Comments
 (0)