forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '8.x' into esql/backport_117878
- Loading branch information
Showing
13 changed files
with
206 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 116953 | ||
summary: Fix false positive date detection with trailing dot | ||
area: Mapping | ||
type: bug | ||
issues: | ||
- 116946 |
6 changes: 6 additions & 0 deletions
6
docs/reference/esql/functions/description/categorize.asciidoc
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
server/src/main/java/org/elasticsearch/index/mapper/IntervalThrottler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* Throttles tracked operations based on a time interval, restricting them to 1 per N seconds. | ||
*/ | ||
enum IntervalThrottler { | ||
DOCUMENT_PARSING_FAILURE(60); | ||
|
||
static final int MILLISECONDS_IN_SECOND = 1000; | ||
|
||
private final Acceptor acceptor; | ||
|
||
IntervalThrottler(long intervalSeconds) { | ||
acceptor = new Acceptor(intervalSeconds * MILLISECONDS_IN_SECOND); | ||
} | ||
|
||
/** | ||
* @return true if the operation gets accepted, false if throttled. | ||
*/ | ||
boolean accept() { | ||
return acceptor.accept(); | ||
} | ||
|
||
// Defined separately for testing. | ||
static class Acceptor { | ||
private final long intervalMillis; | ||
private final AtomicBoolean lastAcceptedGuard = new AtomicBoolean(false); | ||
private volatile long lastAcceptedTimeMillis = 0; | ||
|
||
Acceptor(long intervalMillis) { | ||
this.intervalMillis = intervalMillis; | ||
} | ||
|
||
boolean accept() { | ||
final long now = System.currentTimeMillis(); | ||
// Check without guarding first, to reduce contention. | ||
if (now - lastAcceptedTimeMillis > intervalMillis) { | ||
// Check if another concurrent operation succeeded. | ||
if (lastAcceptedGuard.compareAndSet(false, true)) { | ||
try { | ||
// Repeat check under guard protection, so that only one message gets written per interval. | ||
if (now - lastAcceptedTimeMillis > intervalMillis) { | ||
lastAcceptedTimeMillis = now; | ||
return true; | ||
} | ||
} finally { | ||
// Reset guard. | ||
lastAcceptedGuard.set(false); | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
server/src/test/java/org/elasticsearch/index/mapper/IntervalThrottlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class IntervalThrottlerTests extends ESTestCase { | ||
|
||
public void testThrottling() throws Exception { | ||
var throttler = new IntervalThrottler.Acceptor(10); | ||
assertTrue(throttler.accept()); | ||
assertFalse(throttler.accept()); | ||
assertFalse(throttler.accept()); | ||
|
||
Thread.sleep(20); | ||
assertTrue(throttler.accept()); | ||
assertFalse(throttler.accept()); | ||
assertFalse(throttler.accept()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters