{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/47496037","id":47496037,"diff_hunk":"@@ -1279,4 +1283,108 @@ public void run() {\n             }\n         }\n     }\n+\n+    public void testFailFlush() throws IOException {\n+        Path tempDir = createTempDir();\n+        final AtomicBoolean failWrite = new AtomicBoolean();\n+        final AtomicBoolean simulateDiskFull = new AtomicBoolean();\n+        TranslogConfig config = getTranslogConfig(tempDir);\n+        Translog translog = new Translog(config) {\n+            @Override\n+            TranslogWriter.ChannelFactory getChannelFactory() {\n+                final TranslogWriter.ChannelFactory factory = super.getChannelFactory();\n+\n+                return new TranslogWriter.ChannelFactory() {\n+                    @Override\n+                    public FileChannel open(Path file) throws IOException {\n+                        FileChannel channel = factory.open(file);\n+                        return new FilterFileChannel(channel) {\n+\n+                            @Override\n+                            public int write(ByteBuffer src) throws IOException {\n+                                if (failWrite.get()) {\n+                                    throw new IOException(\"boom\");\n+                                }\n+                                if (simulateDiskFull.get()) {\n+                                    if (src.limit() > 1) {\n+                                        final int pos = src.position();\n+                                        final int limit = src.limit();\n+                                        src.limit(limit / 2);\n+                                        super.write(src);\n+                                        src.position(pos);\n+                                        src.limit(limit);\n+                                        throw new IOException(\"no space left on device\");\n+                                    }\n+                                }\n+                                return super.write(src);\n+                            }\n+                        };\n+                    }\n+                };\n+            }\n+        };\n+\n+        List<Translog.Location> locations = new ArrayList<>();\n+        int opsSynced = 0;\n+        int opsAdded = 0;\n+        boolean failed = false;\n+        boolean syncFailed = true;\n+        while(failed == false) {\n+            try {\n+                locations.add(translog.add(new Translog.Index(\"test\", \"\" + opsSynced, Integer.toString(opsSynced).getBytes(Charset.forName(\"UTF-8\")))));\n+                opsAdded++;\n+                translog.sync();\n+                opsSynced++;\n+            } catch (IOException ex) {\n+                failed = true;\n+                assertEquals(\"no space left on device\", ex.getMessage());\n+            } catch (Exception ex) {\n+                failed = true;\n+                assertTrue(ex.toString(), ex.getMessage().startsWith(\"Failed to write operation\"));\n+             }\n+            simulateDiskFull.set(randomBoolean());\n+        }\n+        simulateDiskFull.set(false);\n+        if (randomBoolean()) {\n+            try {\n+                locations.add(translog.add(new Translog.Index(\"test\", \"\" + opsSynced, Integer.toString(opsSynced).getBytes(Charset.forName(\"UTF-8\")))));\n+                opsSynced++;","path":"core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java","position":97,"original_position":97,"commit_id":"2d03a6b8085cefeaeb8bf11aba2ac18c6992296d","original_commit_id":"2d03a6b8085cefeaeb8bf11aba2ac18c6992296d","user":{"login":"bleskes","id":1006375,"avatar_url":"https://avatars.githubusercontent.com/u/1006375?v=3","gravatar_id":"","url":"https://api.github.com/users/bleskes","html_url":"https://github.com/bleskes","followers_url":"https://api.github.com/users/bleskes/followers","following_url":"https://api.github.com/users/bleskes/following{/other_user}","gists_url":"https://api.github.com/users/bleskes/gists{/gist_id}","starred_url":"https://api.github.com/users/bleskes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bleskes/subscriptions","organizations_url":"https://api.github.com/users/bleskes/orgs","repos_url":"https://api.github.com/users/bleskes/repos","events_url":"https://api.github.com/users/bleskes/events{/privacy}","received_events_url":"https://api.github.com/users/bleskes/received_events","type":"User","site_admin":false},"body":"we shouldn't be here, right? knowing that we failed before, we should have a tragic exception in the queue? feels like I miss something.","created_at":"2015-12-14T13:21:54Z","updated_at":"2015-12-14T13:21:54Z","html_url":"https://github.com/elastic/elasticsearch/pull/15420#discussion_r47496037","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/47496037"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/15420#discussion_r47496037"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420","id":53557750,"html_url":"https://github.com/elastic/elasticsearch/pull/15420","diff_url":"https://github.com/elastic/elasticsearch/pull/15420.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/15420.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15420","number":15420,"state":"open","locked":false,"title":"Fail and close translog hard if writing to disk fails","user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"body":"Today we are super lenient (how could I missed that for f**k sake) with failing\r\n/ closing the translog writer when we hit an exception. It's actually worse, we allow\r\nto further write to it and don't care what has been already written to disk and what hasn't.\r\nWe keep the buffer in memory and try to write it again on the next operation.\r\n\r\nWhen we hit a disk-full expcetion due to for instance a big merge we are likely adding document to the\r\ntranslog but fail to write them to disk. Once the merge failed and freed up it's diskspace (note this is\r\na small window when concurrently indexing and failing the shard due to out of space exceptions) we will\r\nallow in-flight operations to add to the translog and then once we fail the shard fsync it. These operations\r\nare written to disk and fsynced which is fine but the previous buffer flush might have written some bytes\r\nto disk which are not corrupting the translog. That wouldn't be an issue if we prevented the fsync.\r\n\r\nCloses #15333","created_at":"2015-12-14T12:21:47Z","updated_at":"2015-12-14T13:21:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3fe0b1633f43d86b9ee7131633f5bbd15a06e4a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15420/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/2d03a6b8085cefeaeb8bf11aba2ac18c6992296d","head":{"label":"s1monw:fail_translog_on_tragic_event","ref":"fail_translog_on_tragic_event","sha":"2d03a6b8085cefeaeb8bf11aba2ac18c6992296d","user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"repo":{"id":4663744,"name":"elasticsearch","full_name":"s1monw/elasticsearch","owner":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/s1monw/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/s1monw/elasticsearch","forks_url":"https://api.github.com/repos/s1monw/elasticsearch/forks","keys_url":"https://api.github.com/repos/s1monw/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/s1monw/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/s1monw/elasticsearch/teams","hooks_url":"https://api.github.com/repos/s1monw/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/s1monw/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/s1monw/elasticsearch/events","assignees_url":"https://api.github.com/repos/s1monw/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/s1monw/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/s1monw/elasticsearch/tags","blobs_url":"https://api.github.com/repos/s1monw/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/s1monw/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/s1monw/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/s1monw/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/s1monw/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/s1monw/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/s1monw/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/s1monw/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/s1monw/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/s1monw/elasticsearch/subscription","commits_url":"https://api.github.com/repos/s1monw/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/s1monw/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/s1monw/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/s1monw/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/s1monw/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/s1monw/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/s1monw/elasticsearch/merges","archive_url":"https://api.github.com/repos/s1monw/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/s1monw/elasticsearch/downloads","issues_url":"https://api.github.com/repos/s1monw/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/s1monw/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/s1monw/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/s1monw/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/s1monw/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/s1monw/elasticsearch/releases{/id}","created_at":"2012-06-14T13:44:13Z","updated_at":"2015-05-07T08:25:29Z","pushed_at":"2015-12-14T12:16:34Z","git_url":"git://github.com/s1monw/elasticsearch.git","ssh_url":"git@github.com:s1monw/elasticsearch.git","clone_url":"https://github.com/s1monw/elasticsearch.git","svn_url":"https://github.com/s1monw/elasticsearch","homepage":"http://elasticsearch.org","size":183488,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"f520f8bfb97f8bbb9fa6205045facf1c12123cb3","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-12-14T10:36:25Z","pushed_at":"2015-12-14T13:19:33Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":228362,"stargazers_count":13988,"watchers_count":13988,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4648,"mirror_url":null,"open_issues_count":1204,"forks":4648,"open_issues":1204,"watchers":13988,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/15420"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/15420"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/15420/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/15420/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/2d03a6b8085cefeaeb8bf11aba2ac18c6992296d"}}}}