Safe, Sequential And Scalable Counters In Mnesia

前端 未结 4 1478
旧时难觅i
旧时难觅i 2021-02-11 04:44

I am writing an application in Erlang/OTP and want to use sequential counters on a version recording system.

I first implemented them with

mnesia:dirty_update_count         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-11 05:33

    Well, since Mnesia data is not guaranteed to replicate atomicly you have to manually lock somehow. I see three alternatives (two with locking and one without):

    • Using read locks on the table as you request a new version number. That implies transactions though.

    • Use a central server that keeps track of the version numbers and increment them atomically, for example by having a process on one of your nodes which you ask for version numbers.

    • Synchronize your servers with NTP and use timestamps.

提交回复
热议问题