|
12 | 12 |
|
13 | 13 | import java.io.File; |
14 | 14 | import java.io.IOException; |
15 | | -import java.nio.charset.StandardCharsets; |
16 | 15 | import java.nio.file.Files; |
17 | 16 | import java.nio.file.Path; |
18 | 17 | import java.util.Comparator; |
19 | 18 | import java.util.concurrent.locks.ReentrantLock; |
20 | 19 | import java.util.function.Supplier; |
21 | 20 | import java.util.stream.Stream; |
22 | 21 |
|
23 | | -import org.apache.commons.io.FileUtils; |
24 | 22 | import org.eclipse.rdf4j.collection.factory.api.CollectionFactory; |
25 | 23 | import org.eclipse.rdf4j.collection.factory.mapdb.MapDb3CollectionFactory; |
26 | 24 | import org.eclipse.rdf4j.common.annotation.Experimental; |
27 | 25 | import org.eclipse.rdf4j.common.concurrent.locks.Lock; |
28 | 26 | import org.eclipse.rdf4j.common.concurrent.locks.LockManager; |
29 | | -import org.eclipse.rdf4j.common.io.MavenUtil; |
30 | 27 | import org.eclipse.rdf4j.common.transaction.IsolationLevel; |
31 | 28 | import org.eclipse.rdf4j.common.transaction.IsolationLevels; |
32 | 29 | import org.eclipse.rdf4j.model.ValueFactory; |
33 | 30 | import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategy; |
34 | 31 | import org.eclipse.rdf4j.query.algebra.evaluation.EvaluationStrategyFactory; |
35 | 32 | import org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolver; |
36 | 33 | import org.eclipse.rdf4j.query.algebra.evaluation.federation.FederatedServiceResolverClient; |
37 | | -import org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategyFactory; |
| 34 | +import org.eclipse.rdf4j.query.algebra.evaluation.impl.DefaultEvaluationStrategyFactory; |
38 | 35 | import org.eclipse.rdf4j.repository.sparql.federation.SPARQLServiceResolver; |
39 | 36 | import org.eclipse.rdf4j.sail.InterruptedSailException; |
40 | 37 | import org.eclipse.rdf4j.sail.NotifyingSailConnection; |
@@ -62,8 +59,10 @@ public class LmdbStore extends AbstractNotifyingSail implements FederatedService |
62 | 59 | /*-----------* |
63 | 60 | * Variables * |
64 | 61 | *-----------*/ |
65 | | - |
66 | | - private static final String VERSION = MavenUtil.loadVersion("org.eclipse.rdf4j", "rdf4j-sail-lmdb", "devel"); |
| 62 | + /** |
| 63 | + * The current version of the LMDB store. |
| 64 | + */ |
| 65 | + static final int VERSION = 2; |
67 | 66 |
|
68 | 67 | /** |
69 | 68 | * Specifies which triple indexes this lmdb store must use. |
@@ -169,7 +168,7 @@ public void setDataDir(File dataDir) { |
169 | 168 | */ |
170 | 169 | public synchronized EvaluationStrategyFactory getEvaluationStrategyFactory() { |
171 | 170 | if (evalStratFactory == null) { |
172 | | - evalStratFactory = new StrictEvaluationStrategyFactory(getFederatedServiceResolver()); |
| 171 | + evalStratFactory = new DefaultEvaluationStrategyFactory(getFederatedServiceResolver()); |
173 | 172 | } |
174 | 173 | evalStratFactory.setQuerySolutionCacheThreshold(getIterationCacheSyncThreshold()); |
175 | 174 | evalStratFactory.setTrackResultSize(isTrackResultSize()); |
@@ -252,18 +251,33 @@ protected void initializeInternal() throws SailException { |
252 | 251 | logger.debug("Data dir is " + dataDir); |
253 | 252 |
|
254 | 253 | try { |
255 | | - File versionFile = new File(dataDir, "lmdbrdf.ver"); |
256 | | - String version = versionFile.exists() ? FileUtils.readFileToString(versionFile, StandardCharsets.UTF_8) |
257 | | - : null; |
258 | | - if (!VERSION.equals(version) && upgradeStore(dataDir, version)) { |
259 | | - FileUtils.writeStringToFile(versionFile, VERSION, StandardCharsets.UTF_8); |
| 254 | + StoreProperties properties = new StoreProperties(dataDir); |
| 255 | + // ensure that it is an error if an unsupported version of LmdbStore already exists |
| 256 | + if (new File(dataDir, "lmdbrdf.ver").exists()) { |
| 257 | + throw new SailException("Directory contains data from an older unsupported version of LmdbStore"); |
| 258 | + } |
| 259 | + boolean updateVersion = false; |
| 260 | + if (properties.load()) { |
| 261 | + if (!String.valueOf(VERSION).equals(properties.getVersion())) { |
| 262 | + updateVersion = upgradeStore(dataDir, properties.getVersion()); |
| 263 | + } |
| 264 | + } else { |
| 265 | + properties.setVersion(String.valueOf(VERSION)); |
260 | 266 | } |
261 | | - backingStore = new LmdbSailStore(dataDir, config); |
262 | | - this.store = new SnapshotSailStore(backingStore, () -> new MemoryOverflowModel() { |
| 267 | + |
| 268 | + backingStore = new LmdbSailStore(dataDir, properties, config); |
| 269 | + |
| 270 | + // update version afer loading and potential internal migration within value and triple store |
| 271 | + if (updateVersion) { |
| 272 | + properties.setVersion(String.valueOf(VERSION)); |
| 273 | + } |
| 274 | + properties.save(); |
| 275 | + |
| 276 | + this.store = new SnapshotSailStore(backingStore, () -> new MemoryOverflowModel(false) { |
263 | 277 | @Override |
264 | 278 | protected LmdbSailStore createSailStore(File dataDir) throws IOException, SailException { |
265 | 279 | // Model can't fit into memory, use another LmdbSailStore to store delta |
266 | | - LmdbSailStore lmdbSailStore = new LmdbSailStore(dataDir, config); |
| 280 | + LmdbSailStore lmdbSailStore = new LmdbSailStore(dataDir, new StoreProperties(), config); |
267 | 281 | lmdbSailStore.enableMultiThreading = false; |
268 | 282 | return lmdbSailStore; |
269 | 283 | } |
|
0 commit comments