I'm creating a system that involves the reservation of tickets by many users within a short period of time with only a certain number of reservations possible in total. Say 600 tickets available, potentially all being reserved in 3 hour period or less.
Ideally I want to ensure the limit of reservations is not reached so before creating a reservation I am checking whether it's possible to make the reservation against the number of tickets available. Crucially I need to make sure no updates take places between that check and assigning the tickets to a user, to be sure the ticket limit won't be exceeded.
I'm trying to use mysql table write locks to achieve this however am running into problems implementing this within the codeigniter framework. Within the model handling this I've created several functions, one for creating the reservation and others for counting numbers of different types of tickets. The problem is that they don't seem to be sharing the same database sessions as they ticket counting functions are locking up.
The order of execution is
- run $this->model_name->create_reservation in controller
- run lock query in model_name->create_reservation
- call counting method in model_name->create_reservation
- counting function (which is a method in the model_name class) locks up, presumably because using different database session?
The database library is loaded in the model __construct method with $this->load->database();
Any ideas?