I need to implement a way to allow concurrent read to check whether a record has set or not. If set they just return. If not the first read process/thread will then set it based on the result it gets. The purpose of that is to run an init script only once.
If I use mysql 8.0 I think I can use SELECT ... FOR UPDATE NOWAIT so if a process/thread fails to get the lock, that means another process/thread has got it, so it can just return. The one got the lock will decide whether it needs to run the init script and update the record.
But I am using mysql 5.7, no NOWAIT and if I use SELECT ... FOR UPDATE, concurrent read become waiting for the lock one by one. I feel it is not good enough. So is it possbile to implement a home-made NOWAIT (in python) ?
My goal is to make sure the init script run just once, so if no NOWAIT, is there other way to do that ?