Skip to content

Commit f268259

Browse files
Merge branch 'master' into handle_driver_timeout_error
2 parents 4bbc8de + 5e953b7 commit f268259

43 files changed

Lines changed: 852 additions & 538 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@master
11+
- uses: actions/checkout@v2
1212

13-
- name: Set up Go 1.12
13+
- name: Set up Go 1.14
1414
uses: actions/setup-go@v1
1515
with:
16-
version: 1.12
17-
id: go
16+
go-version: 1.14
1817

1918
- name: Build
2019
run: script/cibuild
20+
21+
- name: Upload gh-ost binary artifact
22+
uses: actions/upload-artifact@v1
23+
with:
24+
name: gh-ost
25+
path: bin/gh-ost

.github/workflows/replica-tests.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@master
11+
- uses: actions/checkout@v2
1212

13-
- name: Set up Go 1.12
13+
- name: Set up Go 1.14
1414
uses: actions/setup-go@v1
1515
with:
16-
version: 1.12
17-
id: go
16+
go-version: 1.14
1817

1918
- name: migration tests
2019
run: script/cibuild-gh-ost-replica-tests

Dockerfile.packaging

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22

3-
FROM golang:1.12.6
3+
FROM golang:1.14.7
44

55
RUN apt-get update
66
RUN apt-get install -y ruby ruby-dev rubygems build-essential

Dockerfile.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.12.1
1+
FROM golang:1.14.7
22
LABEL maintainer="github@github.com"
33

44
RUN apt-get update

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Please see [Coding gh-ost](doc/coding-ghost.md) for a guide to getting started d
9494

9595
[Download latest release here](https://github.com/github/gh-ost/releases/latest)
9696

97-
`gh-ost` is a Go project; it is built with Go `1.12` and above. To build on your own, use either:
97+
`gh-ost` is a Go project; it is built with Go `1.14` and above. To build on your own, use either:
9898
- [script/build](https://github.com/github/gh-ost/blob/master/script/build) - this is the same build script used by CI hence the authoritative; artifact is `./bin/gh-ost` binary.
9999
- [build.sh](https://github.com/github/gh-ost/blob/master/build.sh) for building `tar.gz` artifacts in `/tmp/gh-ost`
100100

@@ -109,3 +109,4 @@ Generally speaking, `master` branch is stable, but only [releases](https://githu
109109
- [@shlomi-noach](https://github.com/shlomi-noach)
110110
- [@jessbreckenridge](https://github.com/jessbreckenridge)
111111
- [@gtowey](https://github.com/gtowey)
112+
- [@timvaillancourt](https://github.com/timvaillancourt)

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function build {
1818
GOOS=$3
1919
GOARCH=$4
2020

21-
if ! go version | egrep -q 'go(1\.1[234])' ; then
22-
echo "go version must be 1.12 or above"
21+
if ! go version | egrep -q 'go(1\.1[456])' ; then
22+
echo "go version must be 1.14 or above"
2323
exit 1
2424
fi
2525

go/base/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ func NewThrottleCheckResult(throttle bool, reason string, reasonHint ThrottleRea
7777
type MigrationContext struct {
7878
Uuid string
7979

80-
DatabaseName string
81-
OriginalTableName string
82-
AlterStatement string
80+
DatabaseName string
81+
OriginalTableName string
82+
AlterStatement string
83+
AlterStatementOptions string // anything following the 'ALTER TABLE [schema.]table' from AlterStatement
8384

8485
CountTableRows bool
8586
ConcurrentCountTableRows bool

go/cmd/gh-ost/main.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/github/gh-ost/go/base"
1616
"github.com/github/gh-ost/go/logic"
17+
"github.com/github/gh-ost/go/sql"
1718
_ "github.com/go-sql-driver/mysql"
1819
"github.com/outbrain/golib/log"
1920

@@ -48,6 +49,7 @@ func main() {
4849
flag.StringVar(&migrationContext.InspectorConnectionConfig.Key.Hostname, "host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)")
4950
flag.StringVar(&migrationContext.AssumeMasterHostname, "assume-master-host", "", "(optional) explicitly tell gh-ost the identity of the master. Format: some.host.com[:port] This is useful in master-master setups where you wish to pick an explicit master, or in a tungsten-replicator where gh-ost is unable to determine the master")
5051
flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)")
52+
flag.Float64Var(&migrationContext.InspectorConnectionConfig.Timeout, "mysql-timeout", 0.0, "Connect, read and write timeout for MySQL")
5153
flag.StringVar(&migrationContext.CliUser, "user", "", "MySQL user")
5254
flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password")
5355
flag.StringVar(&migrationContext.CliMasterUser, "master-user", "", "MySQL user on master, if different from that on replica. Requires --assume-master-host")
@@ -172,14 +174,25 @@ func main() {
172174
migrationContext.Log.SetLevel(log.ERROR)
173175
}
174176

177+
if migrationContext.AlterStatement == "" {
178+
log.Fatalf("--alter must be provided and statement must not be empty")
179+
}
180+
parser := sql.NewParserFromAlterStatement(migrationContext.AlterStatement)
181+
migrationContext.AlterStatementOptions = parser.GetAlterStatementOptions()
182+
175183
if migrationContext.DatabaseName == "" {
176-
migrationContext.Log.Fatalf("--database must be provided and database name must not be empty")
184+
if parser.HasExplicitSchema() {
185+
migrationContext.DatabaseName = parser.GetExplicitSchema()
186+
} else {
187+
log.Fatalf("--database must be provided and database name must not be empty, or --alter must specify database name")
188+
}
177189
}
178190
if migrationContext.OriginalTableName == "" {
179-
migrationContext.Log.Fatalf("--table must be provided and table name must not be empty")
180-
}
181-
if migrationContext.AlterStatement == "" {
182-
migrationContext.Log.Fatalf("--alter must be provided and statement must not be empty")
191+
if parser.HasExplicitTable() {
192+
migrationContext.OriginalTableName = parser.GetExplicitTable()
193+
} else {
194+
log.Fatalf("--table must be provided and table name must not be empty, or --alter must specify table name")
195+
}
183196
}
184197
migrationContext.Noop = !(*executeFlag)
185198
if migrationContext.AllowedRunningOnMaster && migrationContext.TestOnReplica {

go/logic/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (this *Applier) AlterGhost() error {
190190
query := fmt.Sprintf(`alter /* gh-ost */ table %s.%s %s`,
191191
sql.EscapeName(this.migrationContext.DatabaseName),
192192
sql.EscapeName(this.migrationContext.GetGhostTableName()),
193-
this.migrationContext.AlterStatement,
193+
this.migrationContext.AlterStatementOptions,
194194
)
195195
this.migrationContext.Log.Infof("Altering ghost table %s.%s",
196196
sql.EscapeName(this.migrationContext.DatabaseName),

go/logic/migrator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const (
6060

6161
// Migrator is the main schema migration flow manager.
6262
type Migrator struct {
63-
parser *sql.Parser
63+
parser *sql.AlterTableParser
6464
inspector *Inspector
6565
applier *Applier
6666
eventsStreamer *EventsStreamer
@@ -88,7 +88,7 @@ type Migrator struct {
8888
func NewMigrator(context *base.MigrationContext) *Migrator {
8989
migrator := &Migrator{
9090
migrationContext: context,
91-
parser: sql.NewParser(),
91+
parser: sql.NewAlterTableParser(),
9292
ghostTableMigrated: make(chan bool),
9393
firstThrottlingCollected: make(chan bool, 3),
9494
rowCopyComplete: make(chan error),

0 commit comments

Comments
 (0)