Skip to content

Commit 2e49e1f

Browse files
committed
working on new ID based join iterator
1 parent b088bd9 commit 2e49e1f

File tree

3 files changed

+33
-48
lines changed

3 files changed

+33
-48
lines changed

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/LmdbDupRecordIterator.java

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,26 @@ RecordIterator get(long[] quadReuse, ByteBuffer minKeyBuf, ByteBuffer maxKeyBuf,
8585
private int lastResult;
8686
private boolean closed = true;
8787

88-
private RecordIterator fallback;
89-
private FallbackSupplier fallbackSupplier;
90-
9188
LmdbDupRecordIterator(DupIndex index, long subj, long pred,
92-
boolean explicit, Txn txnRef, FallbackSupplier fallbackSupplier) throws IOException {
93-
initialize(index, subj, pred, explicit, txnRef, null, fallbackSupplier);
89+
boolean explicit, Txn txnRef) throws IOException {
90+
initialize(index, subj, pred, explicit, txnRef, null);
9491
}
9592

9693
LmdbDupRecordIterator(DupIndex index, long subj, long pred,
97-
boolean explicit, Txn txnRef, long[] quadReuse, FallbackSupplier fallbackSupplier) throws IOException {
98-
initialize(index, subj, pred, explicit, txnRef, quadReuse, fallbackSupplier);
94+
boolean explicit, Txn txnRef, long[] quadReuse) throws IOException {
95+
initialize(index, subj, pred, explicit, txnRef, quadReuse);
9996
}
10097

101-
void initialize(DupIndex index, long subj, long pred, boolean explicit, Txn txnRef, long[] quadReuse,
102-
FallbackSupplier fallbackSupplier) throws IOException {
103-
if (!closed || fallback != null) {
98+
void initialize(DupIndex index, long subj, long pred, boolean explicit, Txn txnRef, long[] quadReuse)
99+
throws IOException {
100+
if (!closed) {
104101
throw new IllegalStateException("Cannot initialize LMDB dup iterator while it is open");
105102
}
106103

107104
this.index = index;
108105
this.dupDbi = index.getDupDB(explicit);
109106
this.txnRef = txnRef;
110107
this.txnLockManager = txnRef.lockManager();
111-
this.fallbackSupplier = fallbackSupplier;
112-
this.fallback = null;
113108

114109
this.prefixSubj = subj;
115110
this.prefixPred = pred;
@@ -165,21 +160,16 @@ void initialize(DupIndex index, long subj, long pred, boolean explicit, Txn txnR
165160
}
166161
if (!positioned) {
167162
closeInternal(false);
168-
fallbackIterator = createFallback();
163+
// TODO: We must be empty????
169164
}
170165
} finally {
171166
txnLockManager.unlockRead(readStamp);
172167
}
173168

174-
this.fallback = fallbackIterator;
175169
}
176170

177171
@Override
178172
public long[] next() {
179-
if (fallback != null) {
180-
return fallback.next();
181-
}
182-
183173
long readStamp;
184174
try {
185175
readStamp = txnLockManager.readLock();
@@ -402,14 +392,7 @@ private void closeInternal(boolean maybeCalledAsync) {
402392

403393
@Override
404394
public void close() {
405-
if (fallback != null) {
406-
fallback.close();
407-
fallback = null;
408-
fallbackSupplier = null;
409-
} else {
410-
closeInternal(true);
411-
fallbackSupplier = null;
412-
}
395+
closeInternal(true);
413396
txnLockManager = null;
414397
txnRef = null;
415398
}
@@ -433,10 +416,4 @@ private long openCursor(long txn, int dbi, boolean tryReuse) throws IOException
433416
}
434417
}
435418

436-
private RecordIterator createFallback() throws IOException {
437-
if (fallbackSupplier == null) {
438-
return null;
439-
}
440-
return fallbackSupplier.get(quad, null, null, null);
441-
}
442419
}

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/TripleStore.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -618,15 +618,7 @@ public RecordIterator getTriples(Txn txn, long subj, long pred, long obj, long c
618618
TripleIndex index = getBestIndex(subj, pred, obj, context);
619619
// System.out.println("get triples: " + Arrays.asList(subj, pred, obj,context));
620620
boolean doRangeSearch = index.getPatternScore(subj, pred, obj, context) > 0;
621-
LmdbDupRecordIterator.FallbackSupplier fallbackSupplier = (quad, minBuf, maxBuf, reuse) -> {
622-
if (reuse != null) {
623-
reuse.initialize(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quad, minBuf,
624-
maxBuf);
625-
return reuse;
626-
}
627-
return new LmdbRecordIterator(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quad,
628-
minBuf, maxBuf);
629-
};
621+
630622
LmdbRecordIterator recordReuse = iteratorReuse instanceof LmdbRecordIterator
631623
? (LmdbRecordIterator) iteratorReuse
632624
: null;
@@ -635,17 +627,35 @@ public RecordIterator getTriples(Txn txn, long subj, long pred, long obj, long c
635627
: null;
636628
if (dupsortRead && subjectPredicateIndex != null && subj >= 0 && pred >= 0 && obj == -1 && context == -1) {
637629
assert context == -1 && obj == -1 : "subject-predicate index can only be used for (s,p,?,?) patterns";
630+
631+
// LmdbDupRecordIterator.FallbackSupplier fallbackSupplier = (quad, minBuf, maxBuf, reuse) -> {
632+
// if (reuse != null) {
633+
// reuse.initialize(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quad, minBuf,
634+
// maxBuf);
635+
// return reuse;
636+
// }
637+
// return new LmdbRecordIterator(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quad,
638+
// minBuf, maxBuf);
639+
// };
640+
638641
// Use SP dup iterator, but union with the standard iterator to guard against any edge cases
639642
// in SP storage/retrieval; de-duplicate at the record level.
640643
if (dupReuse != null) {
641-
dupReuse.initialize(subjectPredicateIndex, subj, pred, explicit, txn, quadReuse, fallbackSupplier);
644+
dupReuse.initialize(subjectPredicateIndex, subj, pred, explicit, txn, quadReuse);
642645
return dupReuse;
643646
}
644-
return new LmdbDupRecordIterator(subjectPredicateIndex, subj, pred, explicit, txn, quadReuse,
645-
fallbackSupplier);
647+
return new LmdbDupRecordIterator(subjectPredicateIndex, subj, pred, explicit, txn, quadReuse);
646648
}
647-
return getTriplesUsingIndex(txn, subj, pred, obj, context, explicit, index, doRangeSearch, fallbackSupplier,
648-
minKeyBuf, maxKeyBuf, quadReuse, recordReuse);
649+
650+
if (recordReuse != null) {
651+
recordReuse.initialize(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quadReuse,
652+
minKeyBuf,
653+
maxKeyBuf);
654+
return recordReuse;
655+
}
656+
return new LmdbRecordIterator(index, null, doRangeSearch, subj, pred, obj, context, explicit, txn, quadReuse,
657+
minKeyBuf, maxKeyBuf);
658+
649659
}
650660

651661
boolean hasTriples(boolean explicit) throws IOException {

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/LmdbIdJoinEvaluationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
import org.eclipse.rdf4j.sail.base.SailDataset;
5555
import org.eclipse.rdf4j.sail.base.SailDatasetTripleSource;
5656
import org.eclipse.rdf4j.sail.base.SailSource;
57-
import org.eclipse.rdf4j.sail.lmdb.LmdbEvaluationDataset;
58-
import org.eclipse.rdf4j.sail.lmdb.LmdbEvaluationDataset.KeyRangeBuffers;
5957
import org.eclipse.rdf4j.sail.lmdb.join.LmdbIdJoinQueryEvaluationStep;
6058
import org.junit.jupiter.api.Test;
6159
import org.junit.jupiter.api.io.TempDir;

0 commit comments

Comments
 (0)