When user makes a request (REST API) I want to copy N records from table source to table destination.
destination.destination select from source LIMIT N (Single query).N can be between the range 100000 - 2500000, if the user makes two request one after the other with N records then 2xN records are being inserted.
Example flow:
100 records.200 records.destination.destination.100 records)200 records)Result: There are 300 records in destination table.
I want to make sure that at any given point of time only one insertion happens.
destination table.destination table.destination table.destination table.Note that when I want to only write lock destination table only, write operations should not happen (but read operation should still happen).
Temporarily we are depending on a flag which we set in database before starting the transaction and then we unset it once the transaction completes. Any other request which arrives while the flag is set they will be terminated with a message (Process already running, please try again later)
Please help me out finding a better solution for this. Let me know if you need more details.
Thanks
You can try the below queries as follow ...
SET AUTOCOMMIT=0;
LOCK TABLES `staff` WRITE;
-- inserts start here
INSERT INTO `staff` VALUES
(2,'Jon','Snow',4,NULL,'[email protected]',2,1,'Jon',NULL,'2006-02-15 03:57:16'),
(2,'Jon','Stephens',4,NULL,'[email protected]',2,1,'Jon',NULL,'2006-02-15 03:57:16');
-- till here
UNLOCK TABLES;
COMMIT;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With