Skip to content

Commit

Permalink
GH-3572 allow concurrent reads and writes against the WeakObjectRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Håvard Ottestad <hmottestad@gmail.com>
  • Loading branch information
hmottestad committed Jan 7, 2022
1 parent afd8b18 commit f717f88
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,11 @@ protected void parsePrefixID() throws IOException, RDFParseException, RDFHandler
skipWSC();

// Read the namespace URI
IRI namespace = parseURI();
String namespaceStr = parseURI().toString();

// Store and report this namespace mapping
String prefixStr = prefixID.toString();
String namespaceStr = namespace.toString();

// Store and report this namespace mapping
setNamespace(prefixStr, namespaceStr);

if (rdfHandler != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.eclipse.rdf4j.sail.base.SailSink;
import org.eclipse.rdf4j.sail.base.SailSource;
import org.eclipse.rdf4j.sail.base.SailStore;
import org.eclipse.rdf4j.sail.memory.model.CloseableIterator;
import org.eclipse.rdf4j.sail.memory.model.MemBNode;
import org.eclipse.rdf4j.sail.memory.model.MemIRI;
import org.eclipse.rdf4j.sail.memory.model.MemResource;
import org.eclipse.rdf4j.sail.memory.model.MemStatement;
Expand Down Expand Up @@ -782,20 +784,25 @@ public CloseableIteration<? extends Resource, SailException> getContextIDs() thr

Lock stLock = openStatementsReadLock();
try {
synchronized (valueFactory) {
int snapshot = getCurrentSnapshot();
for (MemResource memResource : valueFactory.getMemURIs()) {
int snapshot = getCurrentSnapshot();
try (CloseableIterator<MemIRI> memIRIsIterator = valueFactory.getMemIRIsIterator()) {
while (memIRIsIterator.hasNext()) {
MemResource memResource = memIRIsIterator.next();
if (isContextResource(memResource, snapshot)) {
contextIDs.add(memResource);
}
}
}

for (MemResource memResource : valueFactory.getMemBNodes()) {
try (CloseableIterator<MemBNode> memBNodesIterator = valueFactory.getMemBNodesIterator()) {
while (memBNodesIterator.hasNext()) {
MemResource memResource = memBNodesIterator.next();
if (isContextResource(memResource, snapshot)) {
contextIDs.add(memResource);
}
}
}

} finally {
stLock.release();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* Copyright (c) 2022 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
******************************************************************************/

package org.eclipse.rdf4j.sail.memory.model;

import java.util.Iterator;

public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable {

@Override
void close();
}
Loading

0 comments on commit f717f88

Please sign in to comment.