{"action":"created","comment":{"url":"https://api.github.com/repos/basho/leveldb/pulls/comments/77458149","id":77458149,"diff_hunk":"@@ -0,0 +1,654 @@\n+// -------------------------------------------------------------------\n+//\n+// hot_backup.cc\n+//\n+// Copyright (c) 2011-2016 Basho Technologies, Inc. All Rights Reserved.\n+//\n+// This file is provided to you under the Apache License,\n+// Version 2.0 (the \"License\"); you may not use this file\n+// except in compliance with the License.  You may obtain\n+// 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,\n+// software distributed under the License is distributed on an\n+// \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+// KIND, either express or implied.  See the License for the\n+// specific language governing permissions and limitations\n+// under the License.\n+//\n+// -------------------------------------------------------------------\n+\n+#include <unistd.h>\n+\n+#include \"leveldb/atomics.h\"\n+#include \"leveldb/env.h\"\n+\n+#include \"db/dbformat.h\"\n+#include \"db/db_impl.h\"\n+#include \"db/filename.h\"\n+#include \"util/db_list.h\"\n+#include \"util/hot_backup.h\"\n+#include \"util/hot_threads.h\"\n+\n+namespace leveldb {\n+\n+\n+// this local static is used during normal operations.  unit tests\n+//  create independent object.\n+static HotBackup LocalHotBackupObj;\n+HotBackup * gHotBackup(&LocalHotBackupObj);\n+void HotBackup::ResetHotBackupObject() {gHotBackup=&LocalHotBackupObj;};\n+\n+\n+/**\n+ * Called by throttle.cc's thread once a minute.  Used to\n+ *  test for trigger condition\n+ */\n+void\n+CheckHotBackupTrigger()\n+{\n+    // add_and_fetch for memory fences\n+    if (0 == gHotBackup->GetJobsPending())\n+    {\n+        if (gHotBackup->IsTriggerSet())\n+        {\n+            // two instance counts held for \"trigger management\"\n+            //  (protects against hot backups happening as fast as\n+            //   ScanDB() makes calls ... causing trigger to reset too\n+            //   early)\n+            gHotBackup->HotBackupScheduled();\n+            gHotBackup->HotBackupScheduled();\n+\n+            // Log() routes to syslog as an error\n+            Log(NULL, \"leveldb HotBackup triggered.\");\n+            gPerfCounters->Inc(ePerfBackupStarted);\n+\n+            DBList()->ScanDBs(true,  &DBImpl::HotBackup);\n+            DBList()->ScanDBs(false, &DBImpl::HotBackup);\n+\n+            // reduce to one instance count now that events posted\n+            //  (trigger reset now enabled)\n+            gHotBackup->HotBackupFinished();\n+        }   // if\n+    }   // if\n+\n+    return;\n+\n+}   // CheckHotBackupTrigger\n+\n+\n+/**\n+ * Look for external trigger\n+ */\n+bool\n+HotBackup::IsTriggerSet()\n+{\n+    bool ret_flag;\n+    int ret_val;\n+\n+    //\n+    // This is code polls for existance of /etc/riak/hot_backup\n+    //\n+    ret_val=access(GetTriggerPath(), F_OK);\n+    ret_flag=(-1!=ret_val);\n+\n+    return(ret_flag);\n+\n+}   // HotBackup::IsTriggerSet\n+\n+\n+/**\n+ * Let external trigger know that hot backup is complete.  Put\n+ *  message to syslog if unable to delete trigger file\n+ */\n+void\n+HotBackup::ResetTrigger()\n+{\n+    bool ret_flag;\n+    int ret_val;\n+\n+    ret_val=unlink(GetTriggerPath());\n+    if (0==ret_val)\n+    {\n+        // release last counter, enabling future backups\n+        HotBackupFinished();\n+    }   // if\n+    else\n+    {\n+        // one count left, effectively disabling trigger forever (or next program restart)\n+        Log(NULL, \"leveldb HotBackup unable to delete trigger file %s\", GetTriggerPath());\n+        Log(NULL, \"leveldb HotBackup now disabled until program restart\");\n+    }   // if\n+\n+    return;\n+\n+}   // ResetHotBackupTrigger\n+\n+\n+/**\n+ * A database instance marks its intent to backup\n+ */\n+void\n+HotBackup::HotBackupScheduled()\n+{\n+    inc_and_fetch(&m_JobsPending);\n+\n+    return;\n+\n+}   // HotBackupScheduled\n+\n+\n+/**\n+ * A database instance marks that its backup completed\n+ */\n+void\n+HotBackup::HotBackupFinished()\n+{\n+    int ret_val;\n+\n+    ret_val=dec_and_fetch(&m_JobsPending);\n+\n+    // 1 means CheckHotBackupTrigger()'s counter is only\n+    //   one left\n+    if (1==ret_val)\n+    {\n+        // hmm, call file sync() at this point?\n+        Log(NULL, \"leveldb HotBackup complete.\");\n+        ResetTrigger();\n+    }   // if\n+\n+    return;\n+\n+}   // HotBackupFinished\n+\n+\n+/**\n+ * Routine called by DBList()->ScanDBs.  This has full context of one open\n+ *  leveldb database.  Validates then schedules a backup job via compaction\n+ *  threads.\n+ */\n+void\n+DBImpl::HotBackup()\n+{\n+    bool create_backup_event(false);\n+\n+    // hold mutex while reviewing database state\n+    //  (note:  never good to call Log() while holding mutex\n+    //   but these are unlikely error cases)\n+    {\n+        // get mutex,\n+        MutexLock l(&mutex_);\n+\n+        // set backup flag && see if\n+        assert(false==hotbackup_pending_);","path":"util/hot_backup.cc","position":185,"original_position":185,"commit_id":"9b58e117f4249df583516a6ca3539826525b4b93","original_commit_id":"9b58e117f4249df583516a6ca3539826525b4b93","user":{"login":"matthewvon","id":225681,"avatar_url":"https://avatars.githubusercontent.com/u/225681?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewvon","html_url":"https://github.com/matthewvon","followers_url":"https://api.github.com/users/matthewvon/followers","following_url":"https://api.github.com/users/matthewvon/following{/other_user}","gists_url":"https://api.github.com/users/matthewvon/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewvon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewvon/subscriptions","organizations_url":"https://api.github.com/users/matthewvon/orgs","repos_url":"https://api.github.com/users/matthewvon/repos","events_url":"https://api.github.com/users/matthewvon/events{/privacy}","received_events_url":"https://api.github.com/users/matthewvon/received_events","type":"User","site_admin":false},"body":"Decided to review an eleveldb build log before making an incorrect statement:\r\n\r\nmac-mini.bos1 osx10.8\tcc -g -O2 -DERTS_FRMPTR -Wall -O3 -fPIC -I /Users/buildbot/matthewv/eleveldb/c_src/system/include -I. -I./\r\ninclude -fno-builtin-memcmp -DOS_MACOSX -DLEVELDB_PLATFORM_POSIX  -DLEVELDB_VSN=\"2.0.27\" -O2 -g -DNDEBUG     -fPIC -MM -E -MT util\r\n/bloom2.d -MT util/bloom2.o -MF util/bloom2.d util/bloom2.cc\r\n\r\nThe parameter \"-DNDEBUG\" is what disables asserts.  It is active in the eleveldb initiated builds.  My previous statement is therefore correct (and verified).","created_at":"2016-09-04T20:33:38Z","updated_at":"2016-09-04T20:33:38Z","html_url":"https://github.com/basho/leveldb/pull/202#discussion_r77458149","pull_request_url":"https://api.github.com/repos/basho/leveldb/pulls/202","_links":{"self":{"href":"https://api.github.com/repos/basho/leveldb/pulls/comments/77458149"},"html":{"href":"https://github.com/basho/leveldb/pull/202#discussion_r77458149"},"pull_request":{"href":"https://api.github.com/repos/basho/leveldb/pulls/202"}}},"pull_request":{"url":"https://api.github.com/repos/basho/leveldb/pulls/202","id":79965069,"html_url":"https://github.com/basho/leveldb/pull/202","diff_url":"https://github.com/basho/leveldb/pull/202.diff","patch_url":"https://github.com/basho/leveldb/pull/202.patch","issue_url":"https://api.github.com/repos/basho/leveldb/issues/202","number":202,"state":"open","locked":false,"title":"Mv hot backup [JIRA: RIAK-2784]","user":{"login":"matthewvon","id":225681,"avatar_url":"https://avatars.githubusercontent.com/u/225681?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewvon","html_url":"https://github.com/matthewvon","followers_url":"https://api.github.com/users/matthewvon/followers","following_url":"https://api.github.com/users/matthewvon/following{/other_user}","gists_url":"https://api.github.com/users/matthewvon/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewvon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewvon/subscriptions","organizations_url":"https://api.github.com/users/matthewvon/orgs","repos_url":"https://api.github.com/users/matthewvon/repos","events_url":"https://api.github.com/users/matthewvon/events{/privacy}","received_events_url":"https://api.github.com/users/matthewvon/received_events","type":"User","site_admin":false},"body":"Hot Backup allows an external trigger file, /etc/riak/hot_backup, to cause all open leveldb databases on a server to create a backup image, live.  The leveldb process does not the user to stop or pause data operations.  Hot backup will maintain up to five backup snapshots in a rolling fashion if the user does not wish to copy and erase after each backup.\r\n\r\nEach backup snapshot is \"ready to run\".  Previous Basho and 3rd party solutions required a database \"repair\" or similar lengthy process to guarantee state before using their backup.\r\n\r\nUsage and code details are here:  https://github.com/basho/leveldb/wiki/mv-hot-backup","created_at":"2016-08-03T19:34:35Z","updated_at":"2016-09-04T20:33:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2d2b031fca3737164b4d5e908174ab7fdc442fce","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/basho/leveldb/pulls/202/commits","review_comments_url":"https://api.github.com/repos/basho/leveldb/pulls/202/comments","review_comment_url":"https://api.github.com/repos/basho/leveldb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/basho/leveldb/issues/202/comments","statuses_url":"https://api.github.com/repos/basho/leveldb/statuses/9b58e117f4249df583516a6ca3539826525b4b93","head":{"label":"basho:mv-hot-backup","ref":"mv-hot-backup","sha":"9b58e117f4249df583516a6ca3539826525b4b93","user":{"login":"basho","id":176293,"avatar_url":"https://avatars.githubusercontent.com/u/176293?v=3","gravatar_id":"","url":"https://api.github.com/users/basho","html_url":"https://github.com/basho","followers_url":"https://api.github.com/users/basho/followers","following_url":"https://api.github.com/users/basho/following{/other_user}","gists_url":"https://api.github.com/users/basho/gists{/gist_id}","starred_url":"https://api.github.com/users/basho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basho/subscriptions","organizations_url":"https://api.github.com/users/basho/orgs","repos_url":"https://api.github.com/users/basho/repos","events_url":"https://api.github.com/users/basho/events{/privacy}","received_events_url":"https://api.github.com/users/basho/received_events","type":"Organization","site_admin":false},"repo":{"id":3280270,"name":"leveldb","full_name":"basho/leveldb","owner":{"login":"basho","id":176293,"avatar_url":"https://avatars.githubusercontent.com/u/176293?v=3","gravatar_id":"","url":"https://api.github.com/users/basho","html_url":"https://github.com/basho","followers_url":"https://api.github.com/users/basho/followers","following_url":"https://api.github.com/users/basho/following{/other_user}","gists_url":"https://api.github.com/users/basho/gists{/gist_id}","starred_url":"https://api.github.com/users/basho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basho/subscriptions","organizations_url":"https://api.github.com/users/basho/orgs","repos_url":"https://api.github.com/users/basho/repos","events_url":"https://api.github.com/users/basho/events{/privacy}","received_events_url":"https://api.github.com/users/basho/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/basho/leveldb","description":"Clone of http://code.google.com/p/leveldb/","fork":false,"url":"https://api.github.com/repos/basho/leveldb","forks_url":"https://api.github.com/repos/basho/leveldb/forks","keys_url":"https://api.github.com/repos/basho/leveldb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/basho/leveldb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/basho/leveldb/teams","hooks_url":"https://api.github.com/repos/basho/leveldb/hooks","issue_events_url":"https://api.github.com/repos/basho/leveldb/issues/events{/number}","events_url":"https://api.github.com/repos/basho/leveldb/events","assignees_url":"https://api.github.com/repos/basho/leveldb/assignees{/user}","branches_url":"https://api.github.com/repos/basho/leveldb/branches{/branch}","tags_url":"https://api.github.com/repos/basho/leveldb/tags","blobs_url":"https://api.github.com/repos/basho/leveldb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/basho/leveldb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/basho/leveldb/git/refs{/sha}","trees_url":"https://api.github.com/repos/basho/leveldb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/basho/leveldb/statuses/{sha}","languages_url":"https://api.github.com/repos/basho/leveldb/languages","stargazers_url":"https://api.github.com/repos/basho/leveldb/stargazers","contributors_url":"https://api.github.com/repos/basho/leveldb/contributors","subscribers_url":"https://api.github.com/repos/basho/leveldb/subscribers","subscription_url":"https://api.github.com/repos/basho/leveldb/subscription","commits_url":"https://api.github.com/repos/basho/leveldb/commits{/sha}","git_commits_url":"https://api.github.com/repos/basho/leveldb/git/commits{/sha}","comments_url":"https://api.github.com/repos/basho/leveldb/comments{/number}","issue_comment_url":"https://api.github.com/repos/basho/leveldb/issues/comments{/number}","contents_url":"https://api.github.com/repos/basho/leveldb/contents/{+path}","compare_url":"https://api.github.com/repos/basho/leveldb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/basho/leveldb/merges","archive_url":"https://api.github.com/repos/basho/leveldb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/basho/leveldb/downloads","issues_url":"https://api.github.com/repos/basho/leveldb/issues{/number}","pulls_url":"https://api.github.com/repos/basho/leveldb/pulls{/number}","milestones_url":"https://api.github.com/repos/basho/leveldb/milestones{/number}","notifications_url":"https://api.github.com/repos/basho/leveldb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/basho/leveldb/labels{/name}","releases_url":"https://api.github.com/repos/basho/leveldb/releases{/id}","deployments_url":"https://api.github.com/repos/basho/leveldb/deployments","created_at":"2012-01-27T04:49:26Z","updated_at":"2016-09-01T11:00:52Z","pushed_at":"2016-08-23T01:04:18Z","git_url":"git://github.com/basho/leveldb.git","ssh_url":"git@github.com:basho/leveldb.git","clone_url":"https://github.com/basho/leveldb.git","svn_url":"https://github.com/basho/leveldb","homepage":"","size":5851,"stargazers_count":391,"watchers_count":391,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":22,"forks":156,"open_issues":22,"watchers":391,"default_branch":"develop"}},"base":{"label":"basho:develop","ref":"develop","sha":"04a60dbaba2d25bcf94e45f6c5f24f43d8ef733a","user":{"login":"basho","id":176293,"avatar_url":"https://avatars.githubusercontent.com/u/176293?v=3","gravatar_id":"","url":"https://api.github.com/users/basho","html_url":"https://github.com/basho","followers_url":"https://api.github.com/users/basho/followers","following_url":"https://api.github.com/users/basho/following{/other_user}","gists_url":"https://api.github.com/users/basho/gists{/gist_id}","starred_url":"https://api.github.com/users/basho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basho/subscriptions","organizations_url":"https://api.github.com/users/basho/orgs","repos_url":"https://api.github.com/users/basho/repos","events_url":"https://api.github.com/users/basho/events{/privacy}","received_events_url":"https://api.github.com/users/basho/received_events","type":"Organization","site_admin":false},"repo":{"id":3280270,"name":"leveldb","full_name":"basho/leveldb","owner":{"login":"basho","id":176293,"avatar_url":"https://avatars.githubusercontent.com/u/176293?v=3","gravatar_id":"","url":"https://api.github.com/users/basho","html_url":"https://github.com/basho","followers_url":"https://api.github.com/users/basho/followers","following_url":"https://api.github.com/users/basho/following{/other_user}","gists_url":"https://api.github.com/users/basho/gists{/gist_id}","starred_url":"https://api.github.com/users/basho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basho/subscriptions","organizations_url":"https://api.github.com/users/basho/orgs","repos_url":"https://api.github.com/users/basho/repos","events_url":"https://api.github.com/users/basho/events{/privacy}","received_events_url":"https://api.github.com/users/basho/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/basho/leveldb","description":"Clone of http://code.google.com/p/leveldb/","fork":false,"url":"https://api.github.com/repos/basho/leveldb","forks_url":"https://api.github.com/repos/basho/leveldb/forks","keys_url":"https://api.github.com/repos/basho/leveldb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/basho/leveldb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/basho/leveldb/teams","hooks_url":"https://api.github.com/repos/basho/leveldb/hooks","issue_events_url":"https://api.github.com/repos/basho/leveldb/issues/events{/number}","events_url":"https://api.github.com/repos/basho/leveldb/events","assignees_url":"https://api.github.com/repos/basho/leveldb/assignees{/user}","branches_url":"https://api.github.com/repos/basho/leveldb/branches{/branch}","tags_url":"https://api.github.com/repos/basho/leveldb/tags","blobs_url":"https://api.github.com/repos/basho/leveldb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/basho/leveldb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/basho/leveldb/git/refs{/sha}","trees_url":"https://api.github.com/repos/basho/leveldb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/basho/leveldb/statuses/{sha}","languages_url":"https://api.github.com/repos/basho/leveldb/languages","stargazers_url":"https://api.github.com/repos/basho/leveldb/stargazers","contributors_url":"https://api.github.com/repos/basho/leveldb/contributors","subscribers_url":"https://api.github.com/repos/basho/leveldb/subscribers","subscription_url":"https://api.github.com/repos/basho/leveldb/subscription","commits_url":"https://api.github.com/repos/basho/leveldb/commits{/sha}","git_commits_url":"https://api.github.com/repos/basho/leveldb/git/commits{/sha}","comments_url":"https://api.github.com/repos/basho/leveldb/comments{/number}","issue_comment_url":"https://api.github.com/repos/basho/leveldb/issues/comments{/number}","contents_url":"https://api.github.com/repos/basho/leveldb/contents/{+path}","compare_url":"https://api.github.com/repos/basho/leveldb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/basho/leveldb/merges","archive_url":"https://api.github.com/repos/basho/leveldb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/basho/leveldb/downloads","issues_url":"https://api.github.com/repos/basho/leveldb/issues{/number}","pulls_url":"https://api.github.com/repos/basho/leveldb/pulls{/number}","milestones_url":"https://api.github.com/repos/basho/leveldb/milestones{/number}","notifications_url":"https://api.github.com/repos/basho/leveldb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/basho/leveldb/labels{/name}","releases_url":"https://api.github.com/repos/basho/leveldb/releases{/id}","deployments_url":"https://api.github.com/repos/basho/leveldb/deployments","created_at":"2012-01-27T04:49:26Z","updated_at":"2016-09-01T11:00:52Z","pushed_at":"2016-08-23T01:04:18Z","git_url":"git://github.com/basho/leveldb.git","ssh_url":"git@github.com:basho/leveldb.git","clone_url":"https://github.com/basho/leveldb.git","svn_url":"https://github.com/basho/leveldb","homepage":"","size":5851,"stargazers_count":391,"watchers_count":391,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":156,"mirror_url":null,"open_issues_count":22,"forks":156,"open_issues":22,"watchers":391,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/basho/leveldb/pulls/202"},"html":{"href":"https://github.com/basho/leveldb/pull/202"},"issue":{"href":"https://api.github.com/repos/basho/leveldb/issues/202"},"comments":{"href":"https://api.github.com/repos/basho/leveldb/issues/202/comments"},"review_comments":{"href":"https://api.github.com/repos/basho/leveldb/pulls/202/comments"},"review_comment":{"href":"https://api.github.com/repos/basho/leveldb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/basho/leveldb/pulls/202/commits"},"statuses":{"href":"https://api.github.com/repos/basho/leveldb/statuses/9b58e117f4249df583516a6ca3539826525b4b93"}}}}
{"actor":{"display_login":"matthewvon"}}