7 Replies Latest reply on May 12, 2011 3:44 AM by Adam Warski

    Envers and database replication (master-master)

    Ivan Liakhovenko Newbie

      Hi All!


      As far as I understand @RevisionNumber field must be formed from a strictly increasing sequence. That's a mandatory requirement for having the AuditReader logic to work correctly. This requirement normally doesn't cause any problem for most situations, but it does however makes AuditReader practically unusable when you're building a distributed system which is using a master-master database replication.


      My question is - is there a way for getting envers to compare revision timestamps rather than revision numbers when querying the AuditReader?


      The problem lies with generating a globally unique numbers between separate database instances. It's easy to generate a unique number, but almost impossible to generate it in a strictly increasing sequence across multiple geographic locations.


      Just to illustrate - this is how the merged RevisionInfo could look like after the changes have been replicated between databases:


      Revision from database A: rev=500, timstamp=1/1/2011

      Revision from database B: rev=50, timestamp=2/2/2011


      Because the logic is based on max(rev) then, for example, auditReader.getRevisionNumberForDate(3/3/2011) will return 500 which is incorrect, but if you use max(timestamp) then you will get the correct result - 50.


      Can anyone comment on a best option for resolving that, please?


      Many thanks,