Skip to content

Commit 6aea374

Browse files
committed
everything else
1 parent bab1a5b commit 6aea374

86 files changed

Lines changed: 5174 additions & 463 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/lmdb/LmdbPARQL11UpdateComplianceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ protected Repository newRepository() throws Exception {
3737
return new DatasetRepository(
3838
new SailRepository(new LmdbStore(temp, new LmdbStoreConfig("spoc"))));
3939
}
40+
41+
@Override
42+
protected boolean deleteDataDirAfterShutdown() {
43+
return true;
44+
}
4045
}

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/lmdb/LmdbSPARQL11QueryComplianceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ protected Repository newRepository() throws Exception {
3636
new SailRepository(new LmdbStore(temp, new LmdbStoreConfig("spoc"))));
3737
}
3838

39+
@Override
40+
protected boolean deleteDataDirAfterShutdown() {
41+
return true;
42+
}
43+
3944
}

compliance/sparql/src/test/java/org/eclipse/rdf4j/sail/lmdb/LmdbSPARQLComplianceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public RepositoryImplConfig getConfig() {
3030
}
3131
});
3232
}
33+
34+
@Override
35+
protected boolean deleteDataDirAfterShutdown() {
36+
return true;
37+
}
3338
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Some portions generated by Codex
12+
package org.eclipse.rdf4j.common.transaction;
13+
14+
/**
15+
* Transaction setting that enables data import metrics for a single transaction.
16+
*/
17+
public enum DataImportMetrics implements TransactionSetting {
18+
ENABLED
19+
}

core/model/src/main/java/org/eclipse/rdf4j/model/impl/AbstractMemoryOverflowModel.java

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import com.sun.management.GcInfo;
4444

