Skip to content

Commit a5291bb

Browse files
authored
GH-5254 LMDB store: Correctly clear common vocabulary cache. (#5257)
2 parents cd6509b + 875bdaa commit a5291bb

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

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
@@ -1252,6 +1252,7 @@ protected void clearCaches() {
12521252
valueIDCache.clear();
12531253
namespaceCache.clear();
12541254
namespaceIDCache.clear();
1255+
commonVocabulary.clear();
12551256
}
12561257

12571258
/**

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

0 commit comments

Comments
 (0)