Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wojciechwojcik opened this issue Feb 21, 2020 · 1 comment
Closed

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

wojciechwojcik opened this issue Feb 21, 2020 · 1 comment

Comments

@wojciechwojcik
Copy link

wojciechwojcik commented Feb 21, 2020

Starting from Java 11 the default precision of Instant.now() has been raised for some OSes from milis to nano. See similar issue: h2database/h2database#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:

  • Version: 0.4.1
  • Storage Backend: cassandra
  • Mixed Index Backend:
  • Mailing list Thread URL:
  • Steps to Reproduce:
    Try any g.tx().commit() while using OpenJDK 11 under Windows

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
Copy link
Contributor

mad commented Jun 9, 2020

fixed here #2126

@mad mad closed this as completed Jun 9, 2020
@porunov porunov added this to the Release v0.6.0 milestone Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants