{"action":"created","comment":{"url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/comments/45639858","id":45639858,"diff_hunk":"@@ -156,8 +170,29 @@ func (h *handler) invoke(method handlerMethod) error {\n \t\tif err != nil {\n \t\t\treturn err\n \t\t}\n+\n+\t\t//If the Database is currently online process as normal\n+\t\tdbState := atomic.LoadUint32(&dbContext.State)\n+\t\tif (dbState == db.DBOnline) {\n+\t\t\t//Take a readlock for any method that does not run offline, taking a DB offline will\n+\t\t\t//block until all normal calls have returned and released their read locks.\n+\t\t\tif (!h.runOffline) {\n+\t\t\t\t//get a read lock on the dbContext\n+\t\t\t\tdbContext.AccessLock.RLock()\n+\n+\t\t\t\t//defer releasing the dbContext until after the handler method returns\n+\t\t\t\tdefer dbContext.AccessLock.RUnlock()\n+\t\t\t}\n+\t\t} else if (dbState == db.DBOffline) { //DB is offline\n+\t\t\tif (!h.runOffline) { //only handlers with runOffline true can run if DB is in Offline state\n+\t\t\t\treturn base.HTTPErrorf(http.StatusServiceUnavailable, \"DB is currently under maintenance\")\n+\t\t\t}\n+\t\t} else { //DB is in transition state, no calls will be accepted until it is Online or Offline state\n+\t\t\treturn base.HTTPErrorf(http.StatusServiceUnavailable, \"DB is currently in neither online or offline state, try again later\")","path":"src/github.com/couchbase/sync_gateway/rest/handler.go","position":67,"original_position":67,"commit_id":"bf965b4cd2715bf9bd02bdd8970ef0068b1507ab","original_commit_id":"bf965b4cd2715bf9bd02bdd8970ef0068b1507ab","user":{"login":"adamcfraser","id":8866453,"avatar_url":"https://avatars.githubusercontent.com/u/8866453?v=3","gravatar_id":"","url":"https://api.github.com/users/adamcfraser","html_url":"https://github.com/adamcfraser","followers_url":"https://api.github.com/users/adamcfraser/followers","following_url":"https://api.github.com/users/adamcfraser/following{/other_user}","gists_url":"https://api.github.com/users/adamcfraser/gists{/gist_id}","starred_url":"https://api.github.com/users/adamcfraser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamcfraser/subscriptions","organizations_url":"https://api.github.com/users/adamcfraser/orgs","repos_url":"https://api.github.com/users/adamcfraser/repos","events_url":"https://api.github.com/users/adamcfraser/events{/privacy}","received_events_url":"https://api.github.com/users/adamcfraser/received_events","type":"User","site_admin":false},"body":"This error message sounds a bit too Alice in Wonderland - maybe just say \"Database is not online - try again later\"?","created_at":"2015-11-23T18:25:53Z","updated_at":"2015-11-23T18:25:53Z","html_url":"https://github.com/couchbase/sync_gateway/pull/1295#discussion_r45639858","pull_request_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295","_links":{"self":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/comments/45639858"},"html":{"href":"https://github.com/couchbase/sync_gateway/pull/1295#discussion_r45639858"},"pull_request":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295"}}},"pull_request":{"url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295","id":50840364,"html_url":"https://github.com/couchbase/sync_gateway/pull/1295","diff_url":"https://github.com/couchbase/sync_gateway/pull/1295.diff","patch_url":"https://github.com/couchbase/sync_gateway/pull/1295.patch","issue_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/1295","number":1295,"state":"open","locked":false,"title":"Clean merge of DB online/offline changes against latest master","user":{"login":"ajres","id":7745210,"avatar_url":"https://avatars.githubusercontent.com/u/7745210?v=3","gravatar_id":"","url":"https://api.github.com/users/ajres","html_url":"https://github.com/ajres","followers_url":"https://api.github.com/users/ajres/followers","following_url":"https://api.github.com/users/ajres/following{/other_user}","gists_url":"https://api.github.com/users/ajres/gists{/gist_id}","starred_url":"https://api.github.com/users/ajres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajres/subscriptions","organizations_url":"https://api.github.com/users/ajres/orgs","repos_url":"https://api.github.com/users/ajres/repos","events_url":"https://api.github.com/users/ajres/events{/privacy}","received_events_url":"https://api.github.com/users/ajres/received_events","type":"User","site_admin":false},"body":"A clean merge of the changes for DB online/offline with latest master\r\nScope covers\r\n\r\nfixes #908\r\nfixes #909\r\nfixes #910\r\nfixes #911\r\nfixes #912\r\nfixes #1012\r\nfixes #1013\r\n \r\n\r\nAnd bring DB online after specified delay in seconds","created_at":"2015-11-16T17:30:54Z","updated_at":"2015-11-23T18:25:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30e1784eb73e5aaa40d36d12d037b5e7b3d7be30","assignee":{"login":"adamcfraser","id":8866453,"avatar_url":"https://avatars.githubusercontent.com/u/8866453?v=3","gravatar_id":"","url":"https://api.github.com/users/adamcfraser","html_url":"https://github.com/adamcfraser","followers_url":"https://api.github.com/users/adamcfraser/followers","following_url":"https://api.github.com/users/adamcfraser/following{/other_user}","gists_url":"https://api.github.com/users/adamcfraser/gists{/gist_id}","starred_url":"https://api.github.com/users/adamcfraser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamcfraser/subscriptions","organizations_url":"https://api.github.com/users/adamcfraser/orgs","repos_url":"https://api.github.com/users/adamcfraser/repos","events_url":"https://api.github.com/users/adamcfraser/events{/privacy}","received_events_url":"https://api.github.com/users/adamcfraser/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295/commits","review_comments_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295/comments","review_comment_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls/comments{/number}","comments_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/1295/comments","statuses_url":"https://api.github.com/repos/couchbase/sync_gateway/statuses/bf965b4cd2715bf9bd02bdd8970ef0068b1507ab","head":{"label":"couchbase:feature/db_online_offline","ref":"feature/db_online_offline","sha":"bf965b4cd2715bf9bd02bdd8970ef0068b1507ab","user":{"login":"couchbase","id":605755,"avatar_url":"https://avatars.githubusercontent.com/u/605755?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbase","html_url":"https://github.com/couchbase","followers_url":"https://api.github.com/users/couchbase/followers","following_url":"https://api.github.com/users/couchbase/following{/other_user}","gists_url":"https://api.github.com/users/couchbase/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbase/subscriptions","organizations_url":"https://api.github.com/users/couchbase/orgs","repos_url":"https://api.github.com/users/couchbase/repos","events_url":"https://api.github.com/users/couchbase/events{/privacy}","received_events_url":"https://api.github.com/users/couchbase/received_events","type":"Organization","site_admin":false},"repo":{"id":6082996,"name":"sync_gateway","full_name":"couchbase/sync_gateway","owner":{"login":"couchbase","id":605755,"avatar_url":"https://avatars.githubusercontent.com/u/605755?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbase","html_url":"https://github.com/couchbase","followers_url":"https://api.github.com/users/couchbase/followers","following_url":"https://api.github.com/users/couchbase/following{/other_user}","gists_url":"https://api.github.com/users/couchbase/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbase/subscriptions","organizations_url":"https://api.github.com/users/couchbase/orgs","repos_url":"https://api.github.com/users/couchbase/repos","events_url":"https://api.github.com/users/couchbase/events{/privacy}","received_events_url":"https://api.github.com/users/couchbase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/couchbase/sync_gateway","description":"Connects Couchbase Lite to Couchbase Server","fork":false,"url":"https://api.github.com/repos/couchbase/sync_gateway","forks_url":"https://api.github.com/repos/couchbase/sync_gateway/forks","keys_url":"https://api.github.com/repos/couchbase/sync_gateway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/couchbase/sync_gateway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/couchbase/sync_gateway/teams","hooks_url":"https://api.github.com/repos/couchbase/sync_gateway/hooks","issue_events_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/events{/number}","events_url":"https://api.github.com/repos/couchbase/sync_gateway/events","assignees_url":"https://api.github.com/repos/couchbase/sync_gateway/assignees{/user}","branches_url":"https://api.github.com/repos/couchbase/sync_gateway/branches{/branch}","tags_url":"https://api.github.com/repos/couchbase/sync_gateway/tags","blobs_url":"https://api.github.com/repos/couchbase/sync_gateway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/couchbase/sync_gateway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/couchbase/sync_gateway/git/refs{/sha}","trees_url":"https://api.github.com/repos/couchbase/sync_gateway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/couchbase/sync_gateway/statuses/{sha}","languages_url":"https://api.github.com/repos/couchbase/sync_gateway/languages","stargazers_url":"https://api.github.com/repos/couchbase/sync_gateway/stargazers","contributors_url":"https://api.github.com/repos/couchbase/sync_gateway/contributors","subscribers_url":"https://api.github.com/repos/couchbase/sync_gateway/subscribers","subscription_url":"https://api.github.com/repos/couchbase/sync_gateway/subscription","commits_url":"https://api.github.com/repos/couchbase/sync_gateway/commits{/sha}","git_commits_url":"https://api.github.com/repos/couchbase/sync_gateway/git/commits{/sha}","comments_url":"https://api.github.com/repos/couchbase/sync_gateway/comments{/number}","issue_comment_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/comments{/number}","contents_url":"https://api.github.com/repos/couchbase/sync_gateway/contents/{+path}","compare_url":"https://api.github.com/repos/couchbase/sync_gateway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/couchbase/sync_gateway/merges","archive_url":"https://api.github.com/repos/couchbase/sync_gateway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/couchbase/sync_gateway/downloads","issues_url":"https://api.github.com/repos/couchbase/sync_gateway/issues{/number}","pulls_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls{/number}","milestones_url":"https://api.github.com/repos/couchbase/sync_gateway/milestones{/number}","notifications_url":"https://api.github.com/repos/couchbase/sync_gateway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/couchbase/sync_gateway/labels{/name}","releases_url":"https://api.github.com/repos/couchbase/sync_gateway/releases{/id}","created_at":"2012-10-04T22:25:43Z","updated_at":"2015-11-22T16:56:38Z","pushed_at":"2015-11-19T21:35:36Z","git_url":"git://github.com/couchbase/sync_gateway.git","ssh_url":"git@github.com:couchbase/sync_gateway.git","clone_url":"https://github.com/couchbase/sync_gateway.git","svn_url":"https://github.com/couchbase/sync_gateway","homepage":"","size":15332,"stargazers_count":258,"watchers_count":258,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":304,"forks":66,"open_issues":304,"watchers":258,"default_branch":"master"}},"base":{"label":"couchbase:master","ref":"master","sha":"2f3a599c6149d08d0d27c18ca0c13d00f5e88e88","user":{"login":"couchbase","id":605755,"avatar_url":"https://avatars.githubusercontent.com/u/605755?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbase","html_url":"https://github.com/couchbase","followers_url":"https://api.github.com/users/couchbase/followers","following_url":"https://api.github.com/users/couchbase/following{/other_user}","gists_url":"https://api.github.com/users/couchbase/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbase/subscriptions","organizations_url":"https://api.github.com/users/couchbase/orgs","repos_url":"https://api.github.com/users/couchbase/repos","events_url":"https://api.github.com/users/couchbase/events{/privacy}","received_events_url":"https://api.github.com/users/couchbase/received_events","type":"Organization","site_admin":false},"repo":{"id":6082996,"name":"sync_gateway","full_name":"couchbase/sync_gateway","owner":{"login":"couchbase","id":605755,"avatar_url":"https://avatars.githubusercontent.com/u/605755?v=3","gravatar_id":"","url":"https://api.github.com/users/couchbase","html_url":"https://github.com/couchbase","followers_url":"https://api.github.com/users/couchbase/followers","following_url":"https://api.github.com/users/couchbase/following{/other_user}","gists_url":"https://api.github.com/users/couchbase/gists{/gist_id}","starred_url":"https://api.github.com/users/couchbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/couchbase/subscriptions","organizations_url":"https://api.github.com/users/couchbase/orgs","repos_url":"https://api.github.com/users/couchbase/repos","events_url":"https://api.github.com/users/couchbase/events{/privacy}","received_events_url":"https://api.github.com/users/couchbase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/couchbase/sync_gateway","description":"Connects Couchbase Lite to Couchbase Server","fork":false,"url":"https://api.github.com/repos/couchbase/sync_gateway","forks_url":"https://api.github.com/repos/couchbase/sync_gateway/forks","keys_url":"https://api.github.com/repos/couchbase/sync_gateway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/couchbase/sync_gateway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/couchbase/sync_gateway/teams","hooks_url":"https://api.github.com/repos/couchbase/sync_gateway/hooks","issue_events_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/events{/number}","events_url":"https://api.github.com/repos/couchbase/sync_gateway/events","assignees_url":"https://api.github.com/repos/couchbase/sync_gateway/assignees{/user}","branches_url":"https://api.github.com/repos/couchbase/sync_gateway/branches{/branch}","tags_url":"https://api.github.com/repos/couchbase/sync_gateway/tags","blobs_url":"https://api.github.com/repos/couchbase/sync_gateway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/couchbase/sync_gateway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/couchbase/sync_gateway/git/refs{/sha}","trees_url":"https://api.github.com/repos/couchbase/sync_gateway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/couchbase/sync_gateway/statuses/{sha}","languages_url":"https://api.github.com/repos/couchbase/sync_gateway/languages","stargazers_url":"https://api.github.com/repos/couchbase/sync_gateway/stargazers","contributors_url":"https://api.github.com/repos/couchbase/sync_gateway/contributors","subscribers_url":"https://api.github.com/repos/couchbase/sync_gateway/subscribers","subscription_url":"https://api.github.com/repos/couchbase/sync_gateway/subscription","commits_url":"https://api.github.com/repos/couchbase/sync_gateway/commits{/sha}","git_commits_url":"https://api.github.com/repos/couchbase/sync_gateway/git/commits{/sha}","comments_url":"https://api.github.com/repos/couchbase/sync_gateway/comments{/number}","issue_comment_url":"https://api.github.com/repos/couchbase/sync_gateway/issues/comments{/number}","contents_url":"https://api.github.com/repos/couchbase/sync_gateway/contents/{+path}","compare_url":"https://api.github.com/repos/couchbase/sync_gateway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/couchbase/sync_gateway/merges","archive_url":"https://api.github.com/repos/couchbase/sync_gateway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/couchbase/sync_gateway/downloads","issues_url":"https://api.github.com/repos/couchbase/sync_gateway/issues{/number}","pulls_url":"https://api.github.com/repos/couchbase/sync_gateway/pulls{/number}","milestones_url":"https://api.github.com/repos/couchbase/sync_gateway/milestones{/number}","notifications_url":"https://api.github.com/repos/couchbase/sync_gateway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/couchbase/sync_gateway/labels{/name}","releases_url":"https://api.github.com/repos/couchbase/sync_gateway/releases{/id}","created_at":"2012-10-04T22:25:43Z","updated_at":"2015-11-22T16:56:38Z","pushed_at":"2015-11-19T21:35:36Z","git_url":"git://github.com/couchbase/sync_gateway.git","ssh_url":"git@github.com:couchbase/sync_gateway.git","clone_url":"https://github.com/couchbase/sync_gateway.git","svn_url":"https://github.com/couchbase/sync_gateway","homepage":"","size":15332,"stargazers_count":258,"watchers_count":258,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":66,"mirror_url":null,"open_issues_count":304,"forks":66,"open_issues":304,"watchers":258,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295"},"html":{"href":"https://github.com/couchbase/sync_gateway/pull/1295"},"issue":{"href":"https://api.github.com/repos/couchbase/sync_gateway/issues/1295"},"comments":{"href":"https://api.github.com/repos/couchbase/sync_gateway/issues/1295/comments"},"review_comments":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295/comments"},"review_comment":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/couchbase/sync_gateway/pulls/1295/commits"},"statuses":{"href":"https://api.github.com/repos/couchbase/sync_gateway/statuses/bf965b4cd2715bf9bd02bdd8970ef0068b1507ab"}}}}