-
Notifications
You must be signed in to change notification settings - Fork 2.4k
tm revamp: remove calls to refreshTablet #6263
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bcd37a
tm revamp: remove external tablet record updates
sougou 1dd5050
tm revamp: implement publishState
sougou 5708fb5
tm revamp: deprecate refreshTablet WIP
sougou d75c6dd
tm revamp: remove usage of refreshTablet
sougou 5ea4b4d
tm revamp: update state more aggressively
sougou 486138e
tm revamp: address review comments
sougou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,9 +184,6 @@ type ActionAgent struct { | |
| // _shardSyncCancel is the function to stop the background shard sync goroutine. | ||
| _shardSyncCancel context.CancelFunc | ||
|
|
||
| // _tablet has the Tablet record we last read from the topology server. | ||
| _tablet *topodatapb.Tablet | ||
|
|
||
| // _disallowQueryService is set to the reason we should be | ||
| // disallowing queries from being served. It is set from changeCallback, | ||
| // and used by healthcheck. If empty, we should allow queries. | ||
|
|
@@ -230,6 +227,11 @@ type ActionAgent struct { | |
| _lockTablesTimer *time.Timer | ||
| // _isBackupRunning tells us whether there is a backup that is currently running | ||
| _isBackupRunning bool | ||
|
|
||
| pubMu sync.Mutex | ||
| // _tablet has the Tablet record we last read from the topology server. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment should match field name. |
||
| tablet *topodatapb.Tablet | ||
| isPublishing bool | ||
| } | ||
|
|
||
| // NewActionAgent creates a new ActionAgent and registers all the | ||
|
|
@@ -326,6 +328,33 @@ func NewActionAgent( | |
| agent.registerQueryService() | ||
| }) | ||
|
|
||
| // optionally populate metadata records | ||
| if !*restoreFromBackup && *initPopulateMetadata { | ||
| // we use initialTablet here because it has the intended tabletType. | ||
| // the tablet returned by agent.Tablet() will have type UNKNOWN until | ||
| // we call updateState. | ||
| localMetadata := agent.getLocalMetadataValues(agent.initialTablet.Type) | ||
| if agent.Cnf != nil { // we are managing mysqld | ||
| // we'll use batchCtx here because we are still initializing and can't proceed unless this succeeds | ||
| if err := agent.MysqlDaemon.Wait(batchCtx, agent.Cnf); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| err := mysqlctl.PopulateMetadataTables(agent.MysqlDaemon, localMetadata, topoproto.TabletDbName(agent.initialTablet)) | ||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "failed to -init_populate_metadata") | ||
| } | ||
| } | ||
|
|
||
| // Update our state (need the action lock). | ||
| // We do this upfront to prevent this from racing with restoreFromBackup | ||
| // in case it gets launched. | ||
| if err := agent.lock(batchCtx); err != nil { | ||
| return nil, err | ||
| } | ||
| agent.updateState(batchCtx, agent.initialTablet, "Start") | ||
| agent.unlock() | ||
|
|
||
| // two cases then: | ||
| // - restoreFromBackup is set: we restore, then initHealthCheck, all | ||
| // in the background | ||
|
|
@@ -342,34 +371,6 @@ func NewActionAgent( | |
| agent.initHealthCheck() | ||
| }() | ||
| } else { | ||
| // optionally populate metadata records | ||
| if *initPopulateMetadata { | ||
| // we use initialTablet here because it has the intended tabletType. | ||
| // the tablet returned by agent.Tablet() will have type UNKNOWN until we call | ||
| // refreshTablet | ||
| localMetadata := agent.getLocalMetadataValues(agent.initialTablet.Type) | ||
| if agent.Cnf != nil { // we are managing mysqld | ||
| // we'll use batchCtx here because we are still initializing and can't proceed unless this succeeds | ||
| if err := agent.MysqlDaemon.Wait(batchCtx, agent.Cnf); err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| err := mysqlctl.PopulateMetadataTables(agent.MysqlDaemon, localMetadata, topoproto.TabletDbName(agent.initialTablet)) | ||
| if err != nil { | ||
| return nil, vterrors.Wrap(err, "failed to -init_populate_metadata") | ||
| } | ||
| } | ||
|
|
||
| // Update our state (need the action lock). | ||
| if err := agent.lock(batchCtx); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := agent.refreshTablet(batchCtx, "Start"); err != nil { | ||
| agent.unlock() | ||
| return nil, err | ||
| } | ||
| agent.unlock() | ||
|
|
||
| // synchronously start health check if needed | ||
| agent.initHealthCheck() | ||
| } | ||
|
|
@@ -423,9 +424,7 @@ func NewTestActionAgent(batchCtx context.Context, ts *topo.Server, tabletAlias * | |
| panic(vterrors.Wrap(err, "agent.lock() failed")) | ||
| } | ||
| defer agent.unlock() | ||
| if err := agent.refreshTablet(batchCtx, "Start"); err != nil { | ||
| panic(vterrors.Wrapf(err, "agent.refreshTablet(%v) failed", tabletAlias)) | ||
| } | ||
| agent.updateState(batchCtx, agent.initialTablet, "Start") | ||
|
|
||
| return agent | ||
| } | ||
|
|
@@ -475,9 +474,7 @@ func NewComboActionAgent(batchCtx context.Context, ts *topo.Server, tabletAlias | |
| panic(vterrors.Wrap(err, "agent.lock() failed")) | ||
| } | ||
| defer agent.unlock() | ||
| if err := agent.refreshTablet(batchCtx, "Start"); err != nil { | ||
| panic(vterrors.Wrapf(err, "agent.refreshTablet(%v) failed", tabletAlias)) | ||
| } | ||
| agent.updateState(batchCtx, agent.initialTablet, "Start") | ||
|
|
||
| return agent | ||
| } | ||
|
|
@@ -488,19 +485,19 @@ func (agent *ActionAgent) registerQueryRuleSources() { | |
| } | ||
|
|
||
| func (agent *ActionAgent) setTablet(tablet *topodatapb.Tablet) { | ||
| agent.mutex.Lock() | ||
| agent._tablet = proto.Clone(tablet).(*topodatapb.Tablet) | ||
| agent.mutex.Unlock() | ||
| agent.pubMu.Lock() | ||
| agent.tablet = proto.Clone(tablet).(*topodatapb.Tablet) | ||
| agent.pubMu.Unlock() | ||
|
|
||
| // Notify the shard sync loop that the tablet state changed. | ||
| agent.notifyShardSync() | ||
| } | ||
|
|
||
| // Tablet reads the stored Tablet from the agent, protected by mutex. | ||
| // Tablet reads the stored Tablet from the agent. | ||
| func (agent *ActionAgent) Tablet() *topodatapb.Tablet { | ||
| agent.mutex.Lock() | ||
| tablet := proto.Clone(agent._tablet).(*topodatapb.Tablet) | ||
| agent.mutex.Unlock() | ||
| agent.pubMu.Lock() | ||
| tablet := proto.Clone(agent.tablet).(*topodatapb.Tablet) | ||
| agent.pubMu.Unlock() | ||
| return tablet | ||
| } | ||
|
|
||
|
|
@@ -666,6 +663,9 @@ func (agent *ActionAgent) Start(ctx context.Context, dbcfgs *dbconfigs.DBConfigs | |
| return err | ||
| } | ||
|
|
||
| // Initialize masterTermStartTime | ||
| agent.setMasterTermStartTime(logutil.ProtoToTime(agent.initialTablet.MasterTermStartTime)) | ||
|
|
||
| // Verify the topology is correct. | ||
| agent.verifyTopology(ctx) | ||
|
|
||
|
|
@@ -719,8 +719,7 @@ func (agent *ActionAgent) Start(ctx context.Context, dbcfgs *dbconfigs.DBConfigs | |
|
|
||
| // Initialize the current tablet to match our current running | ||
| // state: Has most field filled in, but type is UNKNOWN. | ||
| // Subsequents calls to updateState or refreshTablet | ||
| // will then work as expected. | ||
| // Subsequents calls to updateState will then work as expected. | ||
| startingTablet := proto.Clone(agent.initialTablet).(*topodatapb.Tablet) | ||
| startingTablet.Type = topodatapb.TabletType_UNKNOWN | ||
| agent.setTablet(startingTablet) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.