4545
@InternalUseOnly
46-
public abstract class AbstractMemoryOverflowModel<T extends AbstractModel> extends AbstractModel {
46+
public abstract class AbstractMemoryOverflowModel<T extends AbstractModel> extends AbstractModel
47+
implements AutoCloseable {
4748

4849
private static final long serialVersionUID = 4119844228099208169L;
4950

@@ -86,7 +87,7 @@ public abstract class AbstractMemoryOverflowModel<T extends AbstractModel> exten
8687

8788
static final Logger logger = LoggerFactory.getLogger(AbstractMemoryOverflowModel.class);
8889

89-
private volatile LinkedHashModel memory;
90+
private volatile Model memory;
9091

9192
protected transient volatile T disk;
9293

@@ -188,11 +189,12 @@ private static double mbFree() {
188189
private volatile boolean closed;
189190

190191
public AbstractMemoryOverflowModel() {
191-
memory = new LinkedHashModel();
192+
memory = new DynamicModel(new LinkedHashModelFactory(), true);
192193
}
193194

194195
public AbstractMemoryOverflowModel(Set<Namespace> namespaces) {
195-
memory = new LinkedHashModel(namespaces, 0);
196+
memory = new DynamicModel(new LinkedHashModelFactory(), true);
197+
namespaces.forEach(memory::setNamespace);
196198
}
197199

198200
@Override
@@ -225,6 +227,11 @@ public boolean contains(Resource subj, IRI pred, Value obj, Resource... contexts
225227
return getDelegate().contains(subj, pred, obj, contexts);
226228
}
227229

230+
@Override
231+
public boolean isEmpty() {
232+
return getDelegate().isEmpty();
233+
}
234+
228235
@Override
229236
public boolean add(Resource subj, IRI pred, Value obj, Resource... contexts) {
230237
checkMemoryOverflow();
@@ -312,15 +319,55 @@ protected void removeFilteredTermIteration(Iterator<Statement> iter, Resource su
312319
public synchronized void removeTermIteration(Iterator<Statement> iter, Resource subj, IRI pred, Value obj,
313320
Resource... contexts) {
314321
if (disk == null) {
315-
memory.removeTermIteration(iter, subj, pred, obj, contexts);
322+
if (memory instanceof AbstractModel) {
323+
((AbstractModel) memory).removeTermIteration(iter, subj, pred, obj, contexts);
324+
} else if (memory instanceof DynamicModel) {
325+
((DynamicModel) memory).removeTermIteration(iter, subj, pred, obj, contexts);
326+
} else {
327+
iter.remove();
328+
while (iter.hasNext()) {
329+
Statement statement = iter.next();
330+
if (matchesPattern(statement, subj, pred, obj, contexts)) {
331+
iter.remove();
332+
}
333+
}
334+
}
316335
} else {
317336
disk.removeTermIteration(iter, subj, pred, obj, contexts);
318337
}
319338
}
320339

340+
private static boolean matchesPattern(Statement statement, Resource subj, IRI pred, Value obj,
341+
Resource... contexts) {
342+
if (subj != null && !subj.equals(statement.getSubject())) {
343+
return false;
344+
}
345+
if (pred != null && !pred.equals(statement.getPredicate())) {
346+
return false;
347+
}
348+
if (obj != null && !obj.equals(statement.getObject())) {
349+
return false;
350+
}
351+
if (contexts == null || contexts.length == 0) {
352+
return true;
353+
}
354+
for (Resource context : contexts) {
355+
boolean contextMatch = context == null
356+
? statement.getContext() == null
357+
: context.equals(statement.getContext());
358+
if (contextMatch) {
359+
return true;
360+
}
361+
}
362+
return false;
363+
}
364+
321365
private Model getDelegate() {
322366
var memory = this.memory;
323367
if (memory != null) {
368+
if (memory instanceof DynamicModel) {
369+
((DynamicModel) memory).maybeRegisterLargeStatementSetForReuse((DynamicModel) memory);
370+
}
324371
return memory;
325372
} else {
326373
var disk = this.disk;
@@ -418,7 +465,7 @@ private synchronized void overflowToDisk() {
418465
return;
419466
}
420467

421-
LinkedHashModel memory = this.memory;
468+
Model memory = this.memory;
422469
this.memory = null;
423470
overflowToDiskInner(memory);
424471

@@ -434,5 +481,44 @@ private synchronized void overflowToDisk() {
434481

435482
}
436483

484+
@Override
485+
public void close() {
486+
boolean wasClosed = false;
487+
boolean interrupted = false;
488+
try {
489+
interrupted = Thread.interrupted();
490+
lock.lockInterruptibly();
491+
try {
492+
if (closed) {
493+
wasClosed = true;
494+
return;
495+
}
496+
closed = true;
497+
memory = null;
498+
disk = null;
499+
} finally {
500+
lock.unlock();
501+
}
502+
} catch (InterruptedException e) {
503+
Thread.currentThread().interrupt();
504+
throw new RuntimeException(e);
505+
} finally {
506+
if (interrupted) {
507+
Thread.currentThread().interrupt();
508+
}
509+
510+
// even if we were interrupted we want to make sure we don't leave the model in an inconsistent state and
511+
// that we free up any resources as soon as possible, so we null out the references to the memory and disk
512+
// models and close the disk model if it was not already closed by another thread
513+
memory = null;
514+
disk = null;
515+
if (!wasClosed) {
516+
innerClose();
517+
}
518+
}
519+
}
520+
521+
abstract protected void innerClose();
522+
437523
protected abstract void overflowToDiskInner(Model memory);
438524
}

core/model/src/main/java/org/eclipse/rdf4j/model/impl/AbstractModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class AbstractModel extends AbstractSet<Statement> implements Mo
3232

3333
private static final long serialVersionUID = 4254119331281455614L;
3434
public static final Resource[] NULL_CONTEXT = { null };
35+
public static final Resource[] NO_CONTEXT = {};
3536

3637
@Override
3738
public Model unmodifiable() {
@@ -45,7 +46,7 @@ public boolean add(Statement st) {
4546

4647
@Override
4748
public boolean isEmpty() {
48-
return !contains(null, null, null);
49+
return !contains(null, null, null, NO_CONTEXT);
4950
}
5051

5152
@Override

0 commit comments

Comments
 (0)