Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-20074

AbstractCommitLogService#lastSyncedAt initialized with currentTimeMillis() but later compared and updated with System.nanoTime()

    XMLWordPrintableJSON

Details

    Description

      Within org.apache.cassandra.db.commitlog.AbstractCommitLogService

      we use System.currentMillis()-based time to initialize lastSyncedAt field:

      protected volatile long lastSyncedAt = currentTimeMillis();

      but later we use clock.now() = System.nanoTime() to compare and update the field value:

      long pollStarted = clock.now();
      boolean flushToDisk = lastSyncedAt + syncIntervalNanos <= pollStarted || state != NORMAL || syncRequested; 

      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:

      protected volatile long lastSyncedAt = preciseTime.now();

      Attachments

        Issue Links

          Activity

            People

              dnk Dmitry Konstantinov
              dnk Dmitry Konstantinov
              Dmitry Konstantinov
              Branimir Lambov, Stefan Miklosovic
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h