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

Advisory lock name easily exceeds length limit with MySQL 5.7 #231

Closed
hut8 opened this issue Sep 27, 2016 · 3 comments
Closed

Advisory lock name easily exceeds length limit with MySQL 5.7 #231

hut8 opened this issue Sep 27, 2016 · 3 comments

Comments

@hut8
Copy link
Contributor

hut8 commented Sep 27, 2016

Hey. This doesn't affect MariaDB, which I use on my development machine, but unfortunately on MySQL 5.7 there's a length limit of 64 characters on locks. So I wound up with this error during a migration:

Mysql2::Error: Incorrect user-level lock name 'ClosureTree::CreateFrobulatorServiceTypeHierarchies::FrobulatorServiceType'.:
SELECT GET_LOCK('ClosureTree::CreateFrobulatorServiceTypeHierarchies::FrobulatorServiceType', 0) AS tdf2f8c4cdfaa43bc9026d2d607d0b5e7

I know that 64 seems like a pretty high limit, but the code in support_attributes.rb always prepends ClosureTree::, then (at least in my experience) Rails migrations tend to have very long names (CreateACertainTypeOfThing...), and it's best practice (or so I've heard) to redefine a stub model inside of that class (in case its implementation changes a lot after the migration runs). So in a migration, it's easy to exceed the length limit and it bit me today. And because MySQL doesn't have transactional DDL, it's especially painful to clean up after 😦

Potential Solution

Would you be open to a different implementation of https://github.com/mceachen/closure_tree/blob/master/lib/closure_tree/support_attributes.rb#L9 , perhaps one which uses the first 30 or so characters of the MD5 of the existing implementation?

@mceachen
Copy link
Collaborator

Using an md5 or sha1 of the lock name sounds good to me. Perhaps add it as an option?

I'm afraid I don't have time to add this feature, but I welcome pull requests!

@hut8
Copy link
Contributor Author

hut8 commented Oct 8, 2016

Opened #234 for this

@hut8
Copy link
Contributor Author

hut8 commented Oct 8, 2016

Thanks!

@hut8 hut8 closed this as completed Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants