JanusGraph / janusgraph

JanusGraph: an open-source, distributed graph database
https://janusgraph.org
Other
5.32k stars 1.17k forks source link

Handle Java 11 Instant.now() nano-precision #1979

Closed wojciechwojcik closed 4 years ago

wojciechwojcik commented 4 years ago

Starting from Java 11 the default precision of Instant.now() has been raised for some OSes from milis to nano. See similar issue: https://github.com/h2database/h2database/issues/1178

This makes JanusGraph TimestampProviders always uses NANO precision no matter what enum value is actually configured. Still cassandra uses MICRO precision which makes Janus timestamps incompatible - see stacktrace below.

Fixed version of TimestampProviders:

    MICRO {
        @Override
        public Instant getTime() {
            return Instant.now().truncatedTo(ChronoUnit.MICROS);
        }

        @Override
        public Instant getTime(long sinceEpoch) {
            return Instant.ofEpochSecond(0, (sinceEpoch * 1000L));
        }

        @Override
        public ChronoUnit getUnit() {
            return ChronoUnit.MICROS;
        }

        @Override
        public long getTime(Instant timestamp) {
            return timestamp.getEpochSecond() * 1000000L + timestamp.getNano()/1000;

        }
    },

    MILLI {
        @Override
        public Instant getTime() {
            return Instant.now().truncatedTo(ChronoUnit.MILLIS);
        }

        @Override
        public Instant getTime(long sinceEpoch) {
            return Instant.ofEpochMilli(sinceEpoch);
        }

        @Override
        public ChronoUnit getUnit() {
            return ChronoUnit.MILLIS;
        }

        @Override
        public long getTime(Instant timestamp) {
            return timestamp.getEpochSecond() * 1000 + timestamp.getNano() / 1000000;
        }
    };

Note lines: return Instant.now().truncatedTo(ChronoUnit.MICROS); return Instant.now().truncatedTo(ChronoUnit.MILLIS); The above two lines fix the issue.

For confirmed bugs, please report:

Stack Trace (if you have one)

2020-01-31 11:38:42.124 UTC  WARN    NONE 18172 --- [           main] o.j.d.l.c.ConsistentKeyLocker            : Skipping outdated lock on KeyColumn [k=0x 16-165-160-114-116- 30-100-105-115-112-108- 97-121- 95-110- 97-109-229, c=0x  0] with our rid ( 83- 99-104-101-109- 97- 45- 73-110-105-116- 45- 49- 53- 56- 48- 52- 55- 48- 55- 49- 56- 54- 53- 55) 
but mismatched timestamp (actual ts 2020-01-31T11:38:42.020993Z, expected ts 2020-01-31T11:38:42.020993200Z

2020-01-31 11:38:42.125 UTC ERROR    NONE 18172 --- [           main] o.j.g.d.StandardJanusGraph               : Could not commit transaction [1] due to storage exception in system-commit
org.janusgraph.core.JanusGraphException: Could not execute operation due to backend exception
    at org.janusgraph.diskstorage.util.BackendOperation.execute(BackendOperation.java:56) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction.persist(CacheTransaction.java:91) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction.flushInternal(CacheTransaction.java:139) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction.commit(CacheTransaction.java:196) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.BackendTransaction.commit(BackendTransaction.java:151) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.graphdb.database.StandardJanusGraph.commit(StandardJanusGraph.java:707) [janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.commit(StandardJanusGraphTx.java:1379) [janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.graphdb.database.management.ManagementSystem.commit(ManagementSystem.java:240) [janusgraph-core-0.3.1.jar:?]
    ...
Caused by: org.janusgraph.diskstorage.locking.PermanentLockingException: Permanent locking failure
    at org.janusgraph.diskstorage.locking.AbstractLocker.checkLocks(AbstractLocker.java:359) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction.checkAllLocks(ExpectedValueCheckingTransaction.java:175) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction.prepareForMutations(ExpectedValueCheckingTransaction.java:154) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager.mutateMany(ExpectedValueCheckingStoreManager.java:72) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction$1.call(CacheTransaction.java:94) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction$1.call(CacheTransaction.java:91) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.util.BackendOperation.executeDirect(BackendOperation.java:68) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.util.BackendOperation.execute(BackendOperation.java:54) ~[janusgraph-core-0.3.1.jar:?]
    ... 18 more
Caused by: org.janusgraph.diskstorage.PermanentBackendException: Read 1 locks with our rid  83- 99-104-101-109- 97- 45- 73-110-105-116- 45- 49- 53- 56- 48- 52- 55- 48- 55- 49- 56- 54- 53- 55 but mismatched timestamps; no lock column contained our timestamp (2020-01-31T11:38:42.020993200Z)
    at org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker.checkSeniority(ConsistentKeyLocker.java:528) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker.checkSingleLock(ConsistentKeyLocker.java:454) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker.checkSingleLock(ConsistentKeyLocker.java:118) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.AbstractLocker.checkLocks(AbstractLocker.java:351) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction.checkAllLocks(ExpectedValueCheckingTransaction.java:175) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction.prepareForMutations(ExpectedValueCheckingTransaction.java:154) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager.mutateMany(ExpectedValueCheckingStoreManager.java:72) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction$1.call(CacheTransaction.java:94) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction$1.call(CacheTransaction.java:91) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.util.BackendOperation.executeDirect(BackendOperation.java:68) ~[janusgraph-core-0.3.1.jar:?]
    at org.janusgraph.diskstorage.util.BackendOperation.execute(BackendOperation.java:54) ~[janusgraph-core-0.3.1.jar:?]
    ... 18 more
mad commented 4 years ago

fixed here https://github.com/JanusGraph/janusgraph/pull/2126