@@ -34,7 +34,6 @@ import (
34
34
"github.com/pingcap/tidb/pkg/bindinfo"
35
35
"github.com/pingcap/tidb/pkg/config"
36
36
"github.com/pingcap/tidb/pkg/domain"
37
- "github.com/pingcap/tidb/pkg/domain/infosync"
38
37
"github.com/pingcap/tidb/pkg/expression"
39
38
"github.com/pingcap/tidb/pkg/infoschema"
40
39
infoschemacontext "github.com/pingcap/tidb/pkg/infoschema/context"
@@ -62,7 +61,6 @@ import (
62
61
"github.com/pingcap/tidb/pkg/util/sqlescape"
63
62
"github.com/pingcap/tidb/pkg/util/sqlexec"
64
63
"github.com/pingcap/tidb/pkg/util/timeutil"
65
- "go.etcd.io/etcd/client/v3/concurrency"
66
64
"go.uber.org/zap"
67
65
)
68
66
@@ -721,13 +719,16 @@ const (
721
719
KEY (status));`
722
720
723
721
// CreatePITRIDMap is a table that records the id map from upstream to downstream for PITR.
722
+ // set restore id default to 0 to make it compatible for old BR tool to restore to a new TiDB, such case should be
723
+ // rare though.
724
724
CreatePITRIDMap = `CREATE TABLE IF NOT EXISTS mysql.tidb_pitr_id_map (
725
+ restore_id BIGINT NOT NULL DEFAULT 0,
725
726
restored_ts BIGINT NOT NULL,
726
727
upstream_cluster_id BIGINT NOT NULL,
727
728
segment_id BIGINT NOT NULL,
728
729
id_map BLOB(524288) NOT NULL,
729
730
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
730
- PRIMARY KEY (restored_ts, upstream_cluster_id, segment_id));`
731
+ PRIMARY KEY (restore_id, restored_ts, upstream_cluster_id, segment_id));`
731
732
732
733
// DropMySQLIndexUsageTable removes the table `mysql.schema_index_usage`
733
734
DropMySQLIndexUsageTable = "DROP TABLE IF EXISTS mysql.schema_index_usage"
@@ -1284,11 +1285,15 @@ const (
1284
1285
// version 247
1285
1286
// Add last_stats_histograms_version to mysql.stats_meta.
1286
1287
version247 = 247
1288
+
1289
+ // version 248
1290
+ // Update mysql.tidb_pitr_id_map to add restore_id as a primary key field
1291
+ version248 = 248
1287
1292
)
1288
1293
1289
1294
// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
1290
1295
// please make sure this is the largest version
1291
- var currentBootstrapVersion int64 = version247
1296
+ var currentBootstrapVersion int64 = version248
1292
1297
1293
1298
// 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.
1294
1299
var internalSQLTimeout = owner .ManagerSessionTTL + 15
@@ -1471,6 +1476,7 @@ var (
1471
1476
upgradeToVer245 ,
1472
1477
upgradeToVer246 ,
1473
1478
upgradeToVer247 ,
1479
+ upgradeToVer248 ,
1474
1480
}
1475
1481
)
1476
1482
@@ -1626,31 +1632,6 @@ func upgrade(s sessiontypes.Session) {
1626
1632
}
1627
1633
}
1628
1634
1629
- // checkOwnerVersion is used to wait the DDL owner to be elected in the cluster and check it is the same version as this TiDB.
1630
- func checkOwnerVersion (ctx context.Context , dom * domain.Domain ) (bool , error ) {
1631
- ticker := time .NewTicker (100 * time .Millisecond )
1632
- defer ticker .Stop ()
1633
- logutil .BgLogger ().Info ("Waiting for the DDL owner to be elected in the cluster" )
1634
- for {
1635
- select {
1636
- case <- ctx .Done ():
1637
- return false , ctx .Err ()
1638
- case <- ticker .C :
1639
- ownerID , err := dom .DDL ().OwnerManager ().GetOwnerID (ctx )
1640
- if err == concurrency .ErrElectionNoLeader {
1641
- continue
1642
- }
1643
- info , err := infosync .GetAllServerInfo (ctx )
1644
- if err != nil {
1645
- return false , err
1646
- }
1647
- if s , ok := info [ownerID ]; ok {
1648
- return s .Version == mysql .ServerVersion , nil
1649
- }
1650
- }
1651
- }
1652
- }
1653
-
1654
1635
// upgradeToVer2 updates to version 2.
1655
1636
func upgradeToVer2 (s sessiontypes.Session , ver int64 ) {
1656
1637
if ver >= version2 {
@@ -3477,6 +3458,15 @@ func upgradeToVer247(s sessiontypes.Session, ver int64) {
3477
3458
doReentrantDDL (s , "ALTER TABLE mysql.stats_meta ADD COLUMN last_stats_histograms_version bigint unsigned DEFAULT NULL" , infoschema .ErrColumnExists )
3478
3459
}
3479
3460
3461
+ func upgradeToVer248 (s sessiontypes.Session , ver int64 ) {
3462
+ if ver >= version248 {
3463
+ return
3464
+ }
3465
+ doReentrantDDL (s , "ALTER TABLE mysql.tidb_pitr_id_map ADD COLUMN restore_id BIGINT NOT NULL DEFAULT 0" , infoschema .ErrColumnExists )
3466
+ doReentrantDDL (s , "ALTER TABLE mysql.tidb_pitr_id_map DROP PRIMARY KEY" )
3467
+ doReentrantDDL (s , "ALTER TABLE mysql.tidb_pitr_id_map ADD PRIMARY KEY(restore_id, restored_ts, upstream_cluster_id, segment_id)" )
3468
+ }
3469
+
3480
3470
// initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist.
3481
3471
func initGlobalVariableIfNotExists (s sessiontypes.Session , name string , val any ) {
3482
3472
ctx := kv .WithInternalSourceType (context .Background (), kv .InternalTxnBootstrap )
0 commit comments