You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/07/22 14:23:31 UTC

git commit: less locking/synchronization

Updated Branches:
  refs/heads/develop 28aa7006f -> 2d70611c0


less locking/synchronization


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/2d70611c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/2d70611c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/2d70611c

Branch: refs/heads/develop
Commit: 2d70611c01f3c2d3bf630f7cef2466f34d36b513
Parents: 28aa700
Author: Sebastian Schaffert <ss...@apache.org>
Authored: Mon Jul 22 14:23:08 2013 +0200
Committer: Sebastian Schaffert <ss...@apache.org>
Committed: Mon Jul 22 14:23:08 2013 +0200

----------------------------------------------------------------------
 .../marmotta/kiwi/sail/KiWiValueFactory.java    | 48 ++++++++++++--------
 1 file changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/2d70611c/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
----------------------------------------------------------------------
diff --git a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
index 477efaf..ca383a3 100644
--- a/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
+++ b/libraries/kiwi/kiwi-triplestore/src/main/java/org/apache/marmotta/kiwi/sail/KiWiValueFactory.java
@@ -109,7 +109,7 @@ public class KiWiValueFactory implements ValueFactory {
         this.defaultContext = defaultContext;
 
         // batch commits
-        this.nodeBatch      = new ArrayList<KiWiNode>(batchSize);
+        this.nodeBatch      = Collections.synchronizedList(new ArrayList<KiWiNode>(batchSize));
 
         this.batchCommit    = store.getPersistence().getConfiguration().isBatchCommit();
         this.batchSize      = store.getPersistence().getConfiguration().getBatchSize();
@@ -188,14 +188,17 @@ public class KiWiValueFactory implements ValueFactory {
 
                         if(result.getId() == null) {
                             if(batchCommit) {
-                                result.setId(connection.getNodeId());
-                                synchronized (nodeBatch) {
+                                commitLock.enter();
+                                try {
+                                    result.setId(connection.getNodeId());
                                     nodeBatch.add(result);
                                     batchUriLookup.put(uri,result);
 
                                     if(nodeBatch.size() >= batchSize) {
                                         flushBatch(connection);
                                     }
+                                } finally {
+                                    commitLock.leave();
                                 }
                             } else {
                                 connection.storeNode(result, false);
@@ -267,13 +270,16 @@ public class KiWiValueFactory implements ValueFactory {
 
                         if(result.getId() == null) {
                             if(batchCommit) {
-                                result.setId(connection.getNodeId());
-                                synchronized (nodeBatch) {
+                                commitLock.enter();
+                                try {
+                                    result.setId(connection.getNodeId());
                                     nodeBatch.add(result);
                                     batchBNodeLookup.put(nodeID,result);
-                                }
-                                if(nodeBatch.size() >= batchSize) {
-                                    flushBatch(connection);
+                                    if(nodeBatch.size() >= batchSize) {
+                                        flushBatch(connection);
+                                    }
+                                } finally {
+                                    commitLock.leave();
                                 }
                             } else {
                                 connection.storeNode(result, false);
@@ -478,14 +484,18 @@ public class KiWiValueFactory implements ValueFactory {
 
                     if(result.getId() == null) {
                         if(batchCommit) {
-                            result.setId(connection.getNodeId());
-                            synchronized (nodeBatch) {
+                            commitLock.enter();
+                            try {
+                                result.setId(connection.getNodeId());
                                 nodeBatch.add(result);
                                 batchLiteralLookup.put(LiteralCommons.createCacheKey(value.toString(),locale,type), result);
 
                                 if(nodeBatch.size() >= batchSize) {
                                     flushBatch(connection);
                                 }
+
+                            } finally {
+                                commitLock.leave();
                             }
                         } else {
                             connection.storeNode(result, false);
@@ -679,7 +689,7 @@ public class KiWiValueFactory implements ValueFactory {
      * @return The created statement.
      */
     public Statement createStatement(Resource subject, URI predicate, Value object, Resource context, KiWiConnection connection) {
-        IntArray cacheKey = IntArray.createSPOCKey(subject,predicate,object,context);
+        IntArray cacheKey = IntArray.createSPOCKey(subject, predicate, object, context);
         KiWiTriple result = (KiWiTriple)tripleRegistry.get(cacheKey);
         try {
             if(result == null || ((KiWiTriple)result).isDeleted()) {
@@ -766,16 +776,14 @@ public class KiWiValueFactory implements ValueFactory {
             try {
                 con.startNodeBatch();
 
-                synchronized (nodeBatch) {
-                    for(KiWiNode n : nodeBatch) {
-                        con.storeNode(n,true);
-                    }
-                    nodeBatch.clear();
-
-                    batchLiteralLookup.clear();
-                    batchUriLookup.clear();
-                    batchBNodeLookup.clear();
+                for(KiWiNode n : nodeBatch) {
+                    con.storeNode(n,true);
                 }
+                nodeBatch.clear();
+
+                batchLiteralLookup.clear();
+                batchUriLookup.clear();
+                batchBNodeLookup.clear();
 
                 con.commitNodeBatch();
             } finally {