google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Versioning using timestamps is broken #289

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
morphia-0.99.jar, mongo-java-driver-2.5.3.jar, mongodb-10gen 1.8.1

Morphia's versioning is broken: version is set to current timestamp 
(milliseconds) and then naively incremented in case of match like this:

VersionHelper.java, line 13:

        long currentTimeMillis = System.currentTimeMillis();
        // very unlikely, but you never know
        if (oldVersion != null && oldVersion.longValue() == currentTimeMillis)
            currentTimeMillis++;
        return currentTimeMillis;

In fact, this is not "very unlikely", it is very much "likely" in heavy-loaded 
multithreaded environment for versions to match. I saw it first time I did 
stress test against  Morphia. 

And this renders the whole versioning useles.

I propose that Morphia should use simple increments instead of timestamping.

Original issue reported on code.google.com by Pasko.Bo...@gmail.com on 17 Jun 2011 at 7:32

GoogleCodeExporter commented 9 years ago
Yep, you are correct, this is a poor implementation esp. on a cluster where 
times are not sync'd.

Original comment by scotthernandez on 17 Jun 2011 at 7:35

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1759.

Original comment by scotthernandez on 11 Aug 2011 at 1:41