Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replicate: add state switch #2313

Merged
merged 6 commits into from
Apr 2, 2020
Merged

replicate: add state switch #2313

merged 6 commits into from
Apr 2, 2020

Conversation

disksing
Copy link
Contributor

@disksing disksing commented Apr 1, 2020

Signed-off-by: disksing i@disksing.com

What problem does this PR solve?

Fix #2271

What is changed and how it works?

  • add a background job to check store down and switch states
  • add test

Check List

Tests

  • Unit test

Code changes

  • Has persistent data change

Signed-off-by: disksing <i@disksing.com>
@disksing disksing added the component/schedule Scheduling logic. label Apr 1, 2020
@disksing disksing added this to the v4.0.0-rc milestone Apr 1, 2020
@nolouch nolouch modified the milestones: v4.0.0-rc, v3.0.12, v4.0.0-ga Apr 2, 2020
@@ -118,13 +132,16 @@ func (m *ModeManager) drSwitchToSyncRecover() error {
defer m.Unlock()
id, err := m.idAlloc.Alloc()
if err != nil {
log.Warn("failed to switch to sync_recover state", zap.String("replicate-mode", "dr_async"), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be dr_sync here?

return err
}
m.drAutosync = dr
log.Warn("switched to async state", zap.String("replicate-mode", "dr_async"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log.Info?

return err
}
m.drAutosync = dr
log.Warn("switched to sync_recover state", zap.String("replicate-mode", "dr_async"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log.Info?

@@ -133,8 +150,90 @@ func (m *ModeManager) drSwitchToSync() error {
defer m.Unlock()
dr := drAutosyncStatus{State: drStateSync}
if err := m.storage.SaveReplicateStatus(modeDRAutosync, dr); err != nil {
log.Warn("failed to switch to sync state", zap.String("replicate-mode", "dr_async"), zap.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dr_async -> dr_sync

return err
}
m.drAutosync = dr
log.Warn("switched to sync state", zap.String("replicate-mode", "dr_async"))
Copy link
Contributor

@shafreeck shafreeck Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@disksing disksing requested a review from shafreeck April 2, 2020 08:43
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm.

// Run starts the background job.
func (m *ModeManager) Run(quit chan struct{}) {
select {
case <-time.After(idleTimeout):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to wait for an idle timeout? better to add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, good idea

Copy link
Contributor

@shafreeck shafreeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@disksing
Copy link
Contributor Author

disksing commented Apr 2, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 2, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Apr 2, 2020

/run-all-tests

@sre-bot sre-bot merged commit fccb3d4 into tikv:master Apr 2, 2020
@disksing disksing deleted the state-switch branch April 2, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/schedule Scheduling logic. status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronous replication: states switch
4 participants