What can I do to prevent write-write conflicts on a wiki-style website?

后端 未结 8 1623
借酒劲吻你
借酒劲吻你 2021-02-03 12:44

On a wiki-style website, what can I do to prevent or mitigate write-write conflicts while still allowing the site to run quickly and keeping the site easy to use?

The pr

相关标签:
8条回答
  • 2021-02-03 13:19

    Your problem (lost update) is solved best using Optimistic Concurrency Control.

    One implementation is to add a version column in each editable entity of the system. On user edit you load the row and display the html form on the user. A hidden field gives the version, let's say 3. The update query needs to look something like:

    update articles set ..., version=4 where id=14 and version=3;
    

    If rows returned is 0 then someone has already updated article 14. All you need to do then is how to deal with the situation. Some common solutions:

    1. last commit wins
    2. first commit wins
    3. merge conflicting updates
    4. let the user decide

    Instead of an incrementing version int/long you can use a timestamp but it's not suggested because:

    retrieving the current time from the JVM isn't necessarily safe in a clustered environment, where nodes may not be time synchronized.

    (quote from Java Persistence with Hibernate)

    Some more info at the hibernate documentation.

    0 讨论(0)
  • 2021-02-03 13:21

    In Mediawiki, the server accepts the first change, and then when the second edit is saved a conflicts page comes up, and then the second person merges the two changes together. See Wikipedia: Help:Edit Conflicts

    0 讨论(0)
提交回复
热议问题