Skip to content

Commit 6445d18

Browse files
committed
fixes
1 parent 91cdf60 commit 6445d18

3 files changed

Lines changed: 66 additions & 14 deletions

File tree

core/sail/base/src/main/java/org/eclipse/rdf4j/sail/base/SketchBasedJoinEstimator.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,8 +1934,6 @@ public void startBackgroundRefresh(int stalenessThreshold) {
19341934
}
19351935
continue;
19361936
}
1937-
// Staleness staleness = staleness();
1938-
// System.out.println(staleness.toString());
19391937

19401938
try {
19411939
rebuild();
@@ -3259,11 +3257,6 @@ private static double enforceCardinalityLowerBound(ArrayOfDoublesSketch sketch,
32593257
if (sketch == null || !Double.isFinite(cardinality)) {
32603258
return cardinality;
32613259
}
3262-
// if(cardinality < sketch.getEstimate()){
3263-
// System.out.println("Cardinality " + cardinality + " is lower than sketch estimate " + sketch.getEstimate());
3264-
// }else if(cardinality > sketch.getEstimate()) {
3265-
// System.out.println("Cardinality " + cardinality + " is higher than sketch estimate " + sketch.getEstimate());
3266-
// }
32673260

32683261
// Cardinality cannot be lower than the estimated number of distinct join bindings.
32693262
// return Math.max(cardinality, sketch.getEstimate());
@@ -3547,10 +3540,9 @@ private static final class State {
35473540

35483541
State(int k, int subjectBuckets, int predicateBuckets, int objectBuckets, int contextBuckets,
35493542
boolean contextPairSketchesEnabled) {
3550-
System.out.println("Initializing state: k=" + k + ", subjectBuckets=" + subjectBuckets
3551-
+ ", predicateBuckets="
3552-
+ predicateBuckets + ", objectBuckets=" + objectBuckets + ", contextBuckets=" + contextBuckets
3553-
+ ", contextPairSketchesEnabled=" + contextPairSketchesEnabled);
3543+
logger.info(
3544+
"Initializing state: k={}, subjectBuckets={}, predicateBuckets={}, objectBuckets={}, contextBuckets={}, contextPairSketchesEnabled={}",
3545+
k, subjectBuckets, predicateBuckets, objectBuckets, contextBuckets, contextPairSketchesEnabled);
35543546
this.k = k;
35553547
this.subjectBuckets = subjectBuckets;
35563548
this.predicateBuckets = predicateBuckets;
@@ -8207,7 +8199,13 @@ private long samplingInterval() {
82078199
*/
82088200
public boolean persistIfDirty() {
82098201
flushPendingIncremental();
8210-
SketchEstimatorPersistenceStore store = persistenceStore;
8202+
SketchEstimatorPersistenceStore store;
8203+
try {
8204+
store = ensurePersistenceStore();
8205+
} catch (Throwable t) {
8206+
logger.warn("Failed to open join estimator persistence store at {}", persistenceFile, t);
8207+
return false;
8208+
}
82118209
if (!persistenceEnabled || persistenceFile == null || store == null) {
82128210
return false;
82138211
}
@@ -8935,7 +8933,7 @@ private boolean appendDirtySketchIfResident(int entryId, SketchAddress address,
89358933

89368934
private void appendNativeSketchPayload(State state, int entryId, SketchAddress address, byte[] payload)
89378935
throws IOException {
8938-
SketchEstimatorPersistenceStore store = persistenceStore;
8936+
SketchEstimatorPersistenceStore store = ensurePersistenceStore();
89398937
if (store != null) {
89408938
byte slot = slotByte(slotOf(state));
89418939
int slotBytes = shouldPersistCompactly(address) ? payload.length : state.maxSketchBytes;
@@ -8960,6 +8958,25 @@ private void appendNativeSketchPayload(State state, int entryId, SketchAddress a
89608958
throw new IOException("No directory-backed sketch store configured");
89618959
}
89628960

8961+
private SketchEstimatorPersistenceStore ensurePersistenceStore() throws IOException {
8962+
if (!persistenceEnabled || persistenceFile == null) {
8963+
return null;
8964+
}
8965+
SketchEstimatorPersistenceStore store = persistenceStore;
8966+
if (store != null) {
8967+
return store;
8968+
}
8969+
synchronized (persistLock) {
8970+
store = persistenceStore;
8971+
if (store == null && persistenceEnabled && persistenceFile != null) {
8972+
logger.info("RdfJoinEstimator: Opening default directory-backed sketch store at {}", persistenceFile);
8973+
store = SketchEstimatorPersistenceStore.open(persistenceFile, logger, sketchFileChunks());
8974+
persistenceStore = store;
8975+
}
8976+
return store;
8977+
}
8978+
}
8979+
89638980
private void clearDirtyMappedSketch(int entryId, byte slot) {
89648981
synchronized (sketchCacheLock) {
89658982
cacheDirectory.clearDirty(entryId, slot);

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,35 @@ void closeWritesEstimatorSnapshotAndReopensLazy(@TempDir File dataDir) throws Ex
159159
}
160160
}
161161

162+
@Test
163+
void persistIfDirtyReopensDefaultDirectoryBackedSketchStore(@TempDir File dataDir) throws Exception {
164+
var vf = SimpleValueFactory.getInstance();
165+
var s = vf.createIRI("urn:default-store:s");
166+
var p = vf.createIRI("urn:default-store:p");
167+
var o = vf.createIRI("urn:default-store:o");
168+
169+
LmdbStore store = new LmdbStore(dataDir, new LmdbStoreConfig("spoc"));
170+
store.init();
171+
try {
172+
SketchBasedJoinEstimator estimator = store.getBackingStore().getSketchBasedJoinEstimator();
173+
estimator.stop();
174+
estimator.rebuild();
175+
176+
AutoCloseable persistenceStore = (AutoCloseable) objectField(estimator, "persistenceStore");
177+
persistenceStore.close();
178+
setObjectField(estimator, "persistenceStore", null);
179+
180+
estimator.addStatement(vf.createStatement(s, p, o));
181+
182+
assertTrue(estimator.persistIfDirty(),
183+
"Estimator persistence should reopen the default directory-backed sketch store");
184+
} finally {
185+
store.shutDown();
186+
}
187+
188+
assertTrue(estimatorMetadata(dataDir).isFile(), "Expected estimator metadata in the default store directory");
189+
}
190+
162191
@Test
163192
void closeWritesFilterSelectivitySidecarAndReloadsItAfterRestart(@TempDir File dataDir) throws Exception {
164193
Filter learnedFilter = firstFilter(LEARNED_FILTER_QUERY);
@@ -662,6 +691,12 @@ private static Object objectField(Object target, String name) throws Exception {
662691
return field.get(target);
663692
}
664693

694+
private static void setObjectField(Object target, String name, Object value) throws Exception {
695+
Field field = target.getClass().getDeclaredField(name);
696+
field.setAccessible(true);
697+
field.set(target, value);
698+
}
699+
665700
private static int pendingIncrementalStatementQueueSize(SketchBasedJoinEstimator estimator) throws Exception {
666701
Object[] queues = (Object[]) objectField(estimator, "incrementalStatementQueues");
667702
int pending = 0;

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/benchmark/DatagovLoadIsolationBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class DatagovLoadIsolationBenchmark {
6363

6464
private static final String DATA_FILE = "benchmarkFiles/datagovbe-valid.ttl.gz";
6565

66-
@Param({ "NONE", "READ_COMMITTED" })
66+
@Param({ "NONE", "READ_COMMITTED", "SNAPSHOT_READ", "SNAPSHOT", "SERIALIZABLE" })
6767
public IsolationLevels isolationLevel;
6868

6969
@Param({ "256" })

0 commit comments

Comments
 (0)