Skip to content

Commit 7ed4589

Browse files
RainbowDashytimvaillancourtdm-2wangzihuacoolshlomi-noach
authored
chore: merge upstream (#29)
* Add script and docs for linter (github#1151) * Enable more `golang-ci` linters (github#1149) * Only build RPM and deb packages for amd64 * Convert character to bytes and insert into table using latin1 * delete junk files * restore connection charset to utf8mb4 * Allow zero in dates (github#1161) * Merge pull request #31 from openark/zero-date Support zero date and zero in date, via dedicated command line flag * Merge pull request #32 from openark/existing-date-with-zero Support tables with existing zero dates * Remove un-needed ignore_versions file * Fix new lint errors from golang-ci update Co-authored-by: Shlomi Noach <[email protected]> * Add missing doc from PR github#1131 (github#1162) * Set a transaction isolation level for MySQL connections (github#1156) * Set transaction isolation in connections * Revert load_map.go change * Var rename * Restore comment * Some fix to unit tests. * convert to bytes if character string without charsetConversion. * chore: remove duplicate word in comments (github#1175) Signed-off-by: Abirdcfly <[email protected]> Signed-off-by: Abirdcfly <[email protected]> * Improve applier `.ReadMigrationRangeValues()` func accuracy (github#1164) * Use a transaction in applier `ReadMigrationRangeValues` func * Private func names * Add basic tests for applier (github#1165) * Add basic tests for applier * Add header * Add basic test for inspector (github#1166) * Add basic test for inspector * Add header * Fix return * Add basic tests to migrator (github#1168) * add-rocksdb-as-transactional-engine * Add basic test for hooks (github#1179) * Enable more `golangci-lint` linters (github#1181) * Print status to migration context logger * fix CI tests to ubuntu-20.04 because ubuntu-22.04 (current -latest) doesn't support MySQL 5.7 * temp commit to investigate datetime-with-zero test failure * more testing * add extra debugging output * debugging * add error detection for test setup, sort tests to make it easier to track progress * fix broken test by removing invalid insert statement * Fix: Change table name table name is 'tbl' not 'tble' * Attempt instant DDL if supported * minor cleanup * Add tests, incorporate feedback * Improve docs * Address PR feedback * Make it clear in docs it is disabled by default but safe. * Update go/logic/migrator.go Co-authored-by: dm-2 <[email protected]> * remove useless func per review * support rocksdb as transactional engine * Modify tests to support rocksdb tests * SetConnectionConfig * add support for rocksdb * add support for rocksdb * add percona to versions in workflows * add description and optimize tests * Apply suggestions from code review Co-authored-by: dm-2 <[email protected]> * Apply suggestions from code review Co-authored-by: Tim Vaillancourt <[email protected]> * Update go/logic/applier.go Signed-off-by: Abirdcfly <[email protected]> Co-authored-by: Tim Vaillancourt <[email protected]> Co-authored-by: dm-2 <[email protected]> Co-authored-by: wangzihuacool <[email protected]> Co-authored-by: wangzihuacool <[email protected]> Co-authored-by: Shlomi Noach <[email protected]> Co-authored-by: Abirdcfly <[email protected]> Co-authored-by: Nicholas Calugar <[email protected]> Co-authored-by: Hasan Mshawrab <[email protected]> Co-authored-by: Morgan Tocker <[email protected]> Co-authored-by: Morgan Tocker <[email protected]> Co-authored-by: lukelewang <[email protected]>
1 parent af1faca commit 7ed4589

Some content is hidden

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

56 files changed

+1258
-253
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [pull_request]
55
jobs:
66
build:
77

8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-20.04
99

1010
steps:
1111
- uses: actions/checkout@v2

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ jobs:
1919
- uses: actions/checkout@v3
2020
- name: golangci-lint
2121
uses: golangci/golangci-lint-action@v3
22+
with:
23+
version: v1.46.2

.github/workflows/replica-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ on: [pull_request]
55
jobs:
66
build:
77

8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-20.04
99
strategy:
1010
matrix:
11-
version: [mysql-5.7.25,mysql-8.0.16]
11+
version: [mysql-5.7.25,mysql-8.0.16,PerconaServer-8.0.21]
1212

1313
steps:
1414
- uses: actions/checkout@v2

.golangci.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
run:
22
timeout: 5m
3-
modules-download-mode: readonly
4-
53
linters:
64
disable:
75
- errcheck
86
enable:
7+
- bodyclose
8+
- containedctx
9+
- contextcheck
10+
- dogsled
11+
- durationcheck
12+
- errname
13+
- errorlint
14+
- execinquery
15+
- gofmt
16+
- ifshort
17+
- misspell
18+
- nilerr
19+
- nilnil
920
- noctx
21+
- nolintlint
22+
- nosprintfhostport
23+
- prealloc
1024
- rowserrcheck
1125
- sqlclosecheck
26+
- unconvert
27+
- unparam
1228
- unused
13-
29+
- wastedassign
30+
- whitespace

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function build {
3535

3636
(cd $buildpath && tar cfz ./gh-ost-binary-${osshort}-${GOARCH}-${timestamp}.tar.gz $target)
3737

38-
if [ "$GOOS" == "linux" ] ; then
38+
# build RPM and deb for Linux, x86-64 only
39+
if [ "$GOOS" == "linux" ] && [ "$GOARCH" == "amd64" ] ; then
3940
echo "Creating Distro full packages"
4041
builddir=$(setuptree)
4142
cp $buildpath/$target $builddir/gh-ost/usr/bin

doc/coding-ghost.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Getting started with gh-ost development is simple!
66

77
- First obtain the repository with `git clone` or `go get`.
8-
- From inside of the repository run `script/cibuild`
8+
- From inside of the repository run `script/cibuild`.
99
- This will bootstrap the environment if needed, format the code, build the code, and then run the unit test.
1010

1111
## CI build workflow
@@ -14,6 +14,12 @@ Getting started with gh-ost development is simple!
1414

1515
If additional steps are needed, please add them into this workflow so that the workflow remains simple.
1616

17+
## `golang-ci` linter
18+
19+
To enfore best-practices, Pull Requests are automatically linted by [`golang-ci`](https://golangci-lint.run/). The linter config is located at [`.golangci.yml`](https://github.com/github/gh-ost/blob/master/.golangci.yml) and the `golangci-lint` GitHub Action is located at [`.github/workflows/golangci-lint.yml`](https://github.com/github/gh-ost/blob/master/.github/workflows/golangci-lint.yml).
20+
21+
To run the `golang-ci` linters locally _(recommended before push)_, use `script/lint`.
22+
1723
## Notes:
1824

1925
Currently, `script/ensure-go-installed` will install `go` for Mac OS X and Linux. We welcome PR's to add other platforms.

doc/command-line-flags.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ A more in-depth discussion of various `gh-ost` command line flags: implementatio
66

77
Add this flag when executing on Aliyun RDS.
88

9+
### allow-zero-in-date
10+
11+
Allows the user to make schema changes that include a zero date or zero in date (e.g. adding a `datetime default '0000-00-00 00:00:00'` column), even if global `sql_mode` on MySQL has `NO_ZERO_IN_DATE,NO_ZERO_DATE`.
12+
913
### azure
1014

1115
Add this flag when executing on Azure Database for MySQL.
@@ -41,6 +45,22 @@ If you happen to _know_ your servers use RBR (Row Based Replication, i.e. `binlo
4145
Skipping this step means `gh-ost` would not need the `SUPER` privilege in order to operate.
4246
You may want to use this on Amazon RDS.
4347

48+
### attempt-instant-ddl
49+
50+
MySQL 8.0 supports "instant DDL" for some operations. If an alter statement can be completed with instant DDL, only a metadata change is required internally. Instant operations include:
51+
52+
- Adding a column
53+
- Dropping a column
54+
- Dropping an index
55+
- Extending a varchar column
56+
- Adding a virtual generated column
57+
58+
It is not reliable to parse the `ALTER` statement to determine if it is instant or not. This is because the table might be in an older row format, or have some other incompatibility that is difficult to identify.
59+
60+
`--attempt-instant-ddl` is disabled by default, but the risks of enabling it are relatively minor: `gh-ost` may need to acquire a metadata lock at the start of the operation. This is not a problem for most scenarios, but it could be a problem for users that start the DDL during a period with long running transactions.
61+
62+
`gh-ost` will automatically fallback to the normal DDL process if the attempt to use instant DDL is unsuccessful.
63+
4464
### conf
4565

4666
`--conf=/path/to/my.cnf`: file where credentials are specified. Should be in (or contain) the following format:
@@ -226,6 +246,18 @@ Allows `gh-ost` to connect to the MySQL servers using encrypted connections, but
226246

227247
`--ssl-key=/path/to/ssl-key.key`: SSL private key file (in PEM format).
228248

249+
### storage-engine
250+
Default is `innodb`, and `rocksdb` support is currently experimental. InnoDB and RocksDB are both transactional engines, supporting both shared and exclusive row locks.
251+
252+
But RocksDB currently lacks a few features support compared to InnoDB:
253+
- Gap Locks
254+
- Foreign Key
255+
- Generated Columns
256+
- Spatial
257+
- Geometry
258+
259+
When `--storage-engine=rocksdb`, `gh-ost` will make some changes necessary (e.g. sets isolation level to `READ_COMMITTED`) to support RocksDB.
260+
229261
### test-on-replica
230262

231263
Issue the migration on a replica; do not modify data on master. Useful for validating, testing and benchmarking. See [`testing-on-replica`](testing-on-replica.md)
@@ -242,6 +274,14 @@ Provide a command delimited list of replicas; `gh-ost` will throttle when any of
242274

243275
Provide an HTTP endpoint; `gh-ost` will issue `HEAD` requests on given URL and throttle whenever response status code is not `200`. The URL can be queried and updated dynamically via [interactive commands](interactive-commands.md). Empty URL disables the HTTP check.
244276

277+
### throttle-http-interval-millis
278+
279+
Defaults to 100. Configures the HTTP throttle check interval in milliseconds.
280+
281+
### throttle-http-timeout-millis
282+
283+
Defaults to 1000 (1 second). Configures the HTTP throttler check timeout in milliseconds.
284+
245285
### timestamp-old-table
246286

247287
Makes the _old_ table include a timestamp value. The _old_ table is what the original table is renamed to at the end of a successful migration. For example, if the table is `gh_ost_test`, then the _old_ table would normally be `_gh_ost_test_del`. With `--timestamp-old-table` it would be, for example, `_gh_ost_test_20170221103147_del`.

doc/requirements-and-limitations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The `SUPER` privilege is required for `STOP SLAVE`, `START SLAVE` operations. Th
2020
- Switching your `binlog_format` to `ROW`, in the case where it is _not_ `ROW` and you explicitly specified `--switch-to-rbr`
2121
- If your replication is already in RBR (`binlog_format=ROW`) you can specify `--assume-rbr` to avoid the `STOP SLAVE/START SLAVE` operations, hence no need for `SUPER`.
2222

23+
- `gh-ost` uses the `REPEATABLE_READ` transaction isolation level for all MySQL connections, regardless of the server default.
24+
2325
- Running `--test-on-replica`: before the cut-over phase, `gh-ost` stops replication so that you can compare the two tables and satisfy that the migration is sound.
2426

2527
### Limitations

doc/shared-key.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CREATE TABLE tbl (
2929

3030
(This is also the definition of the _ghost_ table, except that that table would be called `_tbl_gho`).
3131

32-
In this migration, the _before_ and _after_ versions contain the same unique not-null key (the PRIMARY KEY). To run this migration, `gh-ost` would iterate through the `tbl` table using the primary key, copy rows from `tbl` to the _ghost_ table `_tbl_gho` in primary key order, while also applying the binlog event writes from `tble` onto `_tbl_gho`.
32+
In this migration, the _before_ and _after_ versions contain the same unique not-null key (the PRIMARY KEY). To run this migration, `gh-ost` would iterate through the `tbl` table using the primary key, copy rows from `tbl` to the _ghost_ table `_tbl_gho` in primary key order, while also applying the binlog event writes from `tbl` onto `_tbl_gho`.
3333

3434
The applying of the binlog events is what requires the shared unique key. For example, an `UPDATE` statement to `tbl` translates to a `REPLACE` statement which `gh-ost` applies to `_tbl_gho`. A `REPLACE` statement expects to insert or replace an existing row based on its row's values and the table's unique key constraints. In particular, if inserting that row would result in a unique key violation (e.g., a row with that primary key already exists), it would _replace_ that existing row with the new values.
3535

go/base/context.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type MigrationContext struct {
9292
AssumeRBR bool
9393
SkipForeignKeyChecks bool
9494
SkipStrictMode bool
95+
AllowZeroInDate bool
9596
NullableUniqueKeyAllowed bool
9697
ApproveRenamedColumns bool
9798
SkipRenamedColumns bool
@@ -100,6 +101,7 @@ type MigrationContext struct {
100101
AliyunRDS bool
101102
GoogleCloudPlatform bool
102103
AzureMySQL bool
104+
AttemptInstantDDL bool
103105

104106
config ContextConfig
105107
configMutex *sync.Mutex
@@ -289,6 +291,19 @@ func NewMigrationContext() *MigrationContext {
289291
}
290292
}
291293

294+
func (this *MigrationContext) SetConnectionConfig(storageEngine string) error {
295+
var transactionIsolation string
296+
switch storageEngine {
297+
case "rocksdb":
298+
transactionIsolation = "READ-COMMITTED"
299+
default:
300+
transactionIsolation = "REPEATABLE-READ"
301+
}
302+
this.InspectorConnectionConfig.TransactionIsolation = transactionIsolation
303+
this.ApplierConnectionConfig.TransactionIsolation = transactionIsolation
304+
return nil
305+
}
306+
292307
func getSafeTableName(baseName string, suffix string) string {
293308
name := fmt.Sprintf("~%s_%s", baseName, suffix)
294309
if len(name) <= mysql.MaxTableNameLength {
@@ -438,6 +453,10 @@ func (this *MigrationContext) IsTransactionalTable() bool {
438453
{
439454
return true
440455
}
456+
case "rocksdb":
457+
{
458+
return true
459+
}
441460
}
442461
return false
443462
}
@@ -869,7 +888,7 @@ func (this *MigrationContext) ReadConfigFile() error {
869888
if cfg.Section("osc").HasKey("chunk_size") {
870889
this.config.Osc.Chunk_Size, err = cfg.Section("osc").Key("chunk_size").Int64()
871890
if err != nil {
872-
return fmt.Errorf("Unable to read osc chunk size: %s", err.Error())
891+
return fmt.Errorf("Unable to read osc chunk size: %w", err)
873892
}
874893
}
875894

@@ -884,7 +903,7 @@ func (this *MigrationContext) ReadConfigFile() error {
884903
if cfg.Section("osc").HasKey("max_lag_millis") {
885904
this.config.Osc.Max_Lag_Millis, err = cfg.Section("osc").Key("max_lag_millis").Int64()
886905
if err != nil {
887-
return fmt.Errorf("Unable to read max lag millis: %s", err.Error())
906+
return fmt.Errorf("Unable to read max lag millis: %w", err)
888907
}
889908
}
890909

0 commit comments

Comments
 (0)