Skip to content

Commit 11799b1

Browse files
author
Gonlo2
authored
Merge branch 'master' into add-galera-support
2 parents b4a0a79 + dcc3e90 commit 11799b1

96 files changed

Lines changed: 17961 additions & 1913 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@master
12+
13+
- name: Set up Go 1.12
14+
uses: actions/setup-go@v1
15+
with:
16+
version: 1.12
17+
id: go
18+
19+
- name: Build
20+
run: script/cibuild
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: migration tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@master
12+
13+
- name: Set up Go 1.12
14+
uses: actions/setup-go@v1
15+
with:
16+
version: 1.12
17+
id: go
18+
19+
- name: migration tests
20+
run: script/cibuild-gh-ost-replica-tests

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
language: go
33

44
go:
5-
- "1.9"
6-
- "1.10"
5+
- "1.12.x"
76

87
os:
98
- linux
109

10+
services:
11+
- mysql
12+
1113
env:
1214
- MYSQL_USER=root
1315
- CURRENT_CI_ENV=travis

Dockerfile.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.12.1
2+
LABEL maintainer="github@github.com"
3+
4+
RUN apt-get update
5+
RUN apt-get install -y lsb-release
6+
RUN rm -rf /var/lib/apt/lists/*
7+
8+
COPY . /go/src/github.com/github/gh-ost
9+
WORKDIR /go/src/github.com/github/gh-ost
10+
11+
CMD ["script/test"]

README.md

Lines changed: 1 addition & 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.9` and above. To build on your own, use either:
97+
`gh-ost` is a Go project; it is built with Go `1.12` 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

build.sh

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

21-
22-
23-
if ! go version | egrep -q 'go(1[.]9|1[.]1[0-9])' ; then
24-
echo "go version is too low. Must use 1.9 or above"
21+
if ! go version | egrep -q 'go(1\.1[234])' ; then
22+
echo "go version must be 1.12 or above"
2523
exit 1
2624
fi
2725

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: "3.5"
2+
services:
3+
app:
4+
image: app
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.test

go/logic/applier.go

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,12 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
485485
}
486486
defer tx.Rollback()
487487
sessionQuery := fmt.Sprintf(`SET SESSION time_zone = '%s'`, this.migrationContext.ApplierTimeZone)
488+
sqlModeAddendum := `,NO_AUTO_VALUE_ON_ZERO`
488489
if !this.migrationContext.SkipStrictMode {
489-
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
490+
sqlModeAddendum = fmt.Sprintf("%s,STRICT_ALL_TABLES", sqlModeAddendum)
490491
}
492+
sessionQuery = fmt.Sprintf("%s, sql_mode = CONCAT(@@session.sql_mode, ',%s')", sessionQuery, sqlModeAddendum)
493+
491494
if _, err := tx.Exec(sessionQuery); err != nil {
492495
return nil, err
493496
}
@@ -1270,63 +1273,6 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (result
12701273
return append(results, newDmlBuildResultError(fmt.Errorf("Unknown dml event type: %+v", dmlEvent.DML)))
12711274
}
12721275

1273-
// ApplyDMLEventQuery writes an entry to the ghost table, in response to an intercepted
1274-
// original-table binlog event
1275-
func (this *Applier) ApplyDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) error {
1276-
for _, buildResult := range this.buildDMLEventQuery(dmlEvent) {
1277-
if buildResult.err != nil {
1278-
return buildResult.err
1279-
}
1280-
// TODO The below is in preparation for transactional writes on the ghost tables.
1281-
// Such writes would be, for example:
1282-
// - prepended with sql_mode setup
1283-
// - prepended with time zone setup
1284-
// - prepended with SET SQL_LOG_BIN=0
1285-
// - prepended with SET FK_CHECKS=0
1286-
// etc.
1287-
//
1288-
// a known problem: https://github.com/golang/go/issues/9373 -- bitint unsigned values, not supported in database/sql
1289-
// is solved by silently converting unsigned bigints to string values.
1290-
//
1291-
1292-
err := func() error {
1293-
tx, err := this.db.Begin()
1294-
if err != nil {
1295-
return err
1296-
}
1297-
rollback := func(err error) error {
1298-
tx.Rollback()
1299-
return err
1300-
}
1301-
sessionQuery := fmt.Sprintf("SET SESSION time_zone = '+00:00'")
1302-
if !this.migrationContext.SkipStrictMode {
1303-
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
1304-
}
1305-
if _, err := tx.Exec(sessionQuery); err != nil {
1306-
return rollback(err)
1307-
}
1308-
if _, err := tx.Exec(buildResult.query, buildResult.args...); err != nil {
1309-
return rollback(err)
1310-
}
1311-
if err := tx.Commit(); err != nil {
1312-
return err
1313-
}
1314-
return nil
1315-
}()
1316-
1317-
if err != nil {
1318-
err = fmt.Errorf("%s; query=%s; args=%+v", err.Error(), buildResult.query, buildResult.args)
1319-
return log.Errore(err)
1320-
}
1321-
// no error
1322-
atomic.AddInt64(&this.migrationContext.TotalDMLEventsApplied, 1)
1323-
if this.migrationContext.CountTableRows {
1324-
atomic.AddInt64(&this.migrationContext.RowsDeltaEstimate, buildResult.rowsDelta)
1325-
}
1326-
}
1327-
return nil
1328-
}
1329-
13301276
// ApplyDMLEventQueries applies multiple DML queries onto the _ghost_ table
13311277
func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) error {
13321278

@@ -1344,9 +1290,13 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
13441290
}
13451291

13461292
sessionQuery := "SET SESSION time_zone = '+00:00'"
1293+
1294+
sqlModeAddendum := `,NO_AUTO_VALUE_ON_ZERO`
13471295
if !this.migrationContext.SkipStrictMode {
1348-
sessionQuery += ", sql_mode = CONCAT(@@session.sql_mode, ',STRICT_ALL_TABLES')"
1296+
sqlModeAddendum = fmt.Sprintf("%s,STRICT_ALL_TABLES", sqlModeAddendum)
13491297
}
1298+
sessionQuery = fmt.Sprintf("%s, sql_mode = CONCAT(@@session.sql_mode, ',%s')", sessionQuery, sqlModeAddendum)
1299+
13501300
if _, err := tx.Exec(sessionQuery); err != nil {
13511301
return rollback(err)
13521302
}

go/logic/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (pr
144144
switch command {
145145
case "help":
146146
{
147-
fmt.Fprintln(writer, `available commands:
147+
fmt.Fprint(writer, `available commands:
148148
status # Print a detailed status message
149149
sup # Print a short status message
150150
coordinates # Print the currently inspected coordinates
@@ -341,7 +341,7 @@ help # This message
341341
err := fmt.Errorf("User commanded 'panic' on %s, but migrated table is %s; ignoring request.", arg, this.migrationContext.OriginalTableName)
342342
return NoPrintStatusRule, err
343343
}
344-
err := fmt.Errorf("User commanded 'panic'. I will now panic, without cleanup. PANIC!")
344+
err := fmt.Errorf("User commanded 'panic'. The migration will be aborted without cleanup. Please drop the gh-ost tables before trying again.")
345345
this.migrationContext.PanicAbort <- err
346346
return NoPrintStatusRule, err
347347
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
i int not null,
5+
primary key(id)
6+
) auto_increment=1;
7+
8+
set session sql_mode='NO_AUTO_VALUE_ON_ZERO';
9+
insert into gh_ost_test values (0, 23);

0 commit comments

Comments
 (0)