This is an automated email from the ASF dual-hosted git repository.
afs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new d029fdcf9a GH-3431: Ignore incomplete compaction directories when
finding TDB2 storage
d029fdcf9a is described below
commit d029fdcf9a90d5d4309521d2d5e90e8f97f8482c
Author: Duansg <[email protected]>
AuthorDate: Wed Sep 23 23:13:09 2026 -0700
GH-3431: Ignore incomplete compaction directories when finding TDB2 storage
---
.../java/org/apache/jena/tdb2/sys/DatabaseOps.java | 8 ++++++++
.../apache/jena/tdb2/sys/TestDatabaseCompact.java | 23 ++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseOps.java
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseOps.java
index a9faab2fc3..d8b2062983 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseOps.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/sys/DatabaseOps.java
@@ -101,6 +101,8 @@ public class DatabaseOps {
// while initializing the area for TDB2 usage in this JVM.
/*package*/ static final String incompleteWIP = "jena-tdb-temp-files";
+ // EXACT: error on any other "Data*" name except for compaction temporary
directories.
+ // SKIP: ignore other names.
private enum ScanAccept { EXACT, SKIP }
/**
@@ -531,11 +533,17 @@ public class DatabaseOps {
Pattern pattern = Pattern.compile(Pattern.quote(namebase)+
Pattern.quote(nameSep)+
trailerPattern);
+ // Left behind by an incomplete compaction; removed when the database
is next connected.
+ Pattern tmpPattern = Pattern.compile(Pattern.quote(namebase)+
+ Pattern.quote(nameSep)+
+ dbTmpPattern);
List<Path> paths = new ArrayList<>();
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(directory, namebase + "*")) {
for ( Path entry : stream ) {
String filename = entry.getFileName().toString();
if ( !pattern.matcher(filename).matches() ) {
+ if ( tmpPattern.matcher(filename).matches() )
+ continue;
switch ( skipOthers ) {
case EXACT: throw new DBOpEnvException("Invalid
filename for matching: "+entry.getFileName());
case SKIP: continue;
diff --git
a/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseCompact.java
b/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseCompact.java
index 488651ae45..acaac09322 100644
--- a/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseCompact.java
+++ b/jena-tdb2/src/test/java/org/apache/jena/tdb2/sys/TestDatabaseCompact.java
@@ -337,4 +337,27 @@ public class TestDatabaseCompact
assertFalse(Files.exists(pathFile2));
assertFalse(Files.exists(pathTmp2));
}
+
+ @Test public void compact_recovery_2() throws IOException {
+ DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
+ Txn.executeWrite(dsg, ()->dsg.add(quad1));
+
+ DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable)dsg;
+ Path containerPath = dsgs.getContainerPath();
+ Path storagePath = DatabaseOps.findStorageLocation(containerPath);
+ assertNotNull(storagePath);
+
+ // Mock an incomplete compaction.
+ Path pathTmp = containerPath.resolve("Data-0002-tmp");
+ Files.createDirectory(pathTmp);
+ TDBInternal.expel(dsg);
+
+ // Before reconnecting (which cleans up) - e.g. Fuseki checking the
database.
+ assertEquals(storagePath,
DatabaseOps.findStorageLocation(containerPath));
+ assertEquals(storagePath, DatabaseOps.findStorageLocation(dir));
+
+ DatasetGraph dsg2 = DatabaseMgr.connectDatasetGraph(dir);
+ Txn.executeRead(dsg2, ()->assertTrue(dsg2.contains(quad1)));
+ assertFalse(Files.exists(pathTmp));
+ }
}