Reputation: 15
Preface
Users use a thick client application which connects to a Postgres database.
So, multi-user, multi-db connection environment.
Application is a simple ERP design with material stock, material procurement, production, testing, and billing modules to name a few.
Also - app is made with Delphi, using FireDAC with Postgres as a DB.
Problem
This is a legacy application and no concurrency control was ever implemented.
Well, this is a problem.
Potential solutions
1. MUTEX
After we detected concurrency errors I implemented a DB mutex and wrapped it around all hazardous app methods.
Mutex checks DB if the light is green and if so proceeds with its operation otherwise it waits for an amount of time and then tries again.
This works well, but it's not very scalable. I want other options.
2. Version control
This requires all tables to hold an additional field - version. Every update must include version value as a parameter. Version value is incremented on update either as part of the query or a DB trigger.
Update result (affected rows) must be checked against expected updated rows. If there is a mismatch, concurrency error is detected and we do a rollback.
This should be the default solution, but I need to redesign the entire app.
3. What else is there??
What else could work? All FireDAC components have some properties pertaining to the transaction locking but I have never managed to make them work, neither found a solid example.
Does anyone have any recommendations? Does a simple to implement, scalable solution even exist?
Upvotes: 1
Views: 134