{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/presto/pulls/comments/24914608","id":24914608,"diff_hunk":"@@ -0,0 +1,141 @@\n+/*\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.facebook.presto.raptor.storage;\n+\n+import com.facebook.presto.RowPagesBuilder;\n+import com.facebook.presto.metadata.InMemoryNodeManager;\n+import com.facebook.presto.raptor.metadata.DatabaseShardManager;\n+import com.facebook.presto.raptor.metadata.ShardManager;\n+import com.facebook.presto.spi.Page;\n+import com.facebook.presto.spi.PrestoException;\n+import com.facebook.presto.spi.type.Type;\n+import com.google.common.collect.ImmutableList;\n+import io.airlift.units.Duration;\n+import org.skife.jdbi.v2.DBI;\n+import org.skife.jdbi.v2.Handle;\n+import org.skife.jdbi.v2.IDBI;\n+import org.testng.annotations.AfterMethod;\n+import org.testng.annotations.BeforeMethod;\n+import org.testng.annotations.Test;\n+\n+import java.io.File;\n+import java.util.List;\n+import java.util.Optional;\n+import java.util.UUID;\n+import java.util.concurrent.TimeUnit;\n+\n+import static com.facebook.presto.spi.type.BigintType.BIGINT;\n+import static com.facebook.presto.spi.type.VarcharType.VARCHAR;\n+import static com.google.common.io.Files.createTempDir;\n+import static org.testng.Assert.assertFalse;\n+import static org.testng.Assert.assertTrue;\n+\n+public class TestShardRecovery\n+{\n+    private StorageService storageService;\n+    private ShardRecoveryManager recoveryManager;\n+    private Handle dummyHandle;\n+\n+    @BeforeMethod\n+    public void setup()\n+            throws Exception\n+    {\n+        File temporary = createTempDir();\n+        File directory = new File(temporary, \"data\");\n+        File backupDirectory = new File(temporary, \"backup\");\n+        storageService = new FileStorageService(directory, Optional.of(backupDirectory));\n+        storageService.start();\n+\n+        IDBI dbi = new DBI(\"jdbc:h2:mem:test\" + System.nanoTime());\n+        dummyHandle = dbi.open();\n+        ShardManager shardManager = new DatabaseShardManager(dbi);\n+        recoveryManager = new ShardRecoveryManager(storageService, new InMemoryNodeManager(), shardManager, new Duration(5, TimeUnit.MINUTES), 10);\n+    }\n+\n+    @AfterMethod\n+    public void tearDown()\n+            throws Exception\n+    {\n+        dummyHandle.close();\n+    }\n+\n+    @SuppressWarnings(\"EmptyTryBlock\")\n+    @Test\n+    public void testShardRecovery()\n+            throws Exception\n+    {\n+        List<Long> columnIds = ImmutableList.of(3L, 7L);\n+        List<Type> columnTypes = ImmutableList.<Type>of(BIGINT, VARCHAR);\n+\n+        UUID shardUuid = UUID.randomUUID();\n+        File file = storageService.getStorageFile(shardUuid);\n+        File backupFile = storageService.getBackupFile(shardUuid);\n+\n+        try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, backupFile)) {\n+            // create empty file in storage\n+        }\n+\n+        assertTrue(backupFile.exists());\n+        assertFalse(file.exists());\n+        recoveryManager.restoreFromBackup(shardUuid);\n+        assertTrue(backupFile.exists());\n+        assertTrue(file.exists());\n+        assertTrue(file.length() == backupFile.length());\n+    }\n+\n+    @SuppressWarnings(\"EmptyTryBlock\")\n+    @Test\n+    public void testShardRecoveryExistingFileMismatch()\n+            throws Exception\n+    {\n+        List<Long> columnIds = ImmutableList.of(3L, 7L);\n+        List<Type> columnTypes = ImmutableList.<Type>of(BIGINT, VARCHAR);\n+\n+        UUID shardUuid = UUID.randomUUID();\n+        File file = storageService.getStorageFile(shardUuid);\n+        File backupFile = storageService.getBackupFile(shardUuid);\n+\n+        try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, backupFile)) {\n+            List<Page> pages = RowPagesBuilder.rowPagesBuilder(columnTypes)\n+                    .row(123, \"hello\")\n+                    .row(456, \"bye\")\n+                    .build();\n+\n+            writer.appendPages(pages);\n+        }\n+\n+        try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) {\n+            // create empty file in storage\n+        }\n+\n+        assertTrue(backupFile.exists());","path":"presto-raptor/src/test/java/com/facebook/presto/raptor/storage/TestShardRecovery.java","position":122,"original_position":122,"commit_id":"4ec4079f9cab0366a658d04d3c2147cec81b90a3","original_commit_id":"4ec4079f9cab0366a658d04d3c2147cec81b90a3","user":{"login":"electrum","id":9230,"avatar_url":"https://avatars.githubusercontent.com/u/9230?v=3","gravatar_id":"","url":"https://api.github.com/users/electrum","html_url":"https://github.com/electrum","followers_url":"https://api.github.com/users/electrum/followers","following_url":"https://api.github.com/users/electrum/following{/other_user}","gists_url":"https://api.github.com/users/electrum/gists{/gist_id}","starred_url":"https://api.github.com/users/electrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrum/subscriptions","organizations_url":"https://api.github.com/users/electrum/orgs","repos_url":"https://api.github.com/users/electrum/repos","events_url":"https://api.github.com/users/electrum/events{/privacy}","received_events_url":"https://api.github.com/users/electrum/received_events","type":"User","site_admin":false},"body":"Extract a helper `assertRestoreFromBackup`","created_at":"2015-02-18T16:24:44Z","updated_at":"2015-02-18T16:24:44Z","html_url":"https://github.com/facebook/presto/pull/2297#discussion_r24914608","pull_request_url":"https://api.github.com/repos/facebook/presto/pulls/2297","_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments/24914608"},"html":{"href":"https://github.com/facebook/presto/pull/2297#discussion_r24914608"},"pull_request":{"href":"https://api.github.com/repos/facebook/presto/pulls/2297"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/presto/pulls/2297","id":28313525,"html_url":"https://github.com/facebook/presto/pull/2297","diff_url":"https://github.com/facebook/presto/pull/2297.diff","patch_url":"https://github.com/facebook/presto/pull/2297.patch","issue_url":"https://api.github.com/repos/facebook/presto/issues/2297","number":2297,"state":"open","locked":false,"title":"Add file size checks to shard recovery","user":{"login":"nileema","id":1034143,"avatar_url":"https://avatars.githubusercontent.com/u/1034143?v=3","gravatar_id":"","url":"https://api.github.com/users/nileema","html_url":"https://github.com/nileema","followers_url":"https://api.github.com/users/nileema/followers","following_url":"https://api.github.com/users/nileema/following{/other_user}","gists_url":"https://api.github.com/users/nileema/gists{/gist_id}","starred_url":"https://api.github.com/users/nileema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nileema/subscriptions","organizations_url":"https://api.github.com/users/nileema/orgs","repos_url":"https://api.github.com/users/nileema/repos","events_url":"https://api.github.com/users/nileema/events{/privacy}","received_events_url":"https://api.github.com/users/nileema/received_events","type":"User","site_admin":false},"body":"There were instances where the shard was recovered as a zero byte file.\r\nWe do not know the root cause of this, so add a check and classify the\r\nerror so that we can monitor future occurances of this behavior.\r\n\r\nAdd unit tests for shard recovery","created_at":"2015-01-29T20:51:46Z","updated_at":"2015-02-18T16:24:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5def43cb5785a482e068b9686409e9b73bd5243a","assignee":{"login":"electrum","id":9230,"avatar_url":"https://avatars.githubusercontent.com/u/9230?v=3","gravatar_id":"","url":"https://api.github.com/users/electrum","html_url":"https://github.com/electrum","followers_url":"https://api.github.com/users/electrum/followers","following_url":"https://api.github.com/users/electrum/following{/other_user}","gists_url":"https://api.github.com/users/electrum/gists{/gist_id}","starred_url":"https://api.github.com/users/electrum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrum/subscriptions","organizations_url":"https://api.github.com/users/electrum/orgs","repos_url":"https://api.github.com/users/electrum/repos","events_url":"https://api.github.com/users/electrum/events{/privacy}","received_events_url":"https://api.github.com/users/electrum/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/facebook/presto/pulls/2297/commits","review_comments_url":"https://api.github.com/repos/facebook/presto/pulls/2297/comments","review_comment_url":"https://api.github.com/repos/facebook/presto/pulls/comments/{number}","comments_url":"https://api.github.com/repos/facebook/presto/issues/2297/comments","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/4ec4079f9cab0366a658d04d3c2147cec81b90a3","head":{"label":"nileema:recovery","ref":"recovery","sha":"4ec4079f9cab0366a658d04d3c2147cec81b90a3","user":{"login":"nileema","id":1034143,"avatar_url":"https://avatars.githubusercontent.com/u/1034143?v=3","gravatar_id":"","url":"https://api.github.com/users/nileema","html_url":"https://github.com/nileema","followers_url":"https://api.github.com/users/nileema/followers","following_url":"https://api.github.com/users/nileema/following{/other_user}","gists_url":"https://api.github.com/users/nileema/gists{/gist_id}","starred_url":"https://api.github.com/users/nileema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nileema/subscriptions","organizations_url":"https://api.github.com/users/nileema/orgs","repos_url":"https://api.github.com/users/nileema/repos","events_url":"https://api.github.com/users/nileema/events{/privacy}","received_events_url":"https://api.github.com/users/nileema/received_events","type":"User","site_admin":false},"repo":{"id":12574341,"name":"presto","full_name":"nileema/presto","owner":{"login":"nileema","id":1034143,"avatar_url":"https://avatars.githubusercontent.com/u/1034143?v=3","gravatar_id":"","url":"https://api.github.com/users/nileema","html_url":"https://github.com/nileema","followers_url":"https://api.github.com/users/nileema/followers","following_url":"https://api.github.com/users/nileema/following{/other_user}","gists_url":"https://api.github.com/users/nileema/gists{/gist_id}","starred_url":"https://api.github.com/users/nileema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nileema/subscriptions","organizations_url":"https://api.github.com/users/nileema/orgs","repos_url":"https://api.github.com/users/nileema/repos","events_url":"https://api.github.com/users/nileema/events{/privacy}","received_events_url":"https://api.github.com/users/nileema/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nileema/presto","description":"","fork":true,"url":"https://api.github.com/repos/nileema/presto","forks_url":"https://api.github.com/repos/nileema/presto/forks","keys_url":"https://api.github.com/repos/nileema/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nileema/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nileema/presto/teams","hooks_url":"https://api.github.com/repos/nileema/presto/hooks","issue_events_url":"https://api.github.com/repos/nileema/presto/issues/events{/number}","events_url":"https://api.github.com/repos/nileema/presto/events","assignees_url":"https://api.github.com/repos/nileema/presto/assignees{/user}","branches_url":"https://api.github.com/repos/nileema/presto/branches{/branch}","tags_url":"https://api.github.com/repos/nileema/presto/tags","blobs_url":"https://api.github.com/repos/nileema/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nileema/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nileema/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/nileema/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nileema/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/nileema/presto/languages","stargazers_url":"https://api.github.com/repos/nileema/presto/stargazers","contributors_url":"https://api.github.com/repos/nileema/presto/contributors","subscribers_url":"https://api.github.com/repos/nileema/presto/subscribers","subscription_url":"https://api.github.com/repos/nileema/presto/subscription","commits_url":"https://api.github.com/repos/nileema/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/nileema/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/nileema/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/nileema/presto/issues/comments/{number}","contents_url":"https://api.github.com/repos/nileema/presto/contents/{+path}","compare_url":"https://api.github.com/repos/nileema/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nileema/presto/merges","archive_url":"https://api.github.com/repos/nileema/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nileema/presto/downloads","issues_url":"https://api.github.com/repos/nileema/presto/issues{/number}","pulls_url":"https://api.github.com/repos/nileema/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/nileema/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/nileema/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nileema/presto/labels{/name}","releases_url":"https://api.github.com/repos/nileema/presto/releases{/id}","created_at":"2013-09-03T20:40:19Z","updated_at":"2014-08-13T18:36:54Z","pushed_at":"2015-02-12T19:54:00Z","git_url":"git://github.com/nileema/presto.git","ssh_url":"git@github.com:nileema/presto.git","clone_url":"https://github.com/nileema/presto.git","svn_url":"https://github.com/nileema/presto","homepage":null,"size":34385,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"8a0b0269f880efe3a1640ed0ef62f392fe361b30","user":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":5349565,"name":"presto","full_name":"facebook/presto","owner":{"login":"facebook","id":69631,"avatar_url":"https://avatars.githubusercontent.com/u/69631?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/presto","description":"Distributed SQL query engine for running interactive analytic queries against big data sources.","fork":false,"url":"https://api.github.com/repos/facebook/presto","forks_url":"https://api.github.com/repos/facebook/presto/forks","keys_url":"https://api.github.com/repos/facebook/presto/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/presto/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/presto/teams","hooks_url":"https://api.github.com/repos/facebook/presto/hooks","issue_events_url":"https://api.github.com/repos/facebook/presto/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/presto/events","assignees_url":"https://api.github.com/repos/facebook/presto/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/presto/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/presto/tags","blobs_url":"https://api.github.com/repos/facebook/presto/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/presto/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/presto/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/presto/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/presto/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/presto/languages","stargazers_url":"https://api.github.com/repos/facebook/presto/stargazers","contributors_url":"https://api.github.com/repos/facebook/presto/contributors","subscribers_url":"https://api.github.com/repos/facebook/presto/subscribers","subscription_url":"https://api.github.com/repos/facebook/presto/subscription","commits_url":"https://api.github.com/repos/facebook/presto/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/presto/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/presto/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/presto/issues/comments/{number}","contents_url":"https://api.github.com/repos/facebook/presto/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/presto/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/presto/merges","archive_url":"https://api.github.com/repos/facebook/presto/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/presto/downloads","issues_url":"https://api.github.com/repos/facebook/presto/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/presto/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/presto/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/presto/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/presto/labels{/name}","releases_url":"https://api.github.com/repos/facebook/presto/releases{/id}","created_at":"2012-08-09T01:03:37Z","updated_at":"2015-02-17T15:17:49Z","pushed_at":"2015-02-17T01:05:10Z","git_url":"git://github.com/facebook/presto.git","ssh_url":"git@github.com:facebook/presto.git","clone_url":"https://github.com/facebook/presto.git","svn_url":"https://github.com/facebook/presto","homepage":"https://prestodb.io","size":69753,"stargazers_count":2984,"watchers_count":2984,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":665,"mirror_url":null,"open_issues_count":243,"forks":665,"open_issues":243,"watchers":2984,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/presto/pulls/2297"},"html":{"href":"https://github.com/facebook/presto/pull/2297"},"issue":{"href":"https://api.github.com/repos/facebook/presto/issues/2297"},"comments":{"href":"https://api.github.com/repos/facebook/presto/issues/2297/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/presto/pulls/2297/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/presto/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/facebook/presto/pulls/2297/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/presto/statuses/4ec4079f9cab0366a658d04d3c2147cec81b90a3"}}}}