Skip to content

Commit

Permalink
disttask: fix upgrade missing create framework_meta (#47744) (#47755)
Browse files Browse the repository at this point in the history
close #47593
  • Loading branch information
ti-chi-bot authored Oct 19, 2023
1 parent c53993b commit dddae41
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,17 @@ const (
version175 = 175

// version 176
// add `mysql.tidb_global_task_history`.
// add `mysql.tidb_global_task_history`
version176 = 176

// version 177
// add `mysql.dist_framework_meta`
version177 = 177
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version176
var currentBootstrapVersion int64 = version177

// DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it.
var internalSQLTimeout = owner.ManagerSessionTTL + 15
Expand Down Expand Up @@ -1166,6 +1170,7 @@ var (
upgradeToVer174,
upgradeToVer175,
upgradeToVer176,
upgradeToVer177,
}
)

Expand Down Expand Up @@ -2829,6 +2834,14 @@ func upgradeToVer176(s Session, ver int64) {
mustExecute(s, CreateGlobalTaskHistory)
}

func upgradeToVer177(s Session, ver int64) {
if ver >= version177 {
return
}
// ignore error when upgrading from v7.4 to higher version.
doReentrantDDL(s, CreateDistFrameworkMeta, infoschema.ErrTableExists)
}

func writeOOMAction(s Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down
31 changes: 31 additions & 0 deletions pkg/session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2085,5 +2085,36 @@ func TestTiDBUpgradeToVer176(t *testing.T) {
ver, err = getBootstrapVersion(seV175)
require.NoError(t, err)
require.Less(t, int64(ver175), ver)
MustExec(t, seV175, "SELECT * from mysql.tidb_global_task_history")
dom.Close()
}

func TestTiDBUpgradeToVer177(t *testing.T) {
store, _ := CreateStoreAndBootstrap(t)
defer func() {
require.NoError(t, store.Close())
}()
ver176 := version176
seV176 := CreateSessionAndSetID(t, store)
txn, err := store.Begin()
require.NoError(t, err)
m := meta.NewMeta(txn)
err = m.FinishBootstrap(int64(ver176))
require.NoError(t, err)
MustExec(t, seV176, fmt.Sprintf("update mysql.tidb set variable_value=%d where variable_name='tidb_server_version'", ver176))
err = txn.Commit(context.Background())
require.NoError(t, err)

unsetStoreBootstrapped(store.UUID())
ver, err := getBootstrapVersion(seV176)
require.NoError(t, err)
require.Equal(t, int64(ver176), ver)

dom, err := BootstrapSession(store)
require.NoError(t, err)
ver, err = getBootstrapVersion(seV176)
require.NoError(t, err)
require.Less(t, int64(ver176), ver)
MustExec(t, seV176, "SELECT * from mysql.dist_framework_meta")
dom.Close()
}

0 comments on commit dddae41

Please sign in to comment.