Skip to content

Commit 415542a

Browse files
committed
Merge remote-tracking branch 'elastic/master' into pr/39224
* elastic/master: Ensure index commit released when testing timeouts (elastic#39273) Avoid using TimeWarp in TransformIntegrationTests. (elastic#39277) Fixed missed stopping of SchedulerEngine (elastic#39193) [CI] Mute CcrRetentionLeaseIT.testRetentionLeaseIsRenewedDuringRecovery (elastic#39269) Muting AutoFollowIT.testAutoFollowManyIndices (elastic#39264) Clarify the use of sleep in CCR test Fix testCannotShrinkLeaderIndex (elastic#38529) Fix CCR tests that manipulate transport requests Align generated release notes with doc standards (elastic#39234) Mute test (elastic#39248) ReadOnlyEngine should update translog recovery state information (elastic#39238) Wrap accounting breaker check in assertBusy (elastic#39211) Simplify and Fix Synchronization in InternalTestCluster (elastic#39168) [Tests] Make testEngineGCDeletesSetting deterministic (elastic#38942) Extend nextDoc to delegate to the wrapped doc-value iterator for date_nanos (elastic#39176) Change ShardFollowTask to reuse common serialization logic (elastic#39094) Replace superfluous usage of Counter with Supplier (elastic#39048) Disable bwc tests for elastic#39094
2 parents 75fb1f2 + cb9dc28 commit 415542a

File tree

35 files changed

+570
-382
lines changed

35 files changed

+570
-382
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ task verifyVersions {
162162

163163
boolean bwc_tests_enabled = true
164164
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
165-
166165
if (bwc_tests_enabled == false) {
167166
if (bwc_tests_disabled_issue.isEmpty()) {
168167
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

buildSrc/src/main/resources/forbidden/es-server-signatures.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ java.nio.channels.FileChannel#read(java.nio.ByteBuffer, long)
6161
@defaultMessage Use Lucene.parseLenient instead it strips off minor version
6262
org.apache.lucene.util.Version#parseLeniently(java.lang.String)
6363

64-
@defaultMessage Spawns a new thread which is solely under lucenes control use ThreadPool#estimatedTimeInMillisCounter instead
64+
@defaultMessage Spawns a new thread which is solely under lucenes control use ThreadPool#relativeTimeInMillis instead
6565
org.apache.lucene.search.TimeLimitingCollector#getGlobalTimerThread()
6666
org.apache.lucene.search.TimeLimitingCollector#getGlobalCounter()
6767

@@ -146,4 +146,4 @@ org.apache.logging.log4j.Logger#warn(java.lang.Object, java.lang.Throwable)
146146
org.apache.logging.log4j.Logger#error(java.lang.Object)
147147
org.apache.logging.log4j.Logger#error(java.lang.Object, java.lang.Throwable)
148148
org.apache.logging.log4j.Logger#fatal(java.lang.Object)
149-
org.apache.logging.log4j.Logger#fatal(java.lang.Object, java.lang.Throwable)
149+
org.apache.logging.log4j.Logger#fatal(java.lang.Object, java.lang.Throwable)

dev-tools/es_release_notes.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ sub dump_issues {
8787
:pull: https://github.com/${User_Repo}pull/
8888
8989
[[release-notes-$version]]
90-
== $version Release Notes
90+
== {es} version $version
9191
9292
coming[$version]
9393
94-
Also see <<breaking-changes-$branch>>.
94+
Also see <<breaking-changes-$branch,Breaking changes in $branch>>.
9595
9696
ASCIIDOC
9797

libs/dissect/src/test/java/org/elasticsearch/dissect/DissectParserTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public void testBasicMatch() {
127127
assertMatch(delimiterFirstPattern, delimiterFirstInput, expectedKeys, expectedValues);
128128
}
129129

130+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39244")
130131
public void testBasicMatchUnicode() {
131132
String valueFirstInput = "";
132133
String keyFirstPattern = "";

server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.Version;
3535
import org.elasticsearch.common.lucene.Lucene;
3636
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
37+
import org.elasticsearch.common.util.concurrent.ReleasableLock;
3738
import org.elasticsearch.core.internal.io.IOUtils;
3839
import org.elasticsearch.index.mapper.MapperService;
3940
import org.elasticsearch.index.seqno.SeqNoStats;
@@ -287,18 +288,7 @@ public Translog.Snapshot newChangesSnapshot(String source, MapperService mapperS
287288

288289
@Override
289290
public Translog.Snapshot readHistoryOperations(String source, MapperService mapperService, long startingSeqNo) throws IOException {
290-
return new Translog.Snapshot() {
291-
@Override
292-
public void close() { }
293-
@Override
294-
public int totalOperations() {
295-
return 0;
296-
}
297-
@Override
298-
public Translog.Operation next() {
299-
return null;
300-
}
301-
};
291+
return newEmptySnapshot();
302292
}
303293

304294
@Override
@@ -429,7 +419,15 @@ public int fillSeqNoGaps(long primaryTerm) {
429419
}
430420

431421
@Override
432-
public Engine recoverFromTranslog(TranslogRecoveryRunner translogRecoveryRunner, long recoverUpToSeqNo) {
422+
public Engine recoverFromTranslog(final TranslogRecoveryRunner translogRecoveryRunner, final long recoverUpToSeqNo) {
423+
try (ReleasableLock lock = readLock.acquire()) {
424+
ensureOpen();
425+
try (Translog.Snapshot snapshot = newEmptySnapshot()) {
426+
translogRecoveryRunner.run(this, snapshot);
427+
} catch (final Exception e) {
428+
throw new EngineException(shardId, "failed to recover from empty translog snapshot", e);
429+
}
430+
}
433431
return this;
434432
}
435433

@@ -468,4 +466,22 @@ protected void processReaders(IndexReader reader, IndexReader previousReader) {
468466
public boolean refreshNeeded() {
469467
return false;
470468
}
469+
470+
private Translog.Snapshot newEmptySnapshot() {
471+
return new Translog.Snapshot() {
472+
@Override
473+
public void close() {
474+
}
475+
476+
@Override
477+
public int totalOperations() {
478+
return 0;
479+
}
480+
481+
@Override
482+
public Translog.Operation next() {
483+
return null;
484+
}
485+
};
486+
}
471487
}

server/src/main/java/org/elasticsearch/index/fielddata/plain/SortedNumericDVIndexFieldData.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public long nextValue() throws IOException {
177177
public int docValueCount() {
178178
return dv.docValueCount();
179179
}
180+
181+
@Override
182+
public int nextDoc() throws IOException {
183+
return dv.nextDoc();
184+
}
180185
};
181186
}
182187

server/src/main/java/org/elasticsearch/search/DefaultSearchContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.apache.lucene.search.Collector;
2525
import org.apache.lucene.search.FieldDoc;
2626
import org.apache.lucene.search.Query;
27-
import org.apache.lucene.util.Counter;
2827
import org.elasticsearch.Version;
2928
import org.elasticsearch.action.search.SearchTask;
3029
import org.elasticsearch.action.search.SearchType;
@@ -82,13 +81,14 @@
8281
import java.util.HashMap;
8382
import java.util.List;
8483
import java.util.Map;
84+
import java.util.function.LongSupplier;
8585

8686
final class DefaultSearchContext extends SearchContext {
8787

8888
private final long id;
8989
private final ShardSearchRequest request;
9090
private final SearchShardTarget shardTarget;
91-
private final Counter timeEstimateCounter;
91+
private final LongSupplier relativeTimeSupplier;
9292
private SearchType searchType;
9393
private final Engine.Searcher engineSearcher;
9494
private final BigArrays bigArrays;
@@ -159,7 +159,7 @@ final class DefaultSearchContext extends SearchContext {
159159

160160
DefaultSearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget,
161161
Engine.Searcher engineSearcher, ClusterService clusterService, IndexService indexService,
162-
IndexShard indexShard, BigArrays bigArrays, Counter timeEstimateCounter, TimeValue timeout,
162+
IndexShard indexShard, BigArrays bigArrays, LongSupplier relativeTimeSupplier, TimeValue timeout,
163163
FetchPhase fetchPhase, Version minNodeVersion) {
164164
this.id = id;
165165
this.request = request;
@@ -176,7 +176,7 @@ final class DefaultSearchContext extends SearchContext {
176176
this.indexService = indexService;
177177
this.clusterService = clusterService;
178178
this.searcher = new ContextIndexSearcher(engineSearcher, indexService.cache().query(), indexShard.getQueryCachingPolicy());
179-
this.timeEstimateCounter = timeEstimateCounter;
179+
this.relativeTimeSupplier = relativeTimeSupplier;
180180
this.timeout = timeout;
181181
this.minNodeVersion = minNodeVersion;
182182
queryShardContext = indexService.newQueryShardContext(request.shardId().id(), searcher.getIndexReader(), request::nowInMillis,
@@ -804,8 +804,8 @@ public ObjectMapper getObjectMapper(String name) {
804804
}
805805

806806
@Override
807-
public Counter timeEstimateCounter() {
808-
return timeEstimateCounter;
807+
public long getRelativeTimeInMillis() {
808+
return relativeTimeSupplier.getAsLong();
809809
}
810810

811811
@Override

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ private DefaultSearchContext createSearchContext(ShardSearchRequest request, Tim
648648
Engine.Searcher engineSearcher = indexShard.acquireSearcher(source);
649649

650650
final DefaultSearchContext searchContext = new DefaultSearchContext(idGenerator.incrementAndGet(), request, shardTarget,
651-
engineSearcher, clusterService, indexService, indexShard, bigArrays, threadPool.estimatedTimeInMillisCounter(), timeout,
651+
engineSearcher, clusterService, indexService, indexShard, bigArrays, threadPool::relativeTimeInMillis, timeout,
652652
fetchPhase, clusterService.state().nodes().getMinNodeVersion());
653653
boolean success = false;
654654
try {

server/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.lucene.search.Collector;
2323
import org.apache.lucene.search.FieldDoc;
2424
import org.apache.lucene.search.Query;
25-
import org.apache.lucene.util.Counter;
2625
import org.elasticsearch.action.search.SearchTask;
2726
import org.elasticsearch.action.search.SearchType;
2827
import org.elasticsearch.common.unit.TimeValue;
@@ -508,8 +507,8 @@ public ObjectMapper getObjectMapper(String name) {
508507
}
509508

510509
@Override
511-
public Counter timeEstimateCounter() {
512-
return in.timeEstimateCounter();
510+
public long getRelativeTimeInMillis() {
511+
return in.getRelativeTimeInMillis();
513512
}
514513

515514
@Override

server/src/main/java/org/elasticsearch/search/internal/SearchContext.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.lucene.search.Collector;
2323
import org.apache.lucene.search.FieldDoc;
2424
import org.apache.lucene.search.Query;
25-
import org.apache.lucene.util.Counter;
2625
import org.elasticsearch.action.search.SearchTask;
2726
import org.elasticsearch.action.search.SearchType;
2827
import org.elasticsearch.common.Nullable;
@@ -395,7 +394,11 @@ public final boolean hasOnlySuggest() {
395394

396395
public abstract ObjectMapper getObjectMapper(String name);
397396

398-
public abstract Counter timeEstimateCounter();
397+
/**
398+
* Returns time in milliseconds that can be used for relative time calculations.
399+
* WARN: This is not the epoch time.
400+
*/
401+
public abstract long getRelativeTimeInMillis();
399402

400403
/** Return a view of the additional query collectors that should be run for this context. */
401404
public abstract Map<Class<?>, Collector> queryCollectors();

server/src/main/java/org/elasticsearch/search/internal/SubSearchContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.elasticsearch.search.internal;
2020

2121
import org.apache.lucene.search.Query;
22-
import org.apache.lucene.util.Counter;
2322
import org.elasticsearch.common.unit.TimeValue;
2423
import org.elasticsearch.index.query.ParsedQuery;
2524
import org.elasticsearch.search.aggregations.SearchContextAggregations;
@@ -354,7 +353,7 @@ public FetchSearchResult fetchResult() {
354353
}
355354

356355
@Override
357-
public Counter timeEstimateCounter() {
356+
public long getRelativeTimeInMillis() {
358357
throw new UnsupportedOperationException("Not supported");
359358
}
360359

server/src/main/java/org/elasticsearch/search/query/QueryPhase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.lucene.search.Sort;
3838
import org.apache.lucene.search.TopDocs;
3939
import org.apache.lucene.search.TotalHits;
40-
import org.apache.lucene.util.Counter;
4140
import org.elasticsearch.action.search.SearchTask;
4241
import org.elasticsearch.common.lucene.Lucene;
4342
import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore;
@@ -213,12 +212,11 @@ static boolean execute(SearchContext searchContext,
213212

214213
final Runnable timeoutRunnable;
215214
if (timeoutSet) {
216-
final Counter counter = searchContext.timeEstimateCounter();
217-
final long startTime = counter.get();
215+
final long startTime = searchContext.getRelativeTimeInMillis();
218216
final long timeout = searchContext.timeout().millis();
219217
final long maxTime = startTime + timeout;
220218
timeoutRunnable = () -> {
221-
final long time = counter.get();
219+
final long time = searchContext.getRelativeTimeInMillis();
222220
if (time > maxTime) {
223221
throw new TimeExceededException();
224222
}

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.logging.log4j.LogManager;
2323
import org.apache.logging.log4j.Logger;
2424
import org.apache.logging.log4j.message.ParameterizedMessage;
25-
import org.apache.lucene.util.Counter;
2625
import org.elasticsearch.Version;
2726
import org.elasticsearch.common.Nullable;
2827
import org.elasticsearch.common.io.stream.StreamInput;
@@ -162,7 +161,8 @@ public Collection<ExecutorBuilder> builders() {
162161
}
163162

164163
public static Setting<TimeValue> ESTIMATED_TIME_INTERVAL_SETTING =
165-
Setting.timeSetting("thread_pool.estimated_time_interval", TimeValue.timeValueMillis(200), Setting.Property.NodeScope);
164+
Setting.timeSetting("thread_pool.estimated_time_interval",
165+
TimeValue.timeValueMillis(200), TimeValue.ZERO, Setting.Property.NodeScope);
166166

167167
public ThreadPool(final Settings settings, final ExecutorBuilder<?>... customBuilders) {
168168
assert Node.NODE_NAME_SETTING.exists(settings);
@@ -252,10 +252,6 @@ public long absoluteTimeInMillis() {
252252
return cachedTimeThread.absoluteTimeInMillis();
253253
}
254254

255-
public Counter estimatedTimeInMillisCounter() {
256-
return cachedTimeThread.counter;
257-
}
258-
259255
public ThreadPoolInfo info() {
260256
return threadPoolInfo;
261257
}
@@ -538,7 +534,6 @@ public String toString() {
538534
static class CachedTimeThread extends Thread {
539535

540536
final long interval;
541-
final TimeCounter counter;
542537
volatile boolean running = true;
543538
volatile long relativeMillis;
544539
volatile long absoluteMillis;
@@ -548,29 +543,42 @@ static class CachedTimeThread extends Thread {
548543
this.interval = interval;
549544
this.relativeMillis = TimeValue.nsecToMSec(System.nanoTime());
550545
this.absoluteMillis = System.currentTimeMillis();
551-
this.counter = new TimeCounter();
552546
setDaemon(true);
553547
}
554548

555549
/**
556550
* Return the current time used for relative calculations. This is
557551
* {@link System#nanoTime()} truncated to milliseconds.
552+
* <p>
553+
* If {@link ThreadPool#ESTIMATED_TIME_INTERVAL_SETTING} is set to 0
554+
* then the cache is disabled and the method calls {@link System#nanoTime()}
555+
* whenever called. Typically used for testing.
558556
*/
559557
long relativeTimeInMillis() {
560-
return relativeMillis;
558+
if (0 < interval) {
559+
return relativeMillis;
560+
}
561+
return TimeValue.nsecToMSec(System.nanoTime());
561562
}
562563

563564
/**
564565
* Return the current epoch time, used to find absolute time. This is
565566
* a cached version of {@link System#currentTimeMillis()}.
567+
* <p>
568+
* If {@link ThreadPool#ESTIMATED_TIME_INTERVAL_SETTING} is set to 0
569+
* then the cache is disabled and the method calls {@link System#currentTimeMillis()}
570+
* whenever called. Typically used for testing.
566571
*/
567572
long absoluteTimeInMillis() {
568-
return absoluteMillis;
573+
if (0 < interval) {
574+
return absoluteMillis;
575+
}
576+
return System.currentTimeMillis();
569577
}
570578

571579
@Override
572580
public void run() {
573-
while (running) {
581+
while (running && 0 < interval) {
574582
relativeMillis = TimeValue.nsecToMSec(System.nanoTime());
575583
absoluteMillis = System.currentTimeMillis();
576584
try {
@@ -581,19 +589,6 @@ public void run() {
581589
}
582590
}
583591
}
584-
585-
private class TimeCounter extends Counter {
586-
587-
@Override
588-
public long addAndGet(long delta) {
589-
throw new UnsupportedOperationException();
590-
}
591-
592-
@Override
593-
public long get() {
594-
return relativeMillis;
595-
}
596-
}
597592
}
598593

599594
static class ExecutorHolder {

0 commit comments

Comments
 (0)