{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/comments/38470942","id":38470942,"diff_hunk":"@@ -710,35 +727,70 @@ private Runnable getStorer(final byte[] data, final int readingOffset, final int\n         @Override\n         public void run()\n         {\n-          int i = storage.store(identifier, data, readingOffset, writingOffset);\n-          if (i == 0) {\n+          if (uniqueIdentifier == 0) {\n+            uniqueIdentifier = storage.store(identifier, data, readingOffset, writingOffset);\n+          }\n+          if (uniqueIdentifier == 0) {\n             logger.warn(\"Storage returned unexpectedly, please check the status of the spool directory!\");\n           }\n           else {\n             synchronized (Block.this) {\n-              Block.this.uniqueIdentifier = i;\n-              if (refCount == 0) {\n+              if (refCount.get() == 0) {\n+                //logger.debug(\"release block {} to disk\", Block.this);\n+                freeBuffers.offer(Block.this.data);\n                 Block.this.data = null;\n+                numberOfInMemBlockPermits++;\n+              } else {\n+                //logger.debug(\"Keeping Data List Memory Block {} due to {} references.\", Block.this, refCount);\n               }\n             }\n+            resumeSuspendedClients();\n           }\n         }\n-\n       };\n     }\n \n-    synchronized void release(boolean wait)\n+    protected void release(boolean wait)\n     {\n-      if (--refCount == 0 && storage != null) {\n-        if (uniqueIdentifier != 0) {\n-          data = null;\n-          return;\n+      if (refCount.decrementAndGet() == 0 && storage != null) {\n+        assert (Block.this.next != null);\n+        final Runnable storer = getStorer(data, readingOffset, writingOffset, storage);\n+        if (wait && numberOfInMemBlockPermits == 0) {\n+          //logger.info(\"Releasing Data List Memory Block {}\", this);\n+          storer.run();\n+        } else if (numberOfInMemBlockPermits < MAX_COUNT_OF_INMEM_BLOCKS/2) {\n+          //logger.info(\"Scheduling release of Data List Memory Block {}\", this);\n+          storageExecutor.submit(storer);\n         }\n-        if (wait) {\n-          getStorer(data, readingOffset, writingOffset, storage).run();\n+      } else {\n+        //logger.debug(\"Keeping Data List Memory Block {} due to {} references.\", this, refCount);\n+      }\n+    }\n+\n+    private Runnable getDiscarder()\n+    {\n+      return new Runnable()\n+      {\n+        @Override\n+        public void run()\n+        {\n+          if (uniqueIdentifier > 0) {\n+            logger.debug(\"discarding {} {}\", identifier, uniqueIdentifier);","path":"bufferserver/src/main/java/com/datatorrent/bufferserver/internal/DataList.java","position":620,"original_position":620,"commit_id":"755f2e25bc9d56c1e70a58ed1f91c03654b348c0","original_commit_id":"755f2e25bc9d56c1e70a58ed1f91c03654b348c0","user":{"login":"ilganeli","id":1483345,"avatar_url":"https://avatars.githubusercontent.com/u/1483345?v=3","gravatar_id":"","url":"https://api.github.com/users/ilganeli","html_url":"https://github.com/ilganeli","followers_url":"https://api.github.com/users/ilganeli/followers","following_url":"https://api.github.com/users/ilganeli/following{/other_user}","gists_url":"https://api.github.com/users/ilganeli/gists{/gist_id}","starred_url":"https://api.github.com/users/ilganeli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilganeli/subscriptions","organizations_url":"https://api.github.com/users/ilganeli/orgs","repos_url":"https://api.github.com/users/ilganeli/repos","events_url":"https://api.github.com/users/ilganeli/events{/privacy}","received_events_url":"https://api.github.com/users/ilganeli/received_events","type":"User","site_admin":false},"body":"Nit: 'Discarding'","created_at":"2015-09-01T20:55:32Z","updated_at":"2015-09-01T20:55:32Z","html_url":"https://github.com/apache/incubator-apex-core/pull/12#discussion_r38470942","pull_request_url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/comments/38470942"},"html":{"href":"https://github.com/apache/incubator-apex-core/pull/12#discussion_r38470942"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12","id":43780713,"html_url":"https://github.com/apache/incubator-apex-core/pull/12","diff_url":"https://github.com/apache/incubator-apex-core/pull/12.diff","patch_url":"https://github.com/apache/incubator-apex-core/pull/12.patch","issue_url":"https://api.github.com/repos/apache/incubator-apex-core/issues/12","number":12,"state":"open","locked":false,"title":"Buffer server should use a separate thread to spool blocks to disk - for review","user":{"login":"vrozov","id":12200381,"avatar_url":"https://avatars.githubusercontent.com/u/12200381?v=3","gravatar_id":"","url":"https://api.github.com/users/vrozov","html_url":"https://github.com/vrozov","followers_url":"https://api.github.com/users/vrozov/followers","following_url":"https://api.github.com/users/vrozov/following{/other_user}","gists_url":"https://api.github.com/users/vrozov/gists{/gist_id}","starred_url":"https://api.github.com/users/vrozov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vrozov/subscriptions","organizations_url":"https://api.github.com/users/vrozov/orgs","repos_url":"https://api.github.com/users/vrozov/repos","events_url":"https://api.github.com/users/vrozov/events{/privacy}","received_events_url":"https://api.github.com/users/vrozov/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-31T16:10:44Z","updated_at":"2015-09-01T20:55:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"065c3587d203a74c5e0875bd6d7a16e7043b9bc3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-apex-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-apex-core/issues/12/comments","statuses_url":"https://api.github.com/repos/apache/incubator-apex-core/statuses/755f2e25bc9d56c1e70a58ed1f91c03654b348c0","head":{"label":"vrozov:SPOI-5823","ref":"SPOI-5823","sha":"755f2e25bc9d56c1e70a58ed1f91c03654b348c0","user":{"login":"vrozov","id":12200381,"avatar_url":"https://avatars.githubusercontent.com/u/12200381?v=3","gravatar_id":"","url":"https://api.github.com/users/vrozov","html_url":"https://github.com/vrozov","followers_url":"https://api.github.com/users/vrozov/followers","following_url":"https://api.github.com/users/vrozov/following{/other_user}","gists_url":"https://api.github.com/users/vrozov/gists{/gist_id}","starred_url":"https://api.github.com/users/vrozov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vrozov/subscriptions","organizations_url":"https://api.github.com/users/vrozov/orgs","repos_url":"https://api.github.com/users/vrozov/repos","events_url":"https://api.github.com/users/vrozov/events{/privacy}","received_events_url":"https://api.github.com/users/vrozov/received_events","type":"User","site_admin":false},"repo":{"id":41398902,"name":"incubator-apex-core","full_name":"vrozov/incubator-apex-core","owner":{"login":"vrozov","id":12200381,"avatar_url":"https://avatars.githubusercontent.com/u/12200381?v=3","gravatar_id":"","url":"https://api.github.com/users/vrozov","html_url":"https://github.com/vrozov","followers_url":"https://api.github.com/users/vrozov/followers","following_url":"https://api.github.com/users/vrozov/following{/other_user}","gists_url":"https://api.github.com/users/vrozov/gists{/gist_id}","starred_url":"https://api.github.com/users/vrozov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vrozov/subscriptions","organizations_url":"https://api.github.com/users/vrozov/orgs","repos_url":"https://api.github.com/users/vrozov/repos","events_url":"https://api.github.com/users/vrozov/events{/privacy}","received_events_url":"https://api.github.com/users/vrozov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vrozov/incubator-apex-core","description":"Mirror of Apache Apex core (Incubating)","fork":true,"url":"https://api.github.com/repos/vrozov/incubator-apex-core","forks_url":"https://api.github.com/repos/vrozov/incubator-apex-core/forks","keys_url":"https://api.github.com/repos/vrozov/incubator-apex-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vrozov/incubator-apex-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vrozov/incubator-apex-core/teams","hooks_url":"https://api.github.com/repos/vrozov/incubator-apex-core/hooks","issue_events_url":"https://api.github.com/repos/vrozov/incubator-apex-core/issues/events{/number}","events_url":"https://api.github.com/repos/vrozov/incubator-apex-core/events","assignees_url":"https://api.github.com/repos/vrozov/incubator-apex-core/assignees{/user}","branches_url":"https://api.github.com/repos/vrozov/incubator-apex-core/branches{/branch}","tags_url":"https://api.github.com/repos/vrozov/incubator-apex-core/tags","blobs_url":"https://api.github.com/repos/vrozov/incubator-apex-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vrozov/incubator-apex-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vrozov/incubator-apex-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/vrozov/incubator-apex-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vrozov/incubator-apex-core/statuses/{sha}","languages_url":"https://api.github.com/repos/vrozov/incubator-apex-core/languages","stargazers_url":"https://api.github.com/repos/vrozov/incubator-apex-core/stargazers","contributors_url":"https://api.github.com/repos/vrozov/incubator-apex-core/contributors","subscribers_url":"https://api.github.com/repos/vrozov/incubator-apex-core/subscribers","subscription_url":"https://api.github.com/repos/vrozov/incubator-apex-core/subscription","commits_url":"https://api.github.com/repos/vrozov/incubator-apex-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/vrozov/incubator-apex-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/vrozov/incubator-apex-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/vrozov/incubator-apex-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/vrozov/incubator-apex-core/contents/{+path}","compare_url":"https://api.github.com/repos/vrozov/incubator-apex-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vrozov/incubator-apex-core/merges","archive_url":"https://api.github.com/repos/vrozov/incubator-apex-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vrozov/incubator-apex-core/downloads","issues_url":"https://api.github.com/repos/vrozov/incubator-apex-core/issues{/number}","pulls_url":"https://api.github.com/repos/vrozov/incubator-apex-core/pulls{/number}","milestones_url":"https://api.github.com/repos/vrozov/incubator-apex-core/milestones{/number}","notifications_url":"https://api.github.com/repos/vrozov/incubator-apex-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vrozov/incubator-apex-core/labels{/name}","releases_url":"https://api.github.com/repos/vrozov/incubator-apex-core/releases{/id}","created_at":"2015-08-26T02:09:41Z","updated_at":"2015-08-26T02:09:43Z","pushed_at":"2015-09-01T14:26:43Z","git_url":"git://github.com/vrozov/incubator-apex-core.git","ssh_url":"git@github.com:vrozov/incubator-apex-core.git","clone_url":"https://github.com/vrozov/incubator-apex-core.git","svn_url":"https://github.com/vrozov/incubator-apex-core","homepage":null,"size":14916,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:devel-3","ref":"devel-3","sha":"d748ed46fb2ef91d74a70c2be52dc4a56bb4df71","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":41348333,"name":"incubator-apex-core","full_name":"apache/incubator-apex-core","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-apex-core","description":"Mirror of Apache Apex core (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-apex-core","forks_url":"https://api.github.com/repos/apache/incubator-apex-core/forks","keys_url":"https://api.github.com/repos/apache/incubator-apex-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-apex-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-apex-core/teams","hooks_url":"https://api.github.com/repos/apache/incubator-apex-core/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-apex-core/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-apex-core/events","assignees_url":"https://api.github.com/repos/apache/incubator-apex-core/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-apex-core/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-apex-core/tags","blobs_url":"https://api.github.com/repos/apache/incubator-apex-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-apex-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-apex-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-apex-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-apex-core/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-apex-core/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-apex-core/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-apex-core/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-apex-core/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-apex-core/subscription","commits_url":"https://api.github.com/repos/apache/incubator-apex-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-apex-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-apex-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-apex-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-apex-core/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-apex-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-apex-core/merges","archive_url":"https://api.github.com/repos/apache/incubator-apex-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-apex-core/downloads","issues_url":"https://api.github.com/repos/apache/incubator-apex-core/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-apex-core/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-apex-core/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-apex-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-apex-core/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-apex-core/releases{/id}","created_at":"2015-08-25T07:00:05Z","updated_at":"2015-08-26T23:58:34Z","pushed_at":"2015-09-01T15:37:38Z","git_url":"git://github.com/apache/incubator-apex-core.git","ssh_url":"git@github.com:apache/incubator-apex-core.git","clone_url":"https://github.com/apache/incubator-apex-core.git","svn_url":"https://github.com/apache/incubator-apex-core","homepage":null,"size":14916,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":16,"mirror_url":"git://git.apache.org/incubator-apex-core.git","open_issues_count":4,"forks":16,"open_issues":4,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12"},"html":{"href":"https://github.com/apache/incubator-apex-core/pull/12"},"issue":{"href":"https://api.github.com/repos/apache/incubator-apex-core/issues/12"},"comments":{"href":"https://api.github.com/repos/apache/incubator-apex-core/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-apex-core/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-apex-core/statuses/755f2e25bc9d56c1e70a58ed1f91c03654b348c0"}}}}