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

Add support for CREATE TABLE LIKE #91

Closed

Conversation

clifff
Copy link
Contributor

@clifff clifff commented Dec 24, 2018

We are using pg_chameleon to replicate data from a MySQL DB that ingests data from a third party, and noticed that replication crashed whenever we got a CREATE TABLE table LIKE other_table queries.

Rollbar backtrace:

The replica process crashed.
 Source: mysql
 Stack trace: Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pg_chameleon/lib/global_lib.py", line 487, in read_replica
    self.mysql_source.read_replica()
  File "/usr/local/lib/python3.5/dist-packages/pg_chameleon/lib/mysql_lib.py", line 1336, in read_replica
    replica_data=self.__read_replica_stream(batch_data)
  File "/usr/local/lib/python3.5/dist-packages/pg_chameleon/lib/mysql_lib.py", line 1157, in __read_replica_stream
    sql_tokeniser.parse_sql(binlogevent.query)
  File "/usr/local/lib/python3.5/dist-packages/pg_chameleon/lib/sql_util.py", line 489, in parse_sql
    create_parsed=self.parse_create_table(stat_cleanup, stat_dic["name"])
  File "/usr/local/lib/python3.5/dist-packages/pg_chameleon/lib/sql_util.py", line 278, in parse_create_table
    inner_stat = m_inner.group(1).strip()
AttributeError: 'NoneType' object has no attribute 'group'

I was able to recreate this locally using a Docker mysql container run with docker run --env MYSQL_ALLOW_EMPTY_PASSWORD=true -p 3306:3306 -v $(pwd)/tests/my5.7.cnf:/etc/mysql/my.cnf -v $(pwd)/sakila-db:/docker-entrypoint-initdb.d mysql:5.7 and mysql -u root -h 127.0.0.1 -e "DROP TABLE IF EXISTS clone_actor; CREATE TABLE clone_actor LIKE actor" sakila

I think this adds full support for the CREATE TABLE LIKE syntax, although for our purposes, it's outside the whitelist of tables we want to replicate so my main goal here is to prevent the process from crashing.

table_dic = {}

like_match = self.m_like.search(sql_create)
if like_match is not None:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the not None in the check?
using if like_match: should do the same and in a clearer way

@Iced-Sun
Copy link

Isn't this already merged?

@clifff
Copy link
Contributor Author

clifff commented Dec 5, 2019

Isn't this already merged?

I don't believe so. AWS DMS ended up being a better solution for my use case than pg_chameleon, so I don't plan on making any updates to this PR. Will close for now, but if anyone wants to fork/update to get it merged, feel free.

@clifff clifff closed this Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants