Skip to content

Commit 474ad30

Browse files
committed
Remove the possibility of disabling fsync completely
1 parent ca1abf3 commit 474ad30

4 files changed

Lines changed: 62 additions & 5 deletions

File tree

core/sail/lucene-api/src/main/java/org/eclipse/rdf4j/sail/lucene/LuceneSail.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,8 @@ public class LuceneSail extends NotifyingSailWrapper {
308308
/**
309309
* Set the key "fsyncInterval=<t>" as sail parameter to configure the interval in milliseconds in which fsync
310310
* is called on the Lucene index, default is defined in {@link #DEFAULT_FSYNC_INTERVAL}. Changes in the index will
311-
* become visible to readers at most after the interval is elapsed. If set to 0 or a negative value, fsync will be
312-
* disabled completely and there are no guarantees as to when your data will be persisted. This setting is only used
313-
* when {@link #TRANSACTIONAL_KEY} is set to false (rollbacks disabled).
311+
* become visible to readers at most after the interval is elapsed. This must be set to a value > 0. This setting
312+
* is only used when {@link #TRANSACTIONAL_KEY} is set to false (rollbacks disabled).
314313
*/
315314
public static final String FSYNC_INTERVAL_KEY = "fsyncInterval";
316315

core/sail/lucene/src/main/java/org/eclipse/rdf4j/sail/lucene/impl/LuceneIndex.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ public synchronized void initialize(Properties parameters) throws Exception {
229229
this.fsyncIntervalMillis = NumberUtils.toLong(
230230
parameters.getProperty(LuceneSail.FSYNC_INTERVAL_KEY),
231231
LuceneSail.DEFAULT_FSYNC_INTERVAL);
232+
if (this.fsyncIntervalMillis <= 0) {
233+
throw new IllegalArgumentException(LuceneSail.FSYNC_INTERVAL_KEY + " must be > 0");
234+
}
232235
}
233236

234237
postInit();
@@ -294,9 +297,11 @@ private void postInit() throws IOException {
294297

295298
private void setUpFsyncScheduler() {
296299
// If transactions are disabled, launch a background thread to fsync periodically.
297-
if (this.transactionsEnabled || this.fsyncIntervalMillis <= 0) {
300+
if (this.transactionsEnabled) {
298301
return;
299302
}
303+
// Checked in initialize(), assertion here for clarity.
304+
assert this.fsyncIntervalMillis > 0;
300305

301306
// Use a daemon thread so the scheduler does not prevent JVM shutdown.
302307
this.fsyncScheduler = new ScheduledThreadPoolExecutor(1, r -> {

core/sail/lucene/src/test/java/org/eclipse/rdf4j/sail/lucene/impl/LuceneNonTransactionalTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2025 Eclipse RDF4J contributors.
2+
* Copyright (c) 2026 Eclipse RDF4J contributors.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Distribution License v1.0
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 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.lucene.impl;
12+
13+
import static org.junit.Assert.assertThrows;
14+
15+
import java.util.Properties;
16+
17+
import org.eclipse.rdf4j.sail.lucene.LuceneSail;
18+
import org.junit.jupiter.api.Assertions;
19+
import org.junit.jupiter.api.Test;
20+
21+
/**
22+
* Test to verify that LuceneSail parameters are validated correctly.
23+
*
24+
* @author Piotr Sowiński
25+
*/
26+
public class LuceneParametersTest {
27+
28+
@Test
29+
public void testZeroFsyncInterval() {
30+
var index = new LuceneIndex();
31+
var params = new Properties();
32+
params.setProperty(LuceneSail.FSYNC_INTERVAL_KEY, "0");
33+
params.setProperty(LuceneSail.LUCENE_RAMDIR_KEY, "true");
34+
var e = assertThrows(IllegalArgumentException.class, () -> index.initialize(params));
35+
Assertions.assertTrue(
36+
e.getMessage().contains(LuceneSail.FSYNC_INTERVAL_KEY),
37+
"Message should mention fsync interval"
38+
);
39+
}
40+
41+
@Test
42+
public void testNegativeFsyncInterval() {
43+
var index = new LuceneIndex();
44+
var params = new Properties();
45+
params.setProperty(LuceneSail.FSYNC_INTERVAL_KEY, "-10");
46+
params.setProperty(LuceneSail.LUCENE_RAMDIR_KEY, "true");
47+
var e = assertThrows(IllegalArgumentException.class, () -> index.initialize(params));
48+
Assertions.assertTrue(
49+
e.getMessage().contains(LuceneSail.FSYNC_INTERVAL_KEY),
50+
"Message should mention fsync interval"
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)