Github user wastl commented on a diff in the pull request:
https://github.com/apache/marmotta/pull/15#discussion_r44345877
--- Diff:
libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
---
@@ -575,13 +577,29 @@ public Statement createStatement(Resource subject,
URI predicate, Value object,
registry.registerKey(cacheKey,
connection.getTransactionId(), result.getId());
} else {
// not found in registry, try loading from database
-
result.setId(connection.getTripleId(ksubject,kpredicate,kobject,kcontext));
+ needsDBLookup = true;
}
+ }
+
+ if(needsDBLookup) {
+
result.setId(connection.getTripleId(ksubject,kpredicate,kobject,kcontext));
+ }
- // triple has no id from registry or database, so we
create one and flag it for reasoning
- if(result.getId() < 0) {
- result.setId(connection.getNextSequence());
- result.setNewTriple(true);
+ // triple has no id from registry or database, so we create
one and flag it for reasoning
+ if(result.getId() < 0) {
+ synchronized (registry) {
+ // It's possible a concurrent thread might have
created this
+ // triple while we were blocked. Check the registry
again.
+ long tripleId = registry.lookupKey(cacheKey);
+
+ if(tripleId >= 0) {
+ // A concurrent thread got in first. Take the one
it created.
+ result.setId(tripleId);
--- End diff --
I guess in this case the call to registerKey below is not needed (it came
from the registry).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---