Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

add warning if follower is behind #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion commands/unfollow.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ function * run (context, heroku) {
${cli.color.addon(db.name)} will become writeable and no longer follow ${origin}. This cannot be undone.
`)

let response = { leader_xact: 0, follower_xact: 0 }
yield cli.action(`${cli.color.addon(db.name)} unfollowing`, co(function * () {
yield heroku.put(`/client/v11/databases/${db.id}/unfollow`, {host: host(db)})
response = yield heroku.put(`/client/v11/databases/${db.id}/unfollow`, {host: host(db)})
}))

if (response.leader_xact > response.follower_xact) {
cli.warn(`you unfollowed this database while the leader transaction was ${response.leader_xact} and the follower transaction was ${response.follower_xact}. Due to the lag, you may experience read-only mode with the unfollowed database (${db.name}) for a while.`)
}
}

module.exports = {
Expand Down
14 changes: 13 additions & 1 deletion test/commands/unfollow.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ describe('pg:unfollow', () => {
pg.get('/client/v11/databases/1').reply(200, {following: 'postgres://db1'})
pg.put('/client/v11/databases/1/unfollow').reply(200)
return cmd.run({app: 'myapp', args: {}, flags: {confirm: 'myapp'}})
.then(() => expect(cli.stderr, 'to equal', 'postgres-1 unfollowing... done\n'))
.then(() => expect(cli.stderr, 'to equal', 'postgres-1 unfollowing... done\n'))
})

it('warns if there is a lag', () => {
api.get('/apps/myapp/config-vars').reply(200, {DATABASE_URL: 'postgres://db1'})
pg.get('/client/v11/databases/1').reply(200, {following: 'postgres://db1'})
pg.put('/client/v11/databases/1/unfollow').reply(200, { leader_xact: 100, follower_xact: 50 })
return cmd.run({app: 'myapp', args: {}, flags: {confirm: 'myapp'}})
.then(() => expect(cli.stderr, 'to equal', `postgres-1 unfollowing... done
▸ you unfollowed this database while the leader transaction was 100 and the
▸ follower transaction was 50. Due to the lag, you may experience read-only
▸ mode with the unfollowed database (postgres-1) for a while.
`))
})
})