{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/66302572","id":66302572,"diff_hunk":"@@ -270,27 +327,91 @@ class LogSegment(val log: FileMessageSet,\n     catch {\n       case e: IOException => throw kafkaStorageException(\"index\", e)\n     }\n+    try timeIndex.renameTo(new File(CoreUtils.replaceSuffix(timeIndex.file.getPath, oldSuffix, newSuffix)))\n+    catch {\n+      case e: IOException => throw kafkaStorageException(\"timeindex\", e)\n+    }\n+  }\n+\n+  /**\n+   * Append the last time index entry to the time index when this log segment become inactive segment.\n+   * This entry will be used to decide when to delete the segment.\n+   */\n+  def onBecomeInactiveSegment() {\n+    if (maxTimestampSoFar >= 0)\n+      timeIndex.maybeAppend(maxTimestampSoFar, offsetOfMaxTimestamp, skipFullCheck = true)\n+    else\n+      timeIndex.maybeAppend(lastModified, nextOffset() - 1, skipFullCheck = true)\n+  }\n+\n+  /**\n+   * The time this segment has waited to be rolled over. If the segment does not contain any message with a timestamp,\n+   * the time is based on the create time of the segment. Otherwise the time is based on the max timestamp in this\n+   * segment.\n+   */\n+  def timeWaitedForRoll(now: Long) = now - { if (maxTimestampSoFar >= 0) maxTimestampSoFar else created}\n+\n+  /**\n+   * Search the message offset based on timestamp.\n+   * This method returns a TimestampOffset. The offset is the offset of the first message whose timestamp is\n+   * greater than or equals to the target timestamp.\n+   *\n+   * If all the message in the segment have smaller timestamps, the offset will be last offset + 1 and the\n+   * timestamp will be max timestamp in the segment.","path":"core/src/main/scala/kafka/log/LogSegment.scala","position":229,"original_position":229,"commit_id":"da3b39ed789f5eee0679767de1ab9a0660e6eb7b","original_commit_id":"da3b39ed789f5eee0679767de1ab9a0660e6eb7b","user":{"login":"becketqin","id":5778611,"avatar_url":"https://avatars.githubusercontent.com/u/5778611?v=3","gravatar_id":"","url":"https://api.github.com/users/becketqin","html_url":"https://github.com/becketqin","followers_url":"https://api.github.com/users/becketqin/followers","following_url":"https://api.github.com/users/becketqin/following{/other_user}","gists_url":"https://api.github.com/users/becketqin/gists{/gist_id}","starred_url":"https://api.github.com/users/becketqin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becketqin/subscriptions","organizations_url":"https://api.github.com/users/becketqin/orgs","repos_url":"https://api.github.com/users/becketqin/repos","events_url":"https://api.github.com/users/becketqin/events{/privacy}","received_events_url":"https://api.github.com/users/becketqin/received_events","type":"User","site_admin":false},"body":"I think we do return the offset of the first message if none of the messages has timestmap.","created_at":"2016-06-08T17:39:05Z","updated_at":"2016-06-08T17:39:05Z","html_url":"https://github.com/apache/kafka/pull/1215#discussion_r66302572","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/1215","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/66302572"},"html":{"href":"https://github.com/apache/kafka/pull/1215#discussion_r66302572"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/1215"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/1215","id":66076425,"html_url":"https://github.com/apache/kafka/pull/1215","diff_url":"https://github.com/apache/kafka/pull/1215.diff","patch_url":"https://github.com/apache/kafka/pull/1215.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/1215","number":1215,"state":"open","locked":false,"title":"KAFKA-3163: Add time based index to Kafka.","user":{"login":"becketqin","id":5778611,"avatar_url":"https://avatars.githubusercontent.com/u/5778611?v=3","gravatar_id":"","url":"https://api.github.com/users/becketqin","html_url":"https://github.com/becketqin","followers_url":"https://api.github.com/users/becketqin/followers","following_url":"https://api.github.com/users/becketqin/following{/other_user}","gists_url":"https://api.github.com/users/becketqin/gists{/gist_id}","starred_url":"https://api.github.com/users/becketqin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becketqin/subscriptions","organizations_url":"https://api.github.com/users/becketqin/orgs","repos_url":"https://api.github.com/users/becketqin/repos","events_url":"https://api.github.com/users/becketqin/events{/privacy}","received_events_url":"https://api.github.com/users/becketqin/received_events","type":"User","site_admin":false},"body":"This patch is for KIP-33.\r\nhttps://cwiki.apache.org/confluence/display/KAFKA/KIP-33+-+Add+a+time+based+log+index\r\n","created_at":"2016-04-11T22:59:35Z","updated_at":"2016-06-08T17:39:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e067368509e895000220642febb2ab62129eb939","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/1215/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/1215/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/1215/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/da3b39ed789f5eee0679767de1ab9a0660e6eb7b","head":{"label":"becketqin:KAFKA-3163","ref":"KAFKA-3163","sha":"da3b39ed789f5eee0679767de1ab9a0660e6eb7b","user":{"login":"becketqin","id":5778611,"avatar_url":"https://avatars.githubusercontent.com/u/5778611?v=3","gravatar_id":"","url":"https://api.github.com/users/becketqin","html_url":"https://github.com/becketqin","followers_url":"https://api.github.com/users/becketqin/followers","following_url":"https://api.github.com/users/becketqin/following{/other_user}","gists_url":"https://api.github.com/users/becketqin/gists{/gist_id}","starred_url":"https://api.github.com/users/becketqin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becketqin/subscriptions","organizations_url":"https://api.github.com/users/becketqin/orgs","repos_url":"https://api.github.com/users/becketqin/repos","events_url":"https://api.github.com/users/becketqin/events{/privacy}","received_events_url":"https://api.github.com/users/becketqin/received_events","type":"User","site_admin":false},"repo":{"id":21048134,"name":"kafka","full_name":"becketqin/kafka","owner":{"login":"becketqin","id":5778611,"avatar_url":"https://avatars.githubusercontent.com/u/5778611?v=3","gravatar_id":"","url":"https://api.github.com/users/becketqin","html_url":"https://github.com/becketqin","followers_url":"https://api.github.com/users/becketqin/followers","following_url":"https://api.github.com/users/becketqin/following{/other_user}","gists_url":"https://api.github.com/users/becketqin/gists{/gist_id}","starred_url":"https://api.github.com/users/becketqin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/becketqin/subscriptions","organizations_url":"https://api.github.com/users/becketqin/orgs","repos_url":"https://api.github.com/users/becketqin/repos","events_url":"https://api.github.com/users/becketqin/events{/privacy}","received_events_url":"https://api.github.com/users/becketqin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/becketqin/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/becketqin/kafka","forks_url":"https://api.github.com/repos/becketqin/kafka/forks","keys_url":"https://api.github.com/repos/becketqin/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/becketqin/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/becketqin/kafka/teams","hooks_url":"https://api.github.com/repos/becketqin/kafka/hooks","issue_events_url":"https://api.github.com/repos/becketqin/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/becketqin/kafka/events","assignees_url":"https://api.github.com/repos/becketqin/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/becketqin/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/becketqin/kafka/tags","blobs_url":"https://api.github.com/repos/becketqin/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/becketqin/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/becketqin/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/becketqin/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/becketqin/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/becketqin/kafka/languages","stargazers_url":"https://api.github.com/repos/becketqin/kafka/stargazers","contributors_url":"https://api.github.com/repos/becketqin/kafka/contributors","subscribers_url":"https://api.github.com/repos/becketqin/kafka/subscribers","subscription_url":"https://api.github.com/repos/becketqin/kafka/subscription","commits_url":"https://api.github.com/repos/becketqin/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/becketqin/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/becketqin/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/becketqin/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/becketqin/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/becketqin/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/becketqin/kafka/merges","archive_url":"https://api.github.com/repos/becketqin/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/becketqin/kafka/downloads","issues_url":"https://api.github.com/repos/becketqin/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/becketqin/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/becketqin/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/becketqin/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/becketqin/kafka/labels{/name}","releases_url":"https://api.github.com/repos/becketqin/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/becketqin/kafka/deployments","created_at":"2014-06-20T18:28:55Z","updated_at":"2014-06-20T18:28:55Z","pushed_at":"2016-06-05T06:24:19Z","git_url":"git://github.com/becketqin/kafka.git","ssh_url":"git@github.com:becketqin/kafka.git","clone_url":"https://github.com/becketqin/kafka.git","svn_url":"https://github.com/becketqin/kafka","homepage":null,"size":31467,"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.1"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"404b696bea58aca17fbe528aed03cb3c94516c39","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-06-08T15:32:11Z","pushed_at":"2016-06-08T16:34:09Z","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":43391,"stargazers_count":3217,"watchers_count":3217,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1975,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":180,"forks":1975,"open_issues":180,"watchers":3217,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/1215"},"html":{"href":"https://github.com/apache/kafka/pull/1215"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/1215"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/1215/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/1215/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/1215/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/da3b39ed789f5eee0679767de1ab9a0660e6eb7b"}}}}
{"actor":{"display_login":"becketqin"}}