-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace superfluous usage of Counter with Supplier #39048
Changes from 2 commits
8339c2a
934bf9a
45b1afa
260c320
40b56d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -648,7 +648,7 @@ private DefaultSearchContext createSearchContext(ShardSearchRequest request, Tim | |
Engine.Searcher engineSearcher = indexShard.acquireSearcher(source); | ||
|
||
final DefaultSearchContext searchContext = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget, | ||
engineSearcher, clusterService, indexService, indexShard, bigArrays, threadPool.estimatedTimeInMillisCounter(), timeout, | ||
engineSearcher, clusterService, indexService, indexShard, bigArrays, threadPool.estimatedTimeInMillis(), timeout, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
fetchPhase, clusterService.state().nodes().getMinNodeVersion()); | ||
boolean success = false; | ||
try { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.ParameterizedMessage; | ||
import org.apache.lucene.util.Counter; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
|
@@ -58,6 +57,7 @@ | |
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Collections.unmodifiableMap; | ||
|
@@ -252,8 +252,8 @@ public long absoluteTimeInMillis() { | |
return cachedTimeThread.absoluteTimeInMillis(); | ||
} | ||
|
||
public Counter estimatedTimeInMillisCounter() { | ||
return cachedTimeThread.counter; | ||
public Supplier<Long> estimatedTimeInMillis() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be removed and replaced by |
||
return () -> cachedTimeThread.relativeMillis; | ||
} | ||
|
||
public ThreadPoolInfo info() { | ||
|
@@ -538,7 +538,6 @@ public String toString() { | |
static class CachedTimeThread extends Thread { | ||
|
||
final long interval; | ||
final TimeCounter counter; | ||
volatile boolean running = true; | ||
volatile long relativeMillis; | ||
volatile long absoluteMillis; | ||
|
@@ -548,7 +547,6 @@ static class CachedTimeThread extends Thread { | |
this.interval = interval; | ||
this.relativeMillis = TimeValue.nsecToMSec(System.nanoTime()); | ||
this.absoluteMillis = System.currentTimeMillis(); | ||
this.counter = new TimeCounter(); | ||
setDaemon(true); | ||
} | ||
|
||
|
@@ -581,19 +579,6 @@ public void run() { | |
} | ||
} | ||
} | ||
|
||
private class TimeCounter extends Counter { | ||
|
||
@Override | ||
public long addAndGet(long delta) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public long get() { | ||
return relativeMillis; | ||
} | ||
} | ||
} | ||
|
||
static class ExecutorHolder { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import com.carrotsearch.randomizedtesting.generators.RandomNumbers; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.lucene.util.Counter; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
|
@@ -42,6 +41,7 @@ | |
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class DeterministicTaskQueue { | ||
|
||
|
@@ -304,18 +304,8 @@ public long absoluteTimeInMillis() { | |
} | ||
|
||
@Override | ||
public Counter estimatedTimeInMillisCounter() { | ||
return new Counter() { | ||
@Override | ||
public long addAndGet(long delta) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public long get() { | ||
return currentTimeMillis; | ||
} | ||
}; | ||
public Supplier<Long> estimatedTimeInMillis() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use |
||
return () -> currentTimeMillis; | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
LongSupplier
instead