Skip to content

Commit

Permalink
*: suport alter table set flash replica syntax (pingcap#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and lzmhhh123 committed Jan 17, 2020
1 parent 90c07d3 commit 1aed1a5
Show file tree
Hide file tree
Showing 7 changed files with 7,231 additions and 7,119 deletions.
22 changes: 21 additions & 1 deletion ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,8 @@ const (
AlterTablePartition
AlterTableEnableKeys
AlterTableDisableKeys

// AlterTableSetTiFlashReplica uses to set the table TiFlash replica.
AlterTableSetTiFlashReplica
// TODO: Add more actions
)

Expand Down Expand Up @@ -1760,11 +1761,30 @@ type AlterTableSpec struct {
PartitionNames []model.CIStr
PartDefinitions []*PartitionDefinition
Num uint64
TiFlashReplica *TiFlashReplicaSpec
}

type TiFlashReplicaSpec struct {
Count uint64
Labels []string
}

// Restore implements Node interface.
func (n *AlterTableSpec) Restore(ctx *RestoreCtx) error {
switch n.Tp {
case AlterTableSetTiFlashReplica:
ctx.WriteKeyWord("SET TIFLASH REPLICA ")
ctx.WritePlainf("%d", n.TiFlashReplica.Count)
if len(n.TiFlashReplica.Labels) == 0 {
break
}
ctx.WriteKeyWord(" LOCATION LABELS ")
for i, v := range n.TiFlashReplica.Labels {
if i > 0 {
ctx.WritePlain(", ")
}
ctx.WriteString(v)
}
case AlterTableOption:
switch {
case len(n.Options) == 2 &&
Expand Down
3 changes: 3 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ var tokenMap = map[string]int{
"KEY_BLOCK_SIZE": keyBlockSize,
"KEYS": keys,
"KILL": kill,
"LABELS": labels,
"LAST": last,
"LEADING": leading,
"LEFT": left,
Expand All @@ -354,6 +355,7 @@ var tokenMap = map[string]int{
"LOCAL": local,
"LOCALTIME": localTime,
"LOCALTIMESTAMP": localTs,
"LOCATION": location,
"LOCK": lock,
"LONG": long,
"LONGBLOB": longblobType,
Expand Down Expand Up @@ -460,6 +462,7 @@ var tokenMap = map[string]int{
"REPEATABLE": repeatable,
"REPLACE": replace,
"RESPECT": respect,
"REPLICA": replica,
"REPLICATION": replication,
"REQUIRE": require,
"RESTRICT": restrict,
Expand Down
6 changes: 6 additions & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const (
ActionModifySchemaCharsetAndCollate ActionType = 26
ActionLockTable ActionType = 27
ActionUnlockTable ActionType = 28
ActionRepairTable ActionType = 29
ActionSetTiFlashReplica ActionType = 30
ActionUpdateTiFlashReplicaStatus ActionType = 31
ActionAddPrimaryKey ActionType = 32
ActionDropPrimaryKey ActionType = 33
)
Expand Down Expand Up @@ -99,6 +102,9 @@ var actionMap = map[ActionType]string{
ActionDropPrimaryKey: "drop primary key",
ActionLockTable: "lock table",
ActionUnlockTable: "unlock table",
ActionRepairTable: "repair table",
ActionSetTiFlashReplica: "set tiflash replica",
ActionUpdateTiFlashReplicaStatus: "update tiflash replica status",
}

// String return current ddl action in string
Expand Down
10 changes: 10 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ type TableInfo struct {

// Version means the version of the table info.
Version uint16 `json:"version"`

// TiFlashReplica means the TiFlash replica info.
TiFlashReplica *TiFlashReplicaInfo `json:"tiflash_replica"`
}

// TableLockInfo provides meta data describing a table lock.
Expand Down Expand Up @@ -335,6 +338,13 @@ func (t TableLockType) String() string {
return ""
}

// TiFlashReplicaInfo means the flash replica info.
type TiFlashReplicaInfo struct {
Count uint64
LocationLabels []string
Available bool
}

// GetPartitionInfo returns the partition information.
func (t *TableInfo) GetPartitionInfo() *PartitionInfo {
if t.Partition != nil && t.Partition.Enable {
Expand Down
Loading

0 comments on commit 1aed1a5

Please sign in to comment.