Skip to content

Commit

Permalink
hacked 9439.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
vmogilev committed Jul 28, 2023
1 parent 2b42793 commit da5c9ab
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
5 changes: 5 additions & 0 deletions go/cmd/vtbackup/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage back
if err := mysqld.ExecuteSuperQueryList(ctx, cmds); err != nil {
return fmt.Errorf("can't initialize database: %v", err)
}

// Execute Alter commands on reparent_journal and ignore errors
cmds = mysqlctl.AlterReparentJournal()
_ = mysqld.ExecuteSuperQueryList(ctx, cmds)

backupParams.BackupTime = time.Now()
// Now we're ready to take the backup.
if err := mysqlctl.Backup(ctx, backupParams); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions go/vt/discovery/topology_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ func NewCellTabletsWatcher(ctx context.Context, topoServer *topo.Server, tr Tabl
// Start starts the topology watcher
func (tw *TopologyWatcher) Start() {
tw.wg.Add(1)
go func() {
defer tw.wg.Done()
ticker := time.NewTicker(tw.refreshInterval)
go func(t *TopologyWatcher) {
defer t.wg.Done()
ticker := time.NewTicker(t.refreshInterval)
defer ticker.Stop()
for {
tw.loadTablets()
t.loadTablets()
select {
case <-tw.ctx.Done():
case <-t.ctx.Done():
return
case <-ticker.C:
}
}
}()
}(tw)
}

// Stop stops the watcher. It does not clean up the tablets added to LegacyTabletRecorder.
Expand Down
14 changes: 12 additions & 2 deletions go/vt/mysqlctl/reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package mysqlctl

/*
This file contains the reparenting methods for mysqlctl.
TODO(alainjobart) Once refactoring is done, remove unused code paths.
*/

import (
Expand Down Expand Up @@ -50,6 +48,18 @@ func CreateReparentJournal() []string {
ENGINE=InnoDB`, mysql.MaximumPositionSize)}
}

// AlterReparentJournal returns the commands to execute to change
// column master_alias -> primary_alias or the other way
// In 13.0.0 we introduce renaming of primary_alias -> master_alias.
// This is to support in-place downgrade from a later version.
// In 14.0.0 we will replace this with renaming of master_alias -> primary_alias.
// This is to support in-place upgrades from 13.0.x to 14.0.x
func AlterReparentJournal() []string {
return []string{
"`ALTER TABLE _vt.reparent_journal CHANGE COLUMN primary_alias master_alias VARBINARY(32) NOT NULL`",
}
}

// PopulateReparentJournal returns the SQL command to use to populate
// the _vt.reparent_journal table, as well as the time_created_ns
// value used.
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/executor_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestStreamSQLSharded(t *testing.T) {
s := createSandbox("TestExecutor")
s.VSchema = executorVSchema
getSandbox(KsTestUnsharded).VSchema = unshardedVSchema
serv := new(sandboxTopo)
serv := newSandboxForCells([]string{cell})
resolver := newTestLegacyResolver(hc, serv, cell)
shards := []string{"-20", "20-40", "40-60", "60-80", "80-a0", "a0-c0", "c0-e0", "e0-"}
for _, shard := range shards {
Expand Down
14 changes: 13 additions & 1 deletion go/vt/vttablet/tabletmanager/rpc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (tm *TabletManager) InitPrimary(ctx context.Context) (string, error) {
return "", err
}

// Execute ALTER statement on reparent_journal table and ignore errors
cmds = mysqlctl.AlterReparentJournal()
_ = tm.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds)

// get the current replication position
pos, err := tm.MysqlDaemon.PrimaryPosition()
if err != nil {
Expand Down Expand Up @@ -289,7 +293,15 @@ func (tm *TabletManager) PopulateReparentJournal(ctx context.Context, timeCreate
return err
}
cmds := mysqlctl.CreateReparentJournal()
cmds = append(cmds, mysqlctl.PopulateReparentJournal(timeCreatedNS, actionName, topoproto.TabletAliasString(primaryAlias), pos))
if err := tm.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds); err != nil {
return err
}

// Execute ALTER statement on reparent_journal table and ignore errors
cmds = mysqlctl.AlterReparentJournal()
_ = tm.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds)

cmds = []string{mysqlctl.PopulateReparentJournal(timeCreatedNS, actionName, topoproto.TabletAliasString(primaryAlias), pos)}

return tm.MysqlDaemon.ExecuteSuperQueryList(ctx, cmds)
}
Expand Down

0 comments on commit da5c9ab

Please sign in to comment.