简体   繁体   中英

How to ensure db consistency - clustered application sharing common db

I want to scale my java application by spreading it across a cluster. All nodes will share a common DB.

How can I ensure DB consistency? Is there a way to implement it without using any third party library?

I am trying to solve putIfAbsent kind of scenario. If one node is in middle of read-then-update a table row then all other nodes should stay away until first node is done.

What is the best and most simple way to implement this?

Cheers, Ravi

There is no simple way to implement this. But fortunately many others did this for you. State of the art (relational) databases provide Transactions with locking mechanisms to avoid concurrent changes that would result in inconsistencies.

Study the documentation of your DB to find out whether it supports transactions and how they can be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM