問題描述
集群環境中的重複數據問題 (Duplicate data issue over clustered environment)
假設在集群環境中有一個包含 4 個實例的應用程序。現在多個用戶正在添加員工數據。您如何確保員工數據不會重複?後台生成employeeid。
參考解法
方法 1:
You can use Optimistic locking
Optimistic Locking is a strategy where you read a record, take note of a version number (other methods to do this involve dates, timestamps or checksums/hashes) and check that the version hasn't changed before you write the record back. When you write the record back you filter the update on the version to make sure it's atomic. (i.e. hasn't been updated between when you check the version and write the record to the disk) and update the version in one hit.
(by Amit Choudhary、ABHAY JOHRI)