{"action":"created","comment":{"url":"https://api.github.com/repos/neo4j/neo4j/pulls/comments/70794177","id":70794177,"diff_hunk":"@@ -0,0 +1,198 @@\n+/*\n+ * Copyright (c) 2002-2016 \"Neo Technology,\"\n+ * Network Engine for Objects in Lund AB [http://neotechnology.com]\n+ *\n+ * This file is part of Neo4j.\n+ *\n+ * Neo4j is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ */\n+package org.neo4j.kernel.impl.locking.deferred;\n+\n+import org.apache.commons.lang3.mutable.MutableInt;\n+\n+import java.util.Arrays;\n+import java.util.Map;\n+import java.util.TreeMap;\n+\n+import org.neo4j.kernel.impl.locking.AcquireLockTimeoutException;\n+import org.neo4j.kernel.impl.locking.LockClientStoppedException;\n+import org.neo4j.kernel.impl.locking.Locks;\n+\n+// TODO the state keeping in this class is quite unoptimized, please do so\n+public class DeferringLockClient implements Locks.Client\n+{\n+    private final Locks.Client clientDelegate;\n+    private final Map<LockUnit,MutableInt> locks = new TreeMap<>();\n+    private volatile boolean stopped;\n+\n+    public DeferringLockClient( Locks.Client clientDelegate )\n+    {\n+        this.clientDelegate = clientDelegate;\n+    }\n+\n+    @Override\n+    public void acquireShared( Locks.ResourceType resourceType, long... resourceIds ) throws AcquireLockTimeoutException\n+    {\n+        for ( long resourceId : resourceIds )\n+        {\n+            addLock( resourceType, resourceId, false );\n+        }\n+    }\n+\n+    @Override\n+    public void acquireExclusive( Locks.ResourceType resourceType, long... resourceIds )\n+            throws AcquireLockTimeoutException\n+    {\n+        for ( long resourceId : resourceIds )\n+        {\n+            addLock( resourceType, resourceId, true );\n+        }\n+    }\n+\n+    @Override\n+    public boolean tryExclusiveLock( Locks.ResourceType resourceType, long resourceId )\n+    {\n+        throw new UnsupportedOperationException( \"Should not be needed\" );\n+    }\n+\n+    @Override\n+    public boolean trySharedLock( Locks.ResourceType resourceType, long resourceId )\n+    {\n+        throw new UnsupportedOperationException( \"Should not be needed\" );\n+    }\n+\n+    @Override\n+    public void releaseShared( Locks.ResourceType resourceType, long resourceId )\n+    {\n+        removeLock( resourceType, resourceId, false );\n+    }\n+\n+    @Override\n+    public void releaseExclusive( Locks.ResourceType resourceType, long resourceId )\n+    {\n+        removeLock( resourceType, resourceId, true );\n+    }\n+\n+    void acquireDeferredLocks()\n+    {\n+        long[] current = new long[10];\n+        int cursor = 0;\n+        Locks.ResourceType currentType = null;\n+        boolean currentExclusive = false;\n+        for ( LockUnit lockUnit : locks.keySet() )\n+        {\n+            // TODO perhaps also add a condition which sends batches over a certain size threshold\n+            if ( currentType == null ||\n+                 (currentType.typeId() != lockUnit.resourceType().typeId() ||\n+                  currentExclusive != lockUnit.isExclusive()) )\n+            {\n+                // New type, i.e. flush the current array down to delegate in one call\n+                flushLocks( current, cursor, currentType, currentExclusive );\n+\n+                cursor = 0;\n+                currentType = lockUnit.resourceType();\n+                currentExclusive = lockUnit.isExclusive();\n+            }\n+\n+            // Queue into current batch\n+            if ( cursor == current.length )\n+            {\n+                current = Arrays.copyOf( current, cursor * 2 );\n+            }\n+            current[cursor++] = lockUnit.resourceId();\n+        }\n+        flushLocks( current, cursor, currentType, currentExclusive );\n+    }\n+\n+    private void flushLocks( long[] current, int cursor, Locks.ResourceType currentType, boolean exclusive )\n+    {\n+        assertNotStopped();\n+\n+        if ( cursor > 0 )","path":"community/kernel/src/main/java/org/neo4j/kernel/impl/locking/deferred/DeferringLockClient.java","position":122,"original_position":122,"commit_id":"67cb577123cfa66fb8bc7931716c59231192297f","original_commit_id":"67cb577123cfa66fb8bc7931716c59231192297f","user":{"login":"burqen","id":5220077,"avatar_url":"https://avatars.githubusercontent.com/u/5220077?v=3","gravatar_id":"","url":"https://api.github.com/users/burqen","html_url":"https://github.com/burqen","followers_url":"https://api.github.com/users/burqen/followers","following_url":"https://api.github.com/users/burqen/following{/other_user}","gists_url":"https://api.github.com/users/burqen/gists{/gist_id}","starred_url":"https://api.github.com/users/burqen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burqen/subscriptions","organizations_url":"https://api.github.com/users/burqen/orgs","repos_url":"https://api.github.com/users/burqen/repos","events_url":"https://api.github.com/users/burqen/events{/privacy}","received_events_url":"https://api.github.com/users/burqen/received_events","type":"User","site_admin":false},"body":"Then we will have to make this check in two places. Having it inside the method avoids the duplication.","created_at":"2016-07-14T12:13:48Z","updated_at":"2016-07-14T12:13:48Z","html_url":"https://github.com/neo4j/neo4j/pull/7545#discussion_r70794177","pull_request_url":"https://api.github.com/repos/neo4j/neo4j/pulls/7545","_links":{"self":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/comments/70794177"},"html":{"href":"https://github.com/neo4j/neo4j/pull/7545#discussion_r70794177"},"pull_request":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/7545"}}},"pull_request":{"url":"https://api.github.com/repos/neo4j/neo4j/pulls/7545","id":76909297,"html_url":"https://github.com/neo4j/neo4j/pull/7545","diff_url":"https://github.com/neo4j/neo4j/pull/7545.diff","patch_url":"https://github.com/neo4j/neo4j/pull/7545.patch","issue_url":"https://api.github.com/repos/neo4j/neo4j/issues/7545","number":7545,"state":"open","locked":false,"title":"Acquiring locks are deferred to commit time.","user":{"login":"burqen","id":5220077,"avatar_url":"https://avatars.githubusercontent.com/u/5220077?v=3","gravatar_id":"","url":"https://api.github.com/users/burqen","html_url":"https://github.com/burqen","followers_url":"https://api.github.com/users/burqen/followers","following_url":"https://api.github.com/users/burqen/following{/other_user}","gists_url":"https://api.github.com/users/burqen/gists{/gist_id}","starred_url":"https://api.github.com/users/burqen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burqen/subscriptions","organizations_url":"https://api.github.com/users/burqen/orgs","repos_url":"https://api.github.com/users/burqen/repos","events_url":"https://api.github.com/users/burqen/events{/privacy}","received_events_url":"https://api.github.com/users/burqen/received_events","type":"User","site_admin":false},"body":"Introducing setting _deferred_locking_, off by default.\r\n\r\nWe separate between implicit and explicit locking:\r\n\r\n**Implicit locking**\r\nAcquire locks triggered by some write or read event through the `Statement` cake.\r\nInstead of grabbing those locks we only remind what resources we want to lock and then acquire the them right before commit. \r\n\r\n**Explicit locking**\r\nLocks grabbed explicitly by the user or grabbed on master by a slave. Those locks are taken immediately. \r\n\r\n**Note**\r\nGrabbing locks just before commit guards for store inconsistencies but not logical inconsistencies. \r\n\r\n**Warning**\r\nThis feature should not be used. Most of all code in Neo4j is assumed to be executed under some sort of lock, exclusive or shared. This commit makes that assumption false and there has not been enough investigation to foresee what consequences that will have for transaction execution. These problems are still in the unknown but there are also known, purposely undocumented, problems.","created_at":"2016-07-11T07:21:42Z","updated_at":"2016-07-14T12:13:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de6c3de4709364970917e17549294fc2478adb8e","assignee":{"login":"MishaDemianenko","id":12656787,"avatar_url":"https://avatars.githubusercontent.com/u/12656787?v=3","gravatar_id":"","url":"https://api.github.com/users/MishaDemianenko","html_url":"https://github.com/MishaDemianenko","followers_url":"https://api.github.com/users/MishaDemianenko/followers","following_url":"https://api.github.com/users/MishaDemianenko/following{/other_user}","gists_url":"https://api.github.com/users/MishaDemianenko/gists{/gist_id}","starred_url":"https://api.github.com/users/MishaDemianenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MishaDemianenko/subscriptions","organizations_url":"https://api.github.com/users/MishaDemianenko/orgs","repos_url":"https://api.github.com/users/MishaDemianenko/repos","events_url":"https://api.github.com/users/MishaDemianenko/events{/privacy}","received_events_url":"https://api.github.com/users/MishaDemianenko/received_events","type":"User","site_admin":false},"assignees":[{"login":"MishaDemianenko","id":12656787,"avatar_url":"https://avatars.githubusercontent.com/u/12656787?v=3","gravatar_id":"","url":"https://api.github.com/users/MishaDemianenko","html_url":"https://github.com/MishaDemianenko","followers_url":"https://api.github.com/users/MishaDemianenko/followers","following_url":"https://api.github.com/users/MishaDemianenko/following{/other_user}","gists_url":"https://api.github.com/users/MishaDemianenko/gists{/gist_id}","starred_url":"https://api.github.com/users/MishaDemianenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MishaDemianenko/subscriptions","organizations_url":"https://api.github.com/users/MishaDemianenko/orgs","repos_url":"https://api.github.com/users/MishaDemianenko/repos","events_url":"https://api.github.com/users/MishaDemianenko/events{/privacy}","received_events_url":"https://api.github.com/users/MishaDemianenko/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/neo4j/neo4j/pulls/7545/commits","review_comments_url":"https://api.github.com/repos/neo4j/neo4j/pulls/7545/comments","review_comment_url":"https://api.github.com/repos/neo4j/neo4j/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neo4j/neo4j/issues/7545/comments","statuses_url":"https://api.github.com/repos/neo4j/neo4j/statuses/67cb577123cfa66fb8bc7931716c59231192297f","head":{"label":"burqen:2.3-deferring-locks-try-rebase","ref":"2.3-deferring-locks-try-rebase","sha":"67cb577123cfa66fb8bc7931716c59231192297f","user":{"login":"burqen","id":5220077,"avatar_url":"https://avatars.githubusercontent.com/u/5220077?v=3","gravatar_id":"","url":"https://api.github.com/users/burqen","html_url":"https://github.com/burqen","followers_url":"https://api.github.com/users/burqen/followers","following_url":"https://api.github.com/users/burqen/following{/other_user}","gists_url":"https://api.github.com/users/burqen/gists{/gist_id}","starred_url":"https://api.github.com/users/burqen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burqen/subscriptions","organizations_url":"https://api.github.com/users/burqen/orgs","repos_url":"https://api.github.com/users/burqen/repos","events_url":"https://api.github.com/users/burqen/events{/privacy}","received_events_url":"https://api.github.com/users/burqen/received_events","type":"User","site_admin":false},"repo":{"id":34265921,"name":"neo4j","full_name":"burqen/neo4j","owner":{"login":"burqen","id":5220077,"avatar_url":"https://avatars.githubusercontent.com/u/5220077?v=3","gravatar_id":"","url":"https://api.github.com/users/burqen","html_url":"https://github.com/burqen","followers_url":"https://api.github.com/users/burqen/followers","following_url":"https://api.github.com/users/burqen/following{/other_user}","gists_url":"https://api.github.com/users/burqen/gists{/gist_id}","starred_url":"https://api.github.com/users/burqen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/burqen/subscriptions","organizations_url":"https://api.github.com/users/burqen/orgs","repos_url":"https://api.github.com/users/burqen/repos","events_url":"https://api.github.com/users/burqen/events{/privacy}","received_events_url":"https://api.github.com/users/burqen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/burqen/neo4j","description":"Graphs for Everyone","fork":true,"url":"https://api.github.com/repos/burqen/neo4j","forks_url":"https://api.github.com/repos/burqen/neo4j/forks","keys_url":"https://api.github.com/repos/burqen/neo4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/burqen/neo4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/burqen/neo4j/teams","hooks_url":"https://api.github.com/repos/burqen/neo4j/hooks","issue_events_url":"https://api.github.com/repos/burqen/neo4j/issues/events{/number}","events_url":"https://api.github.com/repos/burqen/neo4j/events","assignees_url":"https://api.github.com/repos/burqen/neo4j/assignees{/user}","branches_url":"https://api.github.com/repos/burqen/neo4j/branches{/branch}","tags_url":"https://api.github.com/repos/burqen/neo4j/tags","blobs_url":"https://api.github.com/repos/burqen/neo4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/burqen/neo4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/burqen/neo4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/burqen/neo4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/burqen/neo4j/statuses/{sha}","languages_url":"https://api.github.com/repos/burqen/neo4j/languages","stargazers_url":"https://api.github.com/repos/burqen/neo4j/stargazers","contributors_url":"https://api.github.com/repos/burqen/neo4j/contributors","subscribers_url":"https://api.github.com/repos/burqen/neo4j/subscribers","subscription_url":"https://api.github.com/repos/burqen/neo4j/subscription","commits_url":"https://api.github.com/repos/burqen/neo4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/burqen/neo4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/burqen/neo4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/burqen/neo4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/burqen/neo4j/contents/{+path}","compare_url":"https://api.github.com/repos/burqen/neo4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/burqen/neo4j/merges","archive_url":"https://api.github.com/repos/burqen/neo4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/burqen/neo4j/downloads","issues_url":"https://api.github.com/repos/burqen/neo4j/issues{/number}","pulls_url":"https://api.github.com/repos/burqen/neo4j/pulls{/number}","milestones_url":"https://api.github.com/repos/burqen/neo4j/milestones{/number}","notifications_url":"https://api.github.com/repos/burqen/neo4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/burqen/neo4j/labels{/name}","releases_url":"https://api.github.com/repos/burqen/neo4j/releases{/id}","deployments_url":"https://api.github.com/repos/burqen/neo4j/deployments","created_at":"2015-04-20T14:38:51Z","updated_at":"2015-04-20T14:39:14Z","pushed_at":"2016-07-14T06:58:27Z","git_url":"git://github.com/burqen/neo4j.git","ssh_url":"git@github.com:burqen/neo4j.git","clone_url":"https://github.com/burqen/neo4j.git","svn_url":"https://github.com/burqen/neo4j","homepage":"http://neo4j.com","size":327508,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"2.3"}},"base":{"label":"neo4j:2.3","ref":"2.3","sha":"3a5ff58957e60f6c645491a44280576991239eb5","user":{"login":"neo4j","id":201120,"avatar_url":"https://avatars.githubusercontent.com/u/201120?v=3","gravatar_id":"","url":"https://api.github.com/users/neo4j","html_url":"https://github.com/neo4j","followers_url":"https://api.github.com/users/neo4j/followers","following_url":"https://api.github.com/users/neo4j/following{/other_user}","gists_url":"https://api.github.com/users/neo4j/gists{/gist_id}","starred_url":"https://api.github.com/users/neo4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neo4j/subscriptions","organizations_url":"https://api.github.com/users/neo4j/orgs","repos_url":"https://api.github.com/users/neo4j/repos","events_url":"https://api.github.com/users/neo4j/events{/privacy}","received_events_url":"https://api.github.com/users/neo4j/received_events","type":"Organization","site_admin":false},"repo":{"id":6650539,"name":"neo4j","full_name":"neo4j/neo4j","owner":{"login":"neo4j","id":201120,"avatar_url":"https://avatars.githubusercontent.com/u/201120?v=3","gravatar_id":"","url":"https://api.github.com/users/neo4j","html_url":"https://github.com/neo4j","followers_url":"https://api.github.com/users/neo4j/followers","following_url":"https://api.github.com/users/neo4j/following{/other_user}","gists_url":"https://api.github.com/users/neo4j/gists{/gist_id}","starred_url":"https://api.github.com/users/neo4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neo4j/subscriptions","organizations_url":"https://api.github.com/users/neo4j/orgs","repos_url":"https://api.github.com/users/neo4j/repos","events_url":"https://api.github.com/users/neo4j/events{/privacy}","received_events_url":"https://api.github.com/users/neo4j/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/neo4j/neo4j","description":"Graphs for Everyone","fork":false,"url":"https://api.github.com/repos/neo4j/neo4j","forks_url":"https://api.github.com/repos/neo4j/neo4j/forks","keys_url":"https://api.github.com/repos/neo4j/neo4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neo4j/neo4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neo4j/neo4j/teams","hooks_url":"https://api.github.com/repos/neo4j/neo4j/hooks","issue_events_url":"https://api.github.com/repos/neo4j/neo4j/issues/events{/number}","events_url":"https://api.github.com/repos/neo4j/neo4j/events","assignees_url":"https://api.github.com/repos/neo4j/neo4j/assignees{/user}","branches_url":"https://api.github.com/repos/neo4j/neo4j/branches{/branch}","tags_url":"https://api.github.com/repos/neo4j/neo4j/tags","blobs_url":"https://api.github.com/repos/neo4j/neo4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neo4j/neo4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neo4j/neo4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/neo4j/neo4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neo4j/neo4j/statuses/{sha}","languages_url":"https://api.github.com/repos/neo4j/neo4j/languages","stargazers_url":"https://api.github.com/repos/neo4j/neo4j/stargazers","contributors_url":"https://api.github.com/repos/neo4j/neo4j/contributors","subscribers_url":"https://api.github.com/repos/neo4j/neo4j/subscribers","subscription_url":"https://api.github.com/repos/neo4j/neo4j/subscription","commits_url":"https://api.github.com/repos/neo4j/neo4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/neo4j/neo4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/neo4j/neo4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/neo4j/neo4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/neo4j/neo4j/contents/{+path}","compare_url":"https://api.github.com/repos/neo4j/neo4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neo4j/neo4j/merges","archive_url":"https://api.github.com/repos/neo4j/neo4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neo4j/neo4j/downloads","issues_url":"https://api.github.com/repos/neo4j/neo4j/issues{/number}","pulls_url":"https://api.github.com/repos/neo4j/neo4j/pulls{/number}","milestones_url":"https://api.github.com/repos/neo4j/neo4j/milestones{/number}","notifications_url":"https://api.github.com/repos/neo4j/neo4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neo4j/neo4j/labels{/name}","releases_url":"https://api.github.com/repos/neo4j/neo4j/releases{/id}","deployments_url":"https://api.github.com/repos/neo4j/neo4j/deployments","created_at":"2012-11-12T08:46:15Z","updated_at":"2016-07-14T06:49:26Z","pushed_at":"2016-07-14T12:11:59Z","git_url":"git://github.com/neo4j/neo4j.git","ssh_url":"git@github.com:neo4j/neo4j.git","clone_url":"https://github.com/neo4j/neo4j.git","svn_url":"https://github.com/neo4j/neo4j","homepage":"http://neo4j.com","size":371884,"stargazers_count":2790,"watchers_count":2790,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":949,"mirror_url":null,"open_issues_count":378,"forks":949,"open_issues":378,"watchers":2790,"default_branch":"3.1"}},"_links":{"self":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/7545"},"html":{"href":"https://github.com/neo4j/neo4j/pull/7545"},"issue":{"href":"https://api.github.com/repos/neo4j/neo4j/issues/7545"},"comments":{"href":"https://api.github.com/repos/neo4j/neo4j/issues/7545/comments"},"review_comments":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/7545/comments"},"review_comment":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/7545/commits"},"statuses":{"href":"https://api.github.com/repos/neo4j/neo4j/statuses/67cb577123cfa66fb8bc7931716c59231192297f"}}}}
{"actor":{"display_login":"burqen"}}