Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error when trying to ALTER a table without PRIMARY KEY / UNIQUE KEY #332

Closed
ramkireddy opened this issue Dec 9, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@ramkireddy
Copy link

commented Dec 9, 2016

Running into a following run time error when trying to ALTER a table.

#./gh-ost --max-load=Threads_running=25 --critical-load=Threads_running=1000 --chunk-size=1000 --max-lag-millis=1500 --user="ghuser" --password="xxxxxxxx" --host=sand1mysql-01 --database="czen" --table="ZIP_DIST_TEST" --verbose --alter="ADD COLUMN DESCRIPTION VARCHAR(255) NULL" --allow-master-master --cut-over=default --exact-rowcount --concurrent-rowcount --default-retries=120 --initially-drop-old-table --initially-drop-ghost-table --panic-flag-file=/tmp/ghost.panic.flag --postpone-cut-over-flag-file=/tmp/ghost.postpone.flag --execute
2016-12-09 16:12:31 INFO starting gh-ost 1.0.30
2016-12-09 16:12:31 INFO Migrating `czen`.`ZIP_DIST_TEST`
2016-12-09 16:12:31 INFO connection validated on dom-use-sand1mysql-04:3306
2016-12-09 16:12:31 INFO User has SUPER, REPLICATION SLAVE privileges, and has ALL privileges on `czen`.*
2016-12-09 16:12:31 INFO binary logs validated on dom-use-sand1mysql-04:3306
2016-12-09 16:12:31 INFO Restarting replication on dom-use-sand1mysql-04:3306 to make sure binlog settings apply to replication thread
2016-12-09 16:12:31 INFO Table found. Engine=InnoDB
2016-12-09 16:12:31 INFO Estimated number of rows via EXPLAIN: 10134006
2016-12-09 16:12:31 INFO Recursively searching for replication master
2016-12-09 16:12:31 INFO Master found to be sand1-mysqlmaster:3306
2016-12-09 16:12:31 INFO log_slave_updates validated on dom-use-sand1mysql-04:3306
2016-12-09 16:12:31 INFO connection validated on dom-use-sand1mysql-04:3306
2016-12-09 16:12:31 INFO Registering replica at dom-use-sand1mysql-04:3306
2016-12-09 16:12:31 INFO Connecting binlog streamer at bin-log.000002:220592054
2016-12-09 16:12:31 INFO rotate to next log name: bin-log.000002
2016-12-09 16:12:31 INFO connection validated on sand1-mysqlmaster:3306
2016-12-09 16:12:31 INFO connection validated on sand1-mysqlmaster:3306
2016-12-09 16:12:31 INFO will use time_zone='SYSTEM' on applier
2016-12-09 16:12:31 INFO Examining table structure on applier
2016-12-09 16:12:31 INFO Droppping table `czen`.`_ZIP_DIST_TEST_gho`
2016-12-09 16:12:31 INFO Table dropped
2016-12-09 16:12:31 INFO Droppping table `czen`.`_ZIP_DIST_TEST_del`
2016-12-09 16:12:31 INFO Table dropped
2016-12-09 16:12:31 INFO Droppping table `czen`.`_ZIP_DIST_TEST_ghc`
2016-12-09 16:12:31 INFO Table dropped
2016-12-09 16:12:31 INFO Creating changelog table `czen`.`_ZIP_DIST_TEST_ghc`
2016-12-09 16:12:31 INFO Changelog table created
2016-12-09 16:12:31 INFO Creating ghost table `czen`.`_ZIP_DIST_TEST_gho`
2016-12-09 16:12:31 INFO Ghost table created
2016-12-09 16:12:31 INFO Altering ghost table `czen`.`_ZIP_DIST_TEST_gho`
2016-12-09 16:12:31 INFO Ghost table altered
2016-12-09 16:12:31 INFO Waiting for ghost table to be migrated. Current lag is 0s
2016-12-09 16:12:31 INFO Intercepted changelog state GhostTableMigrated
2016-12-09 16:12:31 INFO Handled changelog state GhostTableMigrated
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x5021c6]

goroutine 1 [running]:
panic(0x679f40, 0xc4200120b0)
        /usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:500 +0x1a1
github.com/github/gh-ost/go/sql.(*ColumnList).Names(0x0, 0xc4201156b0, 0x3, 0x3)
        /Users/shlomi-noach/dev/go/src/github.com/github/gh-ost/go/sql/types.go:123 +0x26
github.com/github/gh-ost/go/logic.(*Inspector).inspectOriginalAndGhostTables(0xc42000eaa0, 0x14, 0x0)
        /Users/shlomi-noach/dev/go/src/github.com/github/gh-ost/go/logic/inspect.go:108 +0x99
github.com/github/gh-ost/go/logic.(*Migrator).Migrate(0xc42009c280, 0x0, 0x0)
        /Users/shlomi-noach/dev/go/src/github.com/github/gh-ost/go/logic/migrator.go:308 +0x58c
main.main()
        /Users/shlomi-noach/dev/go/src/github.com/github/gh-ost/go/cmd/gh-ost/main.go:213 +0x1916

@shlomi-noach shlomi-noach self-assigned this Dec 10, 2016

@shlomi-noach shlomi-noach added the bug label Dec 10, 2016

@shlomi-noach

This comment has been minimized.

Copy link
Collaborator

commented Dec 10, 2016

I like(?) it how the stack trace shows the path on my personal dev machine.

@shlomi-noach

This comment has been minimized.

Copy link
Collaborator

commented Dec 10, 2016

@ramkireddy can you please specify:

  • gh-ost --version

  • What is the original table schema?

@ramkireddy

This comment has been minimized.

Copy link
Author

commented Dec 10, 2016

hi,

[root@dom-use-sand1mysql-04 gh-ost]# ./gh-ost --version
1.0.30

mysql> show create table ZIP_DIST_TEST \G
*************************** 1. row ***************************
       Table: ZIP_DIST_TEST
Create Table: CREATE TABLE `ZIP_DIST_TEST` (
  `ZIP1` char(5) DEFAULT NULL,
  `ZIP2` char(5) DEFAULT NULL,
  `DISTANCE` double(10,5) DEFAULT NULL,
  KEY `IDX_ZIP_DIST_ZIP1` (`ZIP1`,`ZIP2`,`DISTANCE`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
@ggunson

This comment has been minimized.

Copy link
Contributor

commented Dec 10, 2016

@ramkireddy gh-ost requires that a table have a unique or primary key:

The two before & after tables must share some UNIQUE KEY. Such key would be used by gh-ost to iterate the table.

That wouldn't explain the runtime error, though.

@shlomi-noach shlomi-noach referenced this issue Dec 11, 2016

Merged

fix: bailing out on no PRIMARY/UNIQUE KEY #333

4 of 4 tasks complete
@shlomi-noach

This comment has been minimized.

Copy link
Collaborator

commented Dec 11, 2016

This is the source of the runtime error: https://github.com/github/gh-ost/pull/333/files#diff-5aa50dde7ca1baf7a819eecf740ea220L98

After fixing, and on your table, gh-ost will bail out saying:

2016-12-11 02:18:50 FATAL No PRIMARY nor UNIQUE key found in table! Bailing out

and this is the expected behavior.

@ramkireddy

This comment has been minimized.

Copy link
Author

commented Dec 12, 2016

@shlomi-noach, Thanks for all the fixes!, I am going to try and build the tool from the source soon and give it a try!

I didn't realize that this table din't had a primary key/unique key this is one of the handful of tables that we don't have a primary key! out of 800+ tables we have.

Only other major issue that see coming in the way would be the tool unable to handle the foreign key, we rely heavily on foreign keys for data integrity, but I am sure if we start using gh-ost we might slowly try to get rid off Fkeys as we come across them.

@shlomi-noach

This comment has been minimized.

Copy link
Collaborator

commented Dec 12, 2016

@ramkireddy re: foreign keys, someone was just asking: #331

@shlomi-noach shlomi-noach changed the title Runtime error when trying to ALTER a table Runtime error when trying to ALTER a table without PRIMARY KEY / UNIQUE KEY Dec 13, 2016

@shlomi-noach

This comment has been minimized.

Copy link
Collaborator

commented Dec 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.