[ 
https://issues.apache.org/jira/browse/MARMOTTA-191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13626048#comment-13626048
 ] 

Peter Ansell commented on MARMOTTA-191:
---------------------------------------

The relevant method is below:

        public synchronized MemURI getOrCreateMemURI(URI uri) {
                MemURI memURI = getMemURI(uri);

                if (memURI == null) {
                        // Namespace strings are relatively large objects and 
are shared
                        // between uris
                        String namespace = uri.getNamespace();
                        String sharedNamespace = 
namespaceRegistry.get(namespace);

                        if (sharedNamespace == null) {
                                // New namespace, add it to the registry
                                namespaceRegistry.add(namespace);
                        }
                        else {
                                // Use the shared namespace
                                namespace = sharedNamespace;
                        }

                        // Create a MemURI and add it to the registry
                        memURI = new MemURI(this, namespace, 
uri.getLocalName());
                        boolean wasNew = uriRegistry.add(memURI);
                        assert wasNew : "Created a duplicate MemURI for URI " + 
uri;
                }

                return memURI;
        }

The uriRegistry is an org.openrdf.sail.memory.model.WeakObjectRegistry<MemURI>, 
so it could reasonably be expected to be modified by the Garbage Collector in 
strange ways, as it uses a map with java.lang.ref.WeakReference values 
internally.

The uriReigstry is also directly references from the following methods, only 
two of which are synchronized, although getMemURIs returns an unmodifiable view 
on the set, and clear simply calls the clear method:
* clear() : uriRegistry.clear()
* synchronized getMemURI(URI)
* getMemURIs() : return Collections.unmodifiableSet(uriRegistry);
* synchronized getOrCreateMemURI(URI)

I don't think this is major priority, but it may be a bug if you are able to 
consistently reproduce it with "-ea" enabled. Servers do not typically have 
"-ea" enabled, so they should be fine. Could you open an issue on the OpenRDF 
Jira with the source code from SPARQLGraphResultWriter.write as the starting 
point for pinpointing an issue. 

In either case, it is highly inefficient to create a MemoryStore in 
SPARQLGraphResultWriter.write when you could iterate directly over the 
Statements in GraphQueryResult to export to any RDFHandler using 
RDFHandler.handleStatement() (of which RDFWriter is a subclass). You can keep 
the namespaces using RDFHandler.handleNamespace. There is a helper method in 
QueryResultIO that can do that for you, 
QueryResultIO.write(GraphQueryResult,RDFFormat,OutputStream).

                
> SPARQL graph results fails under some circunstances
> ---------------------------------------------------
>
>                 Key: MARMOTTA-191
>                 URL: https://issues.apache.org/jira/browse/MARMOTTA-191
>             Project: Marmotta
>          Issue Type: Bug
>          Components: Platform
>    Affects Versions: 2.6, 3.0-incubating
>            Reporter: Sergio Fernández
>            Assignee: Sergio Fernández
>            Priority: Minor
>             Fix For: 3.1-incubating
>
>
> Write some unit tests: 
> https://git-wip-us.apache.org/repos/asf?p=incubator-marmotta.git;a=blob;f=platform/marmotta-sparql/src/test/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebServiceTest.java;h=06d03ebdcbcdec8cdf33e4ae975383ee6c2332bf;hb=HEAD#l91
> I realized the SPARQL Graph results fails:
>       java.lang.AssertionError: Created a duplicate MemURI for URI 
> http://www.wikier.org/foaf#wikier
>       at 
> org.openrdf.sail.memory.model.MemValueFactory.getOrCreateMemURI(MemValueFactory.java:281)
>       at 
> org.openrdf.sail.memory.model.MemValueFactory.getOrCreateMemResource(MemValueFactory.java:247)
>       at 
> org.openrdf.sail.memory.MemoryStore.addStatement(MemoryStore.java:538)
>       at 
> org.openrdf.sail.memory.MemoryStoreConnection.addStatementInternal(MemoryStoreConnection.java:441)
>       at 
> org.openrdf.sail.memory.MemoryStoreConnection.addStatementInternal(MemoryStoreConnection.java:395)
>       at 
> org.openrdf.sail.helpers.SailConnectionBase.addStatement(SailConnectionBase.java:441)
>       at 
> org.openrdf.repository.sail.SailRepositoryConnection.addWithoutCommit(SailRepositoryConnection.java:281)
>       at 
> org.openrdf.repository.base.RepositoryConnectionBase.addWithoutCommit(RepositoryConnectionBase.java:561)
>       at 
> org.openrdf.repository.base.RepositoryConnectionBase.add(RepositoryConnectionBase.java:433)
>       at 
> org.apache.marmotta.platform.sparql.services.sparqlio.rdf.SPARQLGraphResultWriter.write(SPARQLGraphResultWriter.java:68)
>       at 
> org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.query(SparqlServiceImpl.java:195)
>       at 
> org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl.query(SparqlServiceImpl.java:108)
>       at 
> org.apache.marmotta.platform.sparql.services.sparql.SparqlServiceImpl$Proxy$_$$_WeldClientProxy.query(SparqlServiceImpl$Proxy$_$$_WeldClientProxy.java)
>       at 
> org.apache.marmotta.platform.sparql.webservices.SparqlWebService$1.write(SparqlWebService.java:485)
> But I'm not totally sure it's actually a bug, either on our side or in 
> Sesame, because I cannot easily reproduce it on all environments: it works 
> fine at runtime and from junit at eclipse, but it fails from maven.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to