[ 
https://issues.apache.org/jira/browse/CASSANDRA-20074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17898573#comment-17898573
 ] 

Stefan Miklosovic edited comment on CASSANDRA-20074 at 11/15/24 10:49 AM:
--------------------------------------------------------------------------

oh nevermind ... I see that 
{code}
                // sync and signal
                long pollStarted = clock.now();
{code}

"clock" here is MonotonicClock and put into SyncRunnable as preciseTime

{code}
SyncRunnable sync = new SyncRunnable(preciseTime)
{code}

which is MonotonicClock.Global.preciseTime so we are good ... nevermind.

Neverthless it is probably worth it to investigate why we have two different 
source of nanos in that class. Seems suspicious at first sight. 


was (Author: smiklosovic):
oh nevermind ... I see that 
{code}
                // sync and signal
                long pollStarted = clock.now();
{code}

"clock" here is MonotonicClock and put into SyncRunnable as preciseTime

{code}
SyncRunnable sync = new SyncRunnable(preciseTime)
{code}

which is MonotonicClock.Global.preciseTime so we are good ... nevermind.

> 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]

Reply via email to