{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/48383787","id":48383787,"diff_hunk":"@@ -31,39 +31,45 @@ class OffsetCheckpoint(val file: File) extends Logging {\n \n   def write(offsets: Map[TopicAndPartition, Long]) {\n     lock synchronized {\n-      // write to temp file and then swap with the existing file\n-      val temp = new File(file.getAbsolutePath + \".tmp\")\n-\n-      val fileOutputStream = new FileOutputStream(temp)\n-      val writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream))\n       try {\n-        // write the current version\n-        writer.write(0.toString)\n-        writer.newLine()\n-      \n-        // write the number of entries\n-        writer.write(offsets.size.toString)\n-        writer.newLine()\n+        // write to temp file and then swap with the existing file\n+        val temp = new File(file.getAbsolutePath + \".tmp\")\n+\n+        val fileOutputStream = new FileOutputStream(temp)\n+        val writer = new BufferedWriter(new OutputStreamWriter(fileOutputStream))\n+        try {\n+          // write the current version\n+          writer.write(0.toString)\n+          writer.newLine()\n \n-        // write the entries\n-        offsets.foreach { case (topicPart, offset) =>\n-          writer.write(\"%s %d %d\".format(topicPart.topic, topicPart.partition, offset))\n+          // write the number of entries\n+          writer.write(offsets.size.toString)\n           writer.newLine()\n+\n+          // write the entries\n+          offsets.foreach { case (topicPart, offset) =>\n+            writer.write(\"%s %d %d\".format(topicPart.topic, topicPart.partition, offset))\n+            writer.newLine()\n+          }\n+\n+          // flush the buffer and then fsync the underlying file\n+          writer.flush()\n+          fileOutputStream.getFD().sync()\n+        } finally {","path":"core/src/main/scala/kafka/server/OffsetCheckpoint.scala","position":43,"original_position":43,"commit_id":"4ba2186fbeeeef422395387254d3201f53bc6707","original_commit_id":"4ba2186fbeeeef422395387254d3201f53bc6707","user":{"login":"lindong28","id":5873403,"avatar_url":"https://avatars.githubusercontent.com/u/5873403?v=3","gravatar_id":"","url":"https://api.github.com/users/lindong28","html_url":"https://github.com/lindong28","followers_url":"https://api.github.com/users/lindong28/followers","following_url":"https://api.github.com/users/lindong28/following{/other_user}","gists_url":"https://api.github.com/users/lindong28/gists{/gist_id}","starred_url":"https://api.github.com/users/lindong28/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindong28/subscriptions","organizations_url":"https://api.github.com/users/lindong28/orgs","repos_url":"https://api.github.com/users/lindong28/repos","events_url":"https://api.github.com/users/lindong28/events{/privacy}","received_events_url":"https://api.github.com/users/lindong28/received_events","type":"User","site_admin":false},"body":"To address the issue explained in KAFKA-1860, would it be better to catch the FileNotFoundExeption here, instead of having an extra try/catch? I assume writer.write(0.toString) would throw the exception in the case you want to handle. It seems to be more fine grained than the existing approach.","created_at":"2015-12-23T22:19:50Z","updated_at":"2015-12-23T22:19:50Z","html_url":"https://github.com/apache/kafka/pull/698#discussion_r48383787","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/698","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/48383787"},"html":{"href":"https://github.com/apache/kafka/pull/698#discussion_r48383787"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/698"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/698","id":54161256,"html_url":"https://github.com/apache/kafka/pull/698","diff_url":"https://github.com/apache/kafka/pull/698.diff","patch_url":"https://github.com/apache/kafka/pull/698.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/698","number":698,"state":"open","locked":false,"title":"KAFKA-1860","user":{"login":"MayureshGharat","id":4326831,"avatar_url":"https://avatars.githubusercontent.com/u/4326831?v=3","gravatar_id":"","url":"https://api.github.com/users/MayureshGharat","html_url":"https://github.com/MayureshGharat","followers_url":"https://api.github.com/users/MayureshGharat/followers","following_url":"https://api.github.com/users/MayureshGharat/following{/other_user}","gists_url":"https://api.github.com/users/MayureshGharat/gists{/gist_id}","starred_url":"https://api.github.com/users/MayureshGharat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MayureshGharat/subscriptions","organizations_url":"https://api.github.com/users/MayureshGharat/orgs","repos_url":"https://api.github.com/users/MayureshGharat/repos","events_url":"https://api.github.com/users/MayureshGharat/events{/privacy}","received_events_url":"https://api.github.com/users/MayureshGharat/received_events","type":"User","site_admin":false},"body":"When the disk (raid with caches dir) dies on a Kafka broker, typically the filesystem gets mounted into read-only mode, and hence when Kafka tries to read the disk, they'll get a FileNotFoundException with the read-only errno set (EROFS). However, as long as there is no produce request received, hence no writes attempted on the disks, Kafka will not exit on such FATAL error and keep on throwing exception : java.io.FileNotFoundException\r\n\r\nIn this case, the JVM should stop if the underlying file system goes in to Read only mode. ","created_at":"2015-12-18T23:22:15Z","updated_at":"2015-12-23T22:19:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ea72a385dcd7934a6a0208de2a09953c3c07a08","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/698/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/698/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/698/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/4ba2186fbeeeef422395387254d3201f53bc6707","head":{"label":"MayureshGharat:KAFKA-1860","ref":"KAFKA-1860","sha":"4ba2186fbeeeef422395387254d3201f53bc6707","user":{"login":"MayureshGharat","id":4326831,"avatar_url":"https://avatars.githubusercontent.com/u/4326831?v=3","gravatar_id":"","url":"https://api.github.com/users/MayureshGharat","html_url":"https://github.com/MayureshGharat","followers_url":"https://api.github.com/users/MayureshGharat/followers","following_url":"https://api.github.com/users/MayureshGharat/following{/other_user}","gists_url":"https://api.github.com/users/MayureshGharat/gists{/gist_id}","starred_url":"https://api.github.com/users/MayureshGharat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MayureshGharat/subscriptions","organizations_url":"https://api.github.com/users/MayureshGharat/orgs","repos_url":"https://api.github.com/users/MayureshGharat/repos","events_url":"https://api.github.com/users/MayureshGharat/events{/privacy}","received_events_url":"https://api.github.com/users/MayureshGharat/received_events","type":"User","site_admin":false},"repo":{"id":43786685,"name":"kafka","full_name":"MayureshGharat/kafka","owner":{"login":"MayureshGharat","id":4326831,"avatar_url":"https://avatars.githubusercontent.com/u/4326831?v=3","gravatar_id":"","url":"https://api.github.com/users/MayureshGharat","html_url":"https://github.com/MayureshGharat","followers_url":"https://api.github.com/users/MayureshGharat/followers","following_url":"https://api.github.com/users/MayureshGharat/following{/other_user}","gists_url":"https://api.github.com/users/MayureshGharat/gists{/gist_id}","starred_url":"https://api.github.com/users/MayureshGharat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MayureshGharat/subscriptions","organizations_url":"https://api.github.com/users/MayureshGharat/orgs","repos_url":"https://api.github.com/users/MayureshGharat/repos","events_url":"https://api.github.com/users/MayureshGharat/events{/privacy}","received_events_url":"https://api.github.com/users/MayureshGharat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MayureshGharat/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/MayureshGharat/kafka","forks_url":"https://api.github.com/repos/MayureshGharat/kafka/forks","keys_url":"https://api.github.com/repos/MayureshGharat/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MayureshGharat/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MayureshGharat/kafka/teams","hooks_url":"https://api.github.com/repos/MayureshGharat/kafka/hooks","issue_events_url":"https://api.github.com/repos/MayureshGharat/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/MayureshGharat/kafka/events","assignees_url":"https://api.github.com/repos/MayureshGharat/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/MayureshGharat/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/MayureshGharat/kafka/tags","blobs_url":"https://api.github.com/repos/MayureshGharat/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MayureshGharat/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MayureshGharat/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/MayureshGharat/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MayureshGharat/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/MayureshGharat/kafka/languages","stargazers_url":"https://api.github.com/repos/MayureshGharat/kafka/stargazers","contributors_url":"https://api.github.com/repos/MayureshGharat/kafka/contributors","subscribers_url":"https://api.github.com/repos/MayureshGharat/kafka/subscribers","subscription_url":"https://api.github.com/repos/MayureshGharat/kafka/subscription","commits_url":"https://api.github.com/repos/MayureshGharat/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/MayureshGharat/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/MayureshGharat/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/MayureshGharat/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/MayureshGharat/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/MayureshGharat/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MayureshGharat/kafka/merges","archive_url":"https://api.github.com/repos/MayureshGharat/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MayureshGharat/kafka/downloads","issues_url":"https://api.github.com/repos/MayureshGharat/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/MayureshGharat/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/MayureshGharat/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/MayureshGharat/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MayureshGharat/kafka/labels{/name}","releases_url":"https://api.github.com/repos/MayureshGharat/kafka/releases{/id}","created_at":"2015-10-07T00:28:03Z","updated_at":"2015-10-15T21:35:18Z","pushed_at":"2015-12-22T19:07:56Z","git_url":"git://github.com/MayureshGharat/kafka.git","ssh_url":"git@github.com:MayureshGharat/kafka.git","clone_url":"https://github.com/MayureshGharat/kafka.git","svn_url":"https://github.com/MayureshGharat/kafka","homepage":null,"size":26135,"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":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"8c754c45af57a3249232268c6093cb4f50e1d45f","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}","created_at":"2011-08-15T18:06:16Z","updated_at":"2015-12-23T21:49:42Z","pushed_at":"2015-12-23T20:41:15Z","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":32875,"stargazers_count":2392,"watchers_count":2392,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1424,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":126,"forks":1424,"open_issues":126,"watchers":2392,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/698"},"html":{"href":"https://github.com/apache/kafka/pull/698"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/698"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/698/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/698/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/698/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/4ba2186fbeeeef422395387254d3201f53bc6707"}}}}