Skip to content

Commit bd8ebc4

Browse files
committed
fixes
1 parent d23d883 commit bd8ebc4

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ private void approveAllBulk(Set<Statement> approved, Set<Resource> approvedConte
939939
}
940940
} catch (IOException | RuntimeException e) {
941941
rollback();
942+
clearEstimatorUpdates();
942943
if (multiThreadingActive) {
943944
logger.error("Encountered an unexpected problem while trying to add a statement.", e);
944945
} else {

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/config/LmdbStoreConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ public Resource export(Model m) {
436436
m.add(implNode, LmdbStoreSchema.SKETCH_ESTIMATOR_CONTEXT_BUCKET_COUNT,
437437
vf.createLiteral(sketchEstimatorContextBucketCount));
438438
}
439-
if (!sketchEstimatorContextPairSketchesEnabled) {
439+
if (sketchEstimatorContextPairSketchesEnabled) {
440440
m.add(implNode, LmdbStoreSchema.SKETCH_ESTIMATOR_CONTEXT_PAIR_SKETCHES_ENABLED,
441-
vf.createLiteral(false));
441+
vf.createLiteral(true));
442442
}
443443
if (!optimizerSamplingEnabled) {
444444
m.add(implNode, LmdbStoreSchema.OPTIMIZER_SAMPLING_ENABLED, vf.createLiteral(false));

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.eclipse.rdf4j.sail.SailException;
5656
import org.eclipse.rdf4j.sail.base.SailDataset;
5757
import org.eclipse.rdf4j.sail.base.SailSink;
58+
import org.eclipse.rdf4j.sail.base.SketchBasedJoinEstimator;
5859
import org.eclipse.rdf4j.sail.lmdb.config.LmdbStoreConfig;
5960
import org.junit.jupiter.api.AfterEach;
6061
import org.junit.jupiter.api.BeforeEach;
@@ -412,6 +413,51 @@ void approveAllUsesConfiguredBulkOperationSize() throws Exception {
412413
}
413414
}
414415

416+
@Test
417+
void approveAllBulkFailureDiscardsNonIsolatedEstimatorUpdates() throws Exception {
418+
LmdbStoreConfig config = new LmdbStoreConfig("spoc,posc");
419+
setBulkOperationSize(config, 2);
420+
LmdbStore sail = new LmdbStore(new File(dataDir, "bulk-failure-estimator"), config);
421+
sail.init();
422+
423+
try {
424+
LmdbSailStore backingStore = sail.getBackingStore();
425+
backingStore.enableMultiThreading = false;
426+
SketchBasedJoinEstimator estimator = backingStore.getSketchBasedJoinEstimator();
427+
try (SailSink seedSink = backingStore.getExplicitSailSource().sink(IsolationLevels.NONE)) {
428+
seedSink.approveAll(sampleStatements(5), Set.of());
429+
seedSink.flush();
430+
}
431+
estimator.rebuild();
432+
assertTrue("Expected estimator to be ready before the failed bulk add", estimator.isReady());
433+
434+
Field tripleStoreField = LmdbSailStore.class.getDeclaredField("tripleStore");
435+
tripleStoreField.setAccessible(true);
436+
TripleStore originalTripleStore = (TripleStore) tripleStoreField.get(backingStore);
437+
TripleStore tripleStoreSpy = spy(originalTripleStore);
438+
439+
doAnswer(invocation -> {
440+
IntConsumer addedIndexConsumer = invocation.getArgument(6);
441+
addedIndexConsumer.accept(0);
442+
throw new IOException("expected aligned bulk failure after estimator update");
443+
}).when(tripleStoreSpy)
444+
.storeTriplesAligned(any(long[].class), any(long[].class), any(long[].class),
445+
any(long[].class), anyInt(), anyBoolean(), any(IntConsumer.class));
446+
447+
tripleStoreField.set(backingStore, tripleStoreSpy);
448+
try (SailSink sink = backingStore.getExplicitSailSource().sink(IsolationLevels.NONE)) {
449+
assertThrows(SailException.class, () -> sink.approveAll(sampleStatements(2), Set.of()));
450+
451+
assertFalse("Expected rollback to discard estimator state after an eager non-isolated update",
452+
estimator.isReady());
453+
} finally {
454+
tripleStoreField.set(backingStore, originalTripleStore);
455+
}
456+
} finally {
457+
sail.shutDown();
458+
}
459+
}
460+
415461
private static void setBulkOperationSize(LmdbStoreConfig config, int bulkOperationSize) {
416462
try {
417463
Method setter = config.getClass().getMethod("setBulkOperationSize", int.class);

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/config/LmdbStoreConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void testThatLmdbStoreConfigParseAndExportSketchEstimatorContextPairSketchesEnab
265265
Values.literal(enabled),
266266
"getSketchEstimatorContextPairSketchesEnabled",
267267
enabled,
268-
!enabled
268+
enabled
269269
);
270270
}
271271

0 commit comments

Comments
 (0)