{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/52245166","id":52245166,"diff_hunk":"@@ -291,14 +314,23 @@ private void putInternal(byte[] binaryKey, byte[] binaryValue) {\n     }\n \n     private Segment getSegment(long segmentId) {\n-        int index = (int) (segmentId % segments.length);\n+        if (segmentId > currentSegmentId - segments.length) {\n+            int index = (int) (segmentId % segments.length);\n \n-        if (segments[index] == null) {\n-            segments[index] = new Segment(name + \"-\" + directorySuffix(segmentId), segmentId);\n-            segments[index].openDB(context);\n-        }\n+            if (segments[index] != null && segments[index].id != segmentId) {\n+                cleanup();","path":"streams/src/main/java/org/apache/kafka/streams/state/internals/RocksDBWindowStore.java","position":117,"original_position":117,"commit_id":"a62e263b46b1828814d967f3ba214ec54ea5b25a","original_commit_id":"a62e263b46b1828814d967f3ba214ec54ea5b25a","user":{"login":"ewencp","id":47366,"avatar_url":"https://avatars.githubusercontent.com/u/47366?v=3","gravatar_id":"","url":"https://api.github.com/users/ewencp","html_url":"https://github.com/ewencp","followers_url":"https://api.github.com/users/ewencp/followers","following_url":"https://api.github.com/users/ewencp/following{/other_user}","gists_url":"https://api.github.com/users/ewencp/gists{/gist_id}","starred_url":"https://api.github.com/users/ewencp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewencp/subscriptions","organizations_url":"https://api.github.com/users/ewencp/orgs","repos_url":"https://api.github.com/users/ewencp/repos","events_url":"https://api.github.com/users/ewencp/events{/privacy}","received_events_url":"https://api.github.com/users/ewencp/received_events","type":"User","site_admin":false},"body":"Does this check & cleanup need to be here? Given that `cleanup()` is already invoked when you create new segments, when can this happen?","created_at":"2016-02-08T23:28:39Z","updated_at":"2016-02-08T23:28:39Z","html_url":"https://github.com/apache/kafka/pull/886#discussion_r52245166","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/886","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/52245166"},"html":{"href":"https://github.com/apache/kafka/pull/886#discussion_r52245166"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/886"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/886","id":58671139,"html_url":"https://github.com/apache/kafka/pull/886","diff_url":"https://github.com/apache/kafka/pull/886.diff","patch_url":"https://github.com/apache/kafka/pull/886.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/886","number":886,"state":"open","locked":false,"title":"HOTFIX: open window segments on init","user":{"login":"ymatsuda","id":169548,"avatar_url":"https://avatars.githubusercontent.com/u/169548?v=3","gravatar_id":"","url":"https://api.github.com/users/ymatsuda","html_url":"https://github.com/ymatsuda","followers_url":"https://api.github.com/users/ymatsuda/followers","following_url":"https://api.github.com/users/ymatsuda/following{/other_user}","gists_url":"https://api.github.com/users/ymatsuda/gists{/gist_id}","starred_url":"https://api.github.com/users/ymatsuda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymatsuda/subscriptions","organizations_url":"https://api.github.com/users/ymatsuda/orgs","repos_url":"https://api.github.com/users/ymatsuda/repos","events_url":"https://api.github.com/users/ymatsuda/events{/privacy}","received_events_url":"https://api.github.com/users/ymatsuda/received_events","type":"User","site_admin":false},"body":"@guozhangwang \r\n\r\nA window store should open all existing segments. This is important for segment cleanup, and it also ensures that the first fetch() call returns the hits, the values in the search range. (previously, it missed the hits in fetch() immediately after initialization).\r\n\r\n","created_at":"2016-02-08T21:40:45Z","updated_at":"2016-02-08T23:28:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b4b9f589e966a577033b8a77ae35159beb76973","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/886/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/886/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/886/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/a62e263b46b1828814d967f3ba214ec54ea5b25a","head":{"label":"ymatsuda:hotfix3","ref":"hotfix3","sha":"a62e263b46b1828814d967f3ba214ec54ea5b25a","user":{"login":"ymatsuda","id":169548,"avatar_url":"https://avatars.githubusercontent.com/u/169548?v=3","gravatar_id":"","url":"https://api.github.com/users/ymatsuda","html_url":"https://github.com/ymatsuda","followers_url":"https://api.github.com/users/ymatsuda/followers","following_url":"https://api.github.com/users/ymatsuda/following{/other_user}","gists_url":"https://api.github.com/users/ymatsuda/gists{/gist_id}","starred_url":"https://api.github.com/users/ymatsuda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymatsuda/subscriptions","organizations_url":"https://api.github.com/users/ymatsuda/orgs","repos_url":"https://api.github.com/users/ymatsuda/repos","events_url":"https://api.github.com/users/ymatsuda/events{/privacy}","received_events_url":"https://api.github.com/users/ymatsuda/received_events","type":"User","site_admin":false},"repo":{"id":30946235,"name":"kafka","full_name":"ymatsuda/kafka","owner":{"login":"ymatsuda","id":169548,"avatar_url":"https://avatars.githubusercontent.com/u/169548?v=3","gravatar_id":"","url":"https://api.github.com/users/ymatsuda","html_url":"https://github.com/ymatsuda","followers_url":"https://api.github.com/users/ymatsuda/followers","following_url":"https://api.github.com/users/ymatsuda/following{/other_user}","gists_url":"https://api.github.com/users/ymatsuda/gists{/gist_id}","starred_url":"https://api.github.com/users/ymatsuda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ymatsuda/subscriptions","organizations_url":"https://api.github.com/users/ymatsuda/orgs","repos_url":"https://api.github.com/users/ymatsuda/repos","events_url":"https://api.github.com/users/ymatsuda/events{/privacy}","received_events_url":"https://api.github.com/users/ymatsuda/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ymatsuda/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/ymatsuda/kafka","forks_url":"https://api.github.com/repos/ymatsuda/kafka/forks","keys_url":"https://api.github.com/repos/ymatsuda/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ymatsuda/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ymatsuda/kafka/teams","hooks_url":"https://api.github.com/repos/ymatsuda/kafka/hooks","issue_events_url":"https://api.github.com/repos/ymatsuda/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/ymatsuda/kafka/events","assignees_url":"https://api.github.com/repos/ymatsuda/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/ymatsuda/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/ymatsuda/kafka/tags","blobs_url":"https://api.github.com/repos/ymatsuda/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ymatsuda/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ymatsuda/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/ymatsuda/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ymatsuda/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/ymatsuda/kafka/languages","stargazers_url":"https://api.github.com/repos/ymatsuda/kafka/stargazers","contributors_url":"https://api.github.com/repos/ymatsuda/kafka/contributors","subscribers_url":"https://api.github.com/repos/ymatsuda/kafka/subscribers","subscription_url":"https://api.github.com/repos/ymatsuda/kafka/subscription","commits_url":"https://api.github.com/repos/ymatsuda/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/ymatsuda/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/ymatsuda/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/ymatsuda/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/ymatsuda/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/ymatsuda/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ymatsuda/kafka/merges","archive_url":"https://api.github.com/repos/ymatsuda/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ymatsuda/kafka/downloads","issues_url":"https://api.github.com/repos/ymatsuda/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/ymatsuda/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/ymatsuda/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/ymatsuda/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ymatsuda/kafka/labels{/name}","releases_url":"https://api.github.com/repos/ymatsuda/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/ymatsuda/kafka/deployments","created_at":"2015-02-18T00:56:44Z","updated_at":"2015-02-18T00:56:46Z","pushed_at":"2016-02-08T22:51:38Z","git_url":"git://github.com/ymatsuda/kafka.git","ssh_url":"git@github.com:ymatsuda/kafka.git","clone_url":"https://github.com/ymatsuda/kafka.git","svn_url":"https://github.com/ymatsuda/kafka","homepage":null,"size":27101,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":"0.8.2"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"d2fc6f36cc0b98d4d0acaa62ce3f2283c4e60581","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":2211243,"name":"kafka","full_name":"apache/kafka","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/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/apache/kafka/deployments","created_at":"2011-08-15T18:06:16Z","updated_at":"2016-02-08T13:26:04Z","pushed_at":"2016-02-08T22:52:27Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":34761,"stargazers_count":2610,"watchers_count":2610,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1556,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":125,"forks":1556,"open_issues":125,"watchers":2610,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/886"},"html":{"href":"https://github.com/apache/kafka/pull/886"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/886"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/886/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/886/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/886/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/a62e263b46b1828814d967f3ba214ec54ea5b25a"}}}}