Skip to content

Commit d4c7101

Browse files
authored
Merge main into develop (eclipse-rdf4j#5269)
2 parents a10b405 + c931f34 commit d4c7101

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/ValueStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ protected void clearCaches() {
12561256
valueIDCache.clear();
12571257
namespaceCache.clear();
12581258
namespaceIDCache.clear();
1259+
commonVocabulary.clear();
12591260
}
12601261

12611262
/**

core/sail/lmdb/src/test/java/org/eclipse/rdf4j/sail/lmdb/ValueStoreTest.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525
import java.util.List;
2626
import java.util.Random;
2727
import java.util.Set;
28+
import java.util.stream.Collectors;
2829

2930
import org.eclipse.rdf4j.model.IRI;
3031
import org.eclipse.rdf4j.model.Literal;
3132
import org.eclipse.rdf4j.model.Value;
33+
import org.eclipse.rdf4j.model.util.Values;
34+
import org.eclipse.rdf4j.model.vocabulary.RDF;
35+
import org.eclipse.rdf4j.model.vocabulary.RDFS;
3236
import org.eclipse.rdf4j.model.vocabulary.XSD;
3337
import org.eclipse.rdf4j.sail.lmdb.config.LmdbStoreConfig;
3438
import org.eclipse.rdf4j.sail.lmdb.model.LmdbLiteral;
3539
import org.eclipse.rdf4j.sail.lmdb.model.LmdbValue;
40+
import org.junit.Assert;
3641
import org.junit.jupiter.api.AfterEach;
3742
import org.junit.jupiter.api.BeforeEach;
3843
import org.junit.jupiter.api.Test;
@@ -58,49 +63,53 @@ private ValueStore createValueStore() throws IOException {
5863

5964
@Test
6065
public void testGcValues() throws Exception {
61-
Random random = new Random(1337);
62-
LmdbValue values[] = new LmdbValue[1000];
66+
Value values[] = new Value[] {
67+
RDF.TYPE, RDFS.CLASS,
68+
Values.iri("some:iri"),
69+
Values.literal("This is a literal.")
70+
};
71+
long ids[] = new long[values.length];
6372
valueStore.startTransaction(true);
6473
for (int i = 0; i < values.length; i++) {
65-
values[i] = valueStore.createLiteral("This is a random literal:" + random.nextLong());
66-
valueStore.storeValue(values[i]);
74+
ids[i] = valueStore.storeValue(values[i]);
6775
}
6876
valueStore.commit();
6977

7078
ValueStoreRevision revBefore = valueStore.getRevision();
7179

7280
valueStore.startTransaction(true);
73-
Set<Long> ids = new HashSet<>();
74-
for (int i = 0; i < 30; i++) {
75-
ids.add(values[i].getInternalID());
76-
}
77-
valueStore.gcIds(ids, new HashSet<>());
81+
Set<Long> idsToGc = new HashSet<>(Arrays.stream(ids).boxed().collect(Collectors.toList()));
82+
valueStore.gcIds(idsToGc, new HashSet<>());
7883
valueStore.commit();
7984

8085
ValueStoreRevision revAfter = valueStore.getRevision();
81-
8286
assertNotEquals("revisions must change after gc of IDs", revBefore, revAfter);
8387

84-
Arrays.fill(values, null);
85-
// GC would collect revision at some point in time
86-
// just add revision ID to free list for this test as forcing GC is not possible
88+
for (int i = 0; i < values.length; i++) {
89+
Assert.assertEquals(LmdbValue.UNKNOWN_ID, valueStore.getId(values[i]));
90+
Assert.assertTrue(valueStore.getValue(ids[i]) != null);
91+
}
92+
93+
// simulate GC of unused revisions
8794
valueStore.unusedRevisionIds.add(revBefore.getRevisionId());
8895

8996
valueStore.forceEvictionOfValues();
9097
valueStore.startTransaction(true);
9198
valueStore.commit();
9299

100+
for (int i = 0; i < values.length; i++) {
101+
Assert.assertEquals(LmdbValue.UNKNOWN_ID, valueStore.getId(values[i]));
102+
Assert.assertTrue(valueStore.getValue(ids[i]) != null);
103+
}
104+
93105
valueStore.startTransaction(true);
94-
for (int i = 0; i < 30; i++) {
95-
LmdbValue value = valueStore.createLiteral("This is a random literal:" + random.nextLong());
96-
values[i] = value;
97-
valueStore.storeValue(value);
106+
for (int i = 0; i < values.length; i++) {
98107
// this ID should have been reused
99-
ids.remove(value.getInternalID());
108+
idsToGc.remove(valueStore.storeValue(values[i]));
100109
}
101110
valueStore.commit();
102111

103-
assertEquals("IDs should have been reused", Collections.emptySet(), ids);
112+
assertEquals("IDs should have been reused", Collections.emptySet(), idsToGc);
104113
}
105114

106115
@Test

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclSailValidationException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class ShaclSailValidationException extends SailException implements ValidationException {
2626

2727
private final ValidationReport validationReport;
28+
private Model cachedModel = null;
2829

2930
ShaclSailValidationException(ValidationReport validationReport) {
3031
super("Failed SHACL validation");
@@ -36,6 +37,9 @@ public class ShaclSailValidationException extends SailException implements Valid
3637
*/
3738
@Override
3839
public Model validationReportAsModel() {
40+
if (cachedModel != null) {
41+
return cachedModel;
42+
}
3943
Model model = getValidationReport().asModel();
4044

4145
model.setNamespace(RSX.NS);
@@ -45,6 +49,8 @@ public Model validationReportAsModel() {
4549
model.setNamespace(RDF.NS);
4650
model.setNamespace(RDFS.NS);
4751

52+
cachedModel = model;
53+
4854
return model;
4955
}
5056

0 commit comments

Comments
 (0)