Skip to content

Commit 81a33b3

Browse files
committed
wip
1 parent 58e6c8c commit 81a33b3

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ class TripleStore implements Closeable {
8080
*/
8181
private static final String INDEXES_KEY = "triple-indexes";
8282

83+
/**
84+
* System property that enables the experimental {@link MemoryMappedTxnStatusFile} implementation instead of the
85+
* default {@link TxnStatusFile}.
86+
*/
87+
private static final String MEMORY_MAPPED_TXN_STATUS_FILE_ENABLED_PROP = "org.eclipse.rdf4j.sail.nativerdf.MemoryMappedTxnStatusFile.enabled";
88+
8389
/**
8490
* The version number for the current triple store.
8591
* <ul>
@@ -168,7 +174,7 @@ public TripleStore(File dir, String indexSpecStr) throws IOException, SailExcept
168174
public TripleStore(File dir, String indexSpecStr, boolean forceSync) throws IOException, SailException {
169175
this.dir = dir;
170176
this.forceSync = forceSync;
171-
this.txnStatusFile = new TxnStatusFile(dir);
177+
this.txnStatusFile = createTxnStatusFile(dir);
172178

173179
File propFile = new File(dir, PROPERTIES_FILE);
174180

@@ -223,6 +229,13 @@ public TripleStore(File dir, String indexSpecStr, boolean forceSync) throws IOEx
223229
}
224230
}
225231

232+
private static TxnStatusFile createTxnStatusFile(File dir) throws IOException {
233+
if (Boolean.getBoolean(MEMORY_MAPPED_TXN_STATUS_FILE_ENABLED_PROP)) {
234+
return new MemoryMappedTxnStatusFile(dir);
235+
}
236+
return new TxnStatusFile(dir);
237+
}
238+
226239
/*---------*
227240
* Methods *
228241
*---------*/
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Eclipse RDF4J contributors.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Distribution License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/org/documents/edl-v10.php.
8+
*
9+
* SPDX-License-Identifier: BSD-3-Clause
10+
*******************************************************************************/
11+
package org.eclipse.rdf4j.sail.nativerdf;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
import java.io.File;
17+
18+
import org.junit.jupiter.api.AfterEach;
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.io.TempDir;
21+
22+
/**
23+
* Verifies that the implementation used for the transaction status file can be controlled via a system property.
24+
*/
25+
public class MemoryMappedTxnStatusFileConfigTest {
26+
27+
private static final String MEMORY_MAPPED_ENABLED_PROP = "org.eclipse.rdf4j.sail.nativerdf.MemoryMappedTxnStatusFile.enabled";
28+
29+
@TempDir
30+
File dataDir;
31+
32+
@AfterEach
33+
public void clearProperty() {
34+
System.clearProperty(MEMORY_MAPPED_ENABLED_PROP);
35+
}
36+
37+
@Test
38+
public void defaultUsesNioTxnStatusFile() throws Exception {
39+
TripleStore tripleStore = new TripleStore(dataDir, "spoc");
40+
try {
41+
tripleStore.startTransaction();
42+
tripleStore.storeTriple(1, 2, 3, 4);
43+
tripleStore.commit();
44+
} finally {
45+
tripleStore.close();
46+
}
47+
48+
File txnStatusFile = new File(dataDir, TxnStatusFile.FILE_NAME);
49+
assertTrue(txnStatusFile.exists(), "Transaction status file should exist");
50+
assertEquals(0L, txnStatusFile.length(),
51+
"Default TxnStatusFile implementation truncates the file for NONE status");
52+
}
53+
54+
@Test
55+
public void memoryMappedEnabledUsesFixedSizeFile() throws Exception {
56+
System.setProperty(MEMORY_MAPPED_ENABLED_PROP, "true");
57+
58+
TripleStore tripleStore = new TripleStore(dataDir, "spoc");
59+
try {
60+
tripleStore.startTransaction();
61+
tripleStore.storeTriple(1, 2, 3, 4);
62+
tripleStore.commit();
63+
} finally {
64+
tripleStore.close();
65+
}
66+
67+
File txnStatusFile = new File(dataDir, TxnStatusFile.FILE_NAME);
68+
assertTrue(txnStatusFile.exists(), "Transaction status file should exist");
69+
assertEquals(1L, txnStatusFile.length(),
70+
"Memory-mapped TxnStatusFile keeps a single status byte on disk for NONE status");
71+
}
72+
}

0 commit comments

Comments
 (0)