{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/67100460","id":67100460,"diff_hunk":"@@ -544,6 +586,71 @@ class Log(val dir: File,\n   }\n \n   /**\n+   * Get an offset based on the given timestamp\n+   * The offset returned is the offset of the first message whose timestamp is greater than or equals to the\n+   * given timestamp.\n+   *\n+   * If no such message is found, the log end offset is returned.\n+   *\n+   * `NOTE:` OffsetRequest V0 does not use this method, the behavior of OffsetRequest V0 remains the same as before\n+   * , i.e. it only gives back the timestamp based on the last modification time of the log segments.\n+   *\n+   * @param timestamp The given timestamp for offset fetching.\n+   * @return The offset of the first message whose timestamp is greater than or equals to the given timestamp.\n+   */\n+  def fetchOffsetsByTimestamp(timestamp: Long): Long = {\n+    debug(s\"Searching offset for timestamp $timestamp\")\n+    val segsArray = logSegments.toArray\n+    if (timestamp == OffsetRequest.EarliestTime)\n+      return segsArray(0).baseOffset\n+\n+    // set the target timestamp to be Long.MaxValue if we need to find from the latest.\n+    val targetTimestamp = timestamp match {\n+      case OffsetRequest.LatestTime => Long.MaxValue\n+      case _ => timestamp\n+    }\n+\n+    var foundOffset: Long = -1L\n+    // We have this while loop here to make sure we are returning the valid offsets to our best knowledge.\n+    // This while loop is to handle the case where the log is truncated during the timestamp search and we did not\n+    // find any message. In this case, we need to retry the search.\n+    do {\n+      val targetSeg = {\n+        // Get all the segments whose largest timestamp is smaller than target timestamp\n+        val earlierSegs = segsArray.takeWhile(_.largestTimestamp < targetTimestamp)\n+        // We need to search the first segment whose largest timestamp is greater than the target timestamp if there is one.\n+        if (earlierSegs.length < segsArray.length)\n+          segsArray(earlierSegs.length)\n+        else\n+          earlierSegs.last\n+      }\n+\n+      // First cache the current log end offset\n+      val leo = logEndOffset\n+      foundOffset = {\n+        // Use the cached log end offsets if\n+        // 1. user is asking for latest messages, or,\n+        // 2. we are searching on the active segment and the target timestamp is greater than the largestTimestamp\n+        // after we cached the log end offset. (We have to use the cached log end offsets because it is possible that\n+        // some messages with a larger timestamp are appended after we check the largest timestamp. Using log end offset\n+        // after the timestamp check might skip those messages.)\n+        if (targetTimestamp == Long.MaxValue\n+          || (targetTimestamp > targetSeg.largestTimestamp && targetSeg == activeSegment))\n+          leo\n+        else\n+        // The findOffsetByTimestamp() method may return None when the log is truncated during the timestamp search.\n+        // In that case we simply set the foundOffset to -1 so that we will search the timestaamp again in the","path":"core/src/main/scala/kafka/log/Log.scala","position":317,"original_position":317,"commit_id":"50edf086f796c5cf85a7a68cab369963fc8b610a","original_commit_id":"50edf086f796c5cf85a7a68cab369963fc8b610a","user":{"login":"junrao","id":132330,"avatar_url":"https://avatars.githubusercontent.com/u/132330?v=3","gravatar_id":"","url":"https://api.github.com/users/junrao","html_url":"https://github.com/junrao","followers_url":"https://api.github.com/users/junrao/followers","following_url":"https://api.github.com/users/junrao/following{/other_user}","gists_url":"https://api.github.com/users/junrao/gists{/gist_id}","starred_url":"https://api.github.com/users/junrao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junrao/subscriptions","organizations_url":"https://api.github.com/users/junrao/orgs","repos_url":"https://api.github.com/users/junrao/repos","events_url":"https://api.github.com/users/junrao/events{/privacy}","received_events_url":"https://api.github.com/users/junrao/received_events","type":"User","site_admin":false},"body":"typo timestaamp","created_at":"2016-06-15T05:07:43Z","updated_at":"2016-06-15T05:07:43Z","html_url":"https://github.com/apache/kafka/pull/1215#discussion_r67100460","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/1215","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/67100460"},"html":{"href":"https://github.com/apache/kafka/pull/1215#discussion_r67100460"},"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-15T05:07:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07962a4375497598d9fc09b4f47613d9f772149f","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/50edf086f796c5cf85a7a68cab369963fc8b610a","head":{"label":"becketqin:KAFKA-3163","ref":"KAFKA-3163","sha":"50edf086f796c5cf85a7a68cab369963fc8b610a","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-12T05:58:39Z","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":31759,"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":"eb6f04a8b12194b9e13e2a28d8ffdfa971516d68","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-15T04:17:32Z","pushed_at":"2016-06-15T04:28:26Z","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":43778,"stargazers_count":3248,"watchers_count":3248,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1995,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":195,"forks":1995,"open_issues":195,"watchers":3248,"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/50edf086f796c5cf85a7a68cab369963fc8b610a"}}}}
{"actor":{"display_login":"junrao"}}