Skip to content

Commit 82d35f1

Browse files
zimulalashenli
authored andcommitted
ddl: support the rolling upgrade. (#6301) (#6305)
1 parent 217031a commit 82d35f1

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

ddl/column.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ func (d *ddl) doModifyColumn(t *meta.Meta, job *model.Job, newCol *model.ColumnI
460460
}
461461
}
462462

463+
// gofail: var uninitializedOffsetAndState bool
464+
// if uninitializedOffsetAndState {
465+
// if newCol.State != model.StatePublic {
466+
// return ver, errors.New("the column state is wrong")
467+
// }
468+
// }
469+
463470
// We need the latest column's offset and state. This information can be obtained from the store.
464471
newCol.Offset = oldCol.Offset
465472
newCol.State = oldCol.State

ddl/ddl_api.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,16 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or
13721372
}
13731373

13741374
newCol := table.ToColumn(&model.ColumnInfo{
1375-
ID: col.ID,
1375+
ID: col.ID,
1376+
// We use this PR(https://github.com/pingcap/tidb/pull/6274) as the dividing line to define whether it is a new version or an old version TiDB.
1377+
// The old version TiDB initializes the column's offset and state here.
1378+
// The new version TiDB doesn't initialize the column's offset and state, and it will do the initialization in run DDL function.
1379+
// When we do the rolling upgrade the following may happen:
1380+
// a new version TiDB builds the DDL job that doesn't be set the column's offset and state,
1381+
// and the old version TiDB is the DDL owner, it doesn't get offset and state from the store. Then it will encounter errors.
1382+
// So here we set offset and state to support the rolling upgrade.
1383+
Offset: col.Offset,
1384+
State: col.State,
13761385
OriginDefaultValue: col.OriginDefaultValue,
13771386
FieldType: *specNewColumn.Tp,
13781387
Name: newColName,

ddl/fail_db_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2018 PingCAP, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package ddl_test
15+
16+
import (
17+
gofail "github.com/coreos/gofail/runtime"
18+
. "github.com/pingcap/check"
19+
"golang.org/x/net/context"
20+
)
21+
22+
// TestInitializeOffsetAndState tests the case that the column's offset and state don't be initialized in the file of ddl_api.go when
23+
// doing the operation of 'modify column'.
24+
func (s *testStateChangeSuite) TestInitializeOffsetAndState(c *C) {
25+
_, err := s.se.Execute(context.Background(), "use test_db_state")
26+
c.Assert(err, IsNil)
27+
_, err = s.se.Execute(context.Background(), "create table t(a int, b int, c int)")
28+
c.Assert(err, IsNil)
29+
defer s.se.Execute(context.Background(), "drop table t")
30+
31+
gofail.Enable("github.com/pingcap/tidb/ddl/uninitializedOffsetAndState", `return(true)`)
32+
_, err = s.se.Execute(context.Background(), "ALTER TABLE t MODIFY COLUMN b int FIRST;")
33+
c.Assert(err, IsNil)
34+
gofail.Disable("github.com/pingcap/tidb/ddl/uninitializedOffsetAndState")
35+
}

0 commit comments

Comments
 (0)