juspay / services-flake

NixOS-like services for Nix flakes
https://community.flake.parts/services-flake
MIT License
369 stars 31 forks source link

feat(mysql): allow configuring socketDir on mysql #172

Closed attilaersek closed 6 months ago

attilaersek commented 6 months ago

Introduced a new attribute socketDir to control the UDS location. If null, defaults to dataDir to maintain backward compatibility. Covered with tests.

attilaersek commented 6 months ago

ci failure seems to be an unrelated flakiness:

Error: est> [m3 ] 2024-04-25T11:32:19.304870Z 0 [ERROR] [MY-011292] [Server] Plugin mysqlx reported: 'Preparation of I/O interfaces failed, X Protocol won't be accessible'
Error: est> [m3 ] 2024-04-25T11:32:19.304937Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/run/mysqld/mysqlx.sock' failed, can't create lock file /run/mysqld/mysqlx.sock.lock'

am i right? could you please rerun the failed jobs?

attilaersek commented 6 months ago

I merged the new m4 into the existing m2 to reduce resource pressure and I've also found out that mariadb was sensitive to the existence of the socket directory so changed the directory creation order.

shivaraj-bh commented 6 months ago

We had a similar ask in postgres, see: https://github.com/juspay/services-flake/pull/77. This was introduced because of the unix-socket length limitation. Is this the same reason to have this option here?

What happens in mysql if the socket length exceeds 100 or so characters? Does it fallback to using TCP/IP or does it crash the server?

I am asking this because, due to this behaviour we had decided to make socketDir in postgres empty by default, so that it uses TCP/IP; PR.

If that’s not a concern with MySQL, it should make sense to have it set to dataDir by default.

attilaersek commented 6 months ago

We had a similar ask in postgres, see: #77. This was introduced because of the unix-socket length limitation. Is this the same reason to have this option here?

What happens in mysql if the socket length exceeds 100 or so characters? Does it fallback to using TCP/IP or does it crash the server?

I am asking this because, due to this behaviour we had decided to make socketDir in postgres empty by default, so that it uses TCP/IP; PR.

If that’s not a concern with MySQL, it should make sense to have it set to dataDir by default.

It is the very same issue as UDS path length limitation is a system (kernel) limit and does not depend on the app itself. The current behavior (prior my change) is to always use the dataDir to store the UDS. That could cause a process crash if the user's current directory is too long, that could happen easily on build servers.

I introduced this change in way that it maintains backward compatibility with the existing behavior, so opens the socket in the dataDir.

attilaersek commented 6 months ago

I'm not a mysql expert, I'm not sure if UDS can be disabled at all, but it would require a major change in the current initialization scripts.

shivaraj-bh commented 6 months ago

I'm not a mysql expert, I'm not sure if UDS can be disabled at all, but it would require a major change in the current initialization scripts.

Right, makes sense. I could have a look at this later, in a separate PR.

In that case, this PR looks good to me

attilaersek commented 6 months ago

Let me know if you need help in future improvements! Appreciate your quick responses!

shivaraj-bh commented 6 months ago

Let me know if you need help in future improvements! Appreciate your quick responses!

Thanks! I will just quickly test it on my machine and then merge

shivaraj-bh commented 6 months ago

Works great! Thanks for the contribution