[
https://issues.apache.org/jira/browse/CASSANDRA-20074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17898572#comment-17898572
]
Stefan Miklosovic commented on CASSANDRA-20074:
-----------------------------------------------
[~dnk] I noticed something as I was going to merge this ...
Why do we use "MonotonicClock.Global.preciseTime.now()" instead of
"Clock.Global.nanoTime" ? We use that import in that class already. What is the
difference between these two? Should not we just use "Clock.Global.nanoTime" as
well for this field if we want to have nanos? What's the deal with monotonic
clock that we have to use that?
> AbstractCommitLogService#lastSyncedAt initialized with currentTimeMillis()
> but later compared and updated with System.nanoTime()
> ---------------------------------------------------------------------------------------------------------------------------------
>
> Key: CASSANDRA-20074
> URL: https://issues.apache.org/jira/browse/CASSANDRA-20074
> Project: Cassandra
> Issue Type: Bug
> Components: Local/Commit Log
> Reporter: Dmitry Konstantinov
> Assignee: Dmitry Konstantinov
> Priority: Low
> Fix For: 4.0.x, 4.1.x, 5.0.x, 5.x
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> Within org.apache.cassandra.db.commitlog.AbstractCommitLogService
> we use System.currentMillis()-based time to initialize lastSyncedAt field:
> {code:java}
> protected volatile long lastSyncedAt = currentTimeMillis();{code}
> but later we use clock.now() = System.nanoTime() to compare and update the
> field value:
> {code:java}
> long pollStarted = clock.now();
> boolean flushToDisk = lastSyncedAt + syncIntervalNanos <= pollStarted ||
> state != NORMAL || syncRequested; {code}
> As of now we are lucky that in the current JDK implementations
> System.nanoTime() is much bigger than currentTimeMillis() but it is not
> guaranteed by a specification of the API. If nanoTime() <
> currentTimeMillis() then we can stuck without sync of commit log to disk.
> So, we need to align the time sources and change the init logic to:
> {code:java}
> protected volatile long lastSyncedAt = preciseTime.now();{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]