Concurrent Insert / Update of data over multiple processors
843854Nov 3 2003 — edited Nov 4 2003Hi All,
I am developing a Java application which is distributed over several processors (physically different machines, all win2K). This is all being done with the J2SE 1.4 version. What I have is say 4 application servers which all access a single database server (at this stage SQL Svr 2000).
For the most part everything works fine. However at one point in time all the the servers are accessing a single table on the database, and they are all updating the table (that is both updating and inserting into the table).
Now because of the large volume of data the process is broken down into 3 basic steps.
1. Read in the existing table data.
2. Update Records which already exist in the table.
3. Insert Records which don't exist in the table.
This works fine, except that if all servers are operating on the same table I get unique key constraints when doing the insert. ie
Process A - reads in the table (which at first is empty).
Process B - reads in the table (which is at this stage empty).
Process A - processes the data and decides to insert say 100K records.
Process A - inserts the records and commits the data.
Process B - processes the data and decided to insert say 200K records (some of the same ones in process A).
Process B - inserts the records and commits the data.
Now process B will fail with a unique key constraint as some of the data is already inserted by process A.
I could resolve the problem if I could get a read lock on the table and prevent Process B from reading the table at all until A commits the data, but this does not seem possible?
Any ideas? If this is already answered somewhere please can someone point me in the right direction?
Thanks
Michael