Skip to content

Commit 17f983b

Browse files
michaeljmarshalldjatnieks
authored andcommitted
CNBD-12239: Replace System.nanoTime with approxTime in SAI where appropriate (#1469)
Fixes riptano/cndb#12239 We found the System.nanoTime was using significant cpu cost, but because the timeout is high enough, we can accept the inaccuracy. - [ ] Make sure there is a PR in the CNDB project updating the Converged Cassandra version - [ ] Use `NoSpamLogger` for log lines that may appear frequently in the logs - [ ] Verify test results on Butler - [ ] Test coverage for new/modified code is > 80% - [ ] Proper code formatting - [ ] Proper title for each commit staring with the project-issue number, like CNDB-1234 - [ ] Each commit has a meaningful description - [ ] Each commit is not very long and contains related changes - [ ] Renames, moves and reformatting are in distinct commits
1 parent bddd5bb commit 17f983b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/java/org/apache/cassandra/index/sai/QueryContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.apache.cassandra.config.CassandraRelevantProperties;
2828
import org.apache.cassandra.config.DatabaseDescriptor;
2929
import org.apache.cassandra.index.sai.utils.AbortedOperationException;
30+
import org.apache.cassandra.utils.MonotonicClock;
3031

31-
import static org.apache.cassandra.utils.Clock.Global.nanoTime;
3232
import static java.lang.Math.max;
3333

3434
/**
@@ -79,12 +79,12 @@ public QueryContext()
7979
public QueryContext(long executionQuotaMs)
8080
{
8181
this.executionQuotaNano = TimeUnit.MILLISECONDS.toNanos(executionQuotaMs);
82-
queryStartTimeNanos = nanoTime();
82+
this.queryStartTimeNanos = MonotonicClock.Global.approxTime.now();
8383
}
8484

8585
public long totalQueryTimeNs()
8686
{
87-
return nanoTime() - queryStartTimeNanos;
87+
return MonotonicClock.Global.approxTime.now() - queryStartTimeNanos;
8888
}
8989

9090
// setters

src/java/org/apache/cassandra/index/sai/plan/QueryView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.apache.cassandra.io.sstable.format.SSTableReader;
4444
import org.apache.cassandra.io.sstable.format.SSTableReaderWithFilter;
4545
import org.apache.cassandra.tracing.Tracing;
46-
import org.apache.cassandra.utils.Clock;
46+
import org.apache.cassandra.utils.MonotonicClock;
4747
import org.apache.cassandra.utils.NoSpamLogger;
4848

4949
public class QueryView implements AutoCloseable
@@ -162,11 +162,11 @@ protected QueryView build()
162162
// Log about the failures
163163
if (failingSince <= 0)
164164
{
165-
failingSince = Clock.Global.nanoTime();
165+
failingSince = MonotonicClock.Global.approxTime.now();
166166
}
167-
else if (Clock.Global.nanoTime() - failingSince > TimeUnit.MILLISECONDS.toNanos(100))
167+
else if (MonotonicClock.Global.approxTime.now() - failingSince > TimeUnit.MILLISECONDS.toNanos(100))
168168
{
169-
failingSince = Clock.Global.nanoTime();
169+
failingSince = MonotonicClock.Global.approxTime.now();
170170
if (success)
171171
NoSpamLogger.log(logger, NoSpamLogger.Level.WARN, 1, TimeUnit.SECONDS,
172172
"Spinning trying to capture index reader for {}, but it was released.", index);

0 commit comments

Comments
 (0)