Skip to content

Commit 7fed99a

Browse files
committed
Disable time cache on interval == 0
1 parent a1fadb1 commit 7fed99a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

server/src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,22 +550,39 @@ static class CachedTimeThread extends Thread {
550550
this.absoluteMillis = System.currentTimeMillis();
551551
this.counter = new TimeCounter();
552552
setDaemon(true);
553+
if (interval <= 0) {
554+
this.running = false;
555+
}
553556
}
554557

555558
/**
556559
* Return the current time used for relative calculations. This is
557560
* {@link System#nanoTime()} truncated to milliseconds.
561+
* <p>
562+
* If {@link ThreadPool#ESTIMATED_TIME_INTERVAL_SETTING} is set to 0
563+
* then the cache is disabled and the method calls {@link System#nanoTime()}
564+
* whenever called. Typically used for testing.
558565
*/
559566
long relativeTimeInMillis() {
560-
return relativeMillis;
567+
if (running) {
568+
return relativeMillis;
569+
}
570+
return TimeValue.nsecToMSec(System.nanoTime());
561571
}
562572

563573
/**
564574
* Return the current epoch time, used to find absolute time. This is
565575
* a cached version of {@link System#currentTimeMillis()}.
576+
* <p>
577+
* If {@link ThreadPool#ESTIMATED_TIME_INTERVAL_SETTING} is set to 0
578+
* then the cache is disabled and the method calls {@link System#currentTimeMillis()}
579+
* whenever called. Typically used for testing.
566580
*/
567581
long absoluteTimeInMillis() {
568-
return absoluteMillis;
582+
if (running) {
583+
return absoluteMillis;
584+
}
585+
return System.currentTimeMillis();
569586
}
570587

571588
@Override

server/src/test/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public List<Setting<?>> getSettings() {
134134
@Override
135135
protected Settings nodeSettings(int nodeOrdinal) {
136136
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
137-
.put("thread_pool.estimated_time_interval", TimeValue.timeValueMillis(1))
137+
.put("thread_pool.estimated_time_interval", 0)
138138
.build();
139139
}
140140

0 commit comments

Comments
 (0)