@@ -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 );
0 commit comments