Commit graph

623 commits

Author SHA1 Message Date
Dmitry Cherniachenko
e21a4874ab
Use String.replace() instead of replaceAll() for non-regexp replacements (#105127)
* Use String.replace() instead of replaceAll() for non-regexp replacements

When arguments do not make use of regexp features replace() is a more efficient option, especially the char-variant.
2024-02-12 13:11:15 -05:00
Armin Braun
842915701d
Faster ref-count logic for when ref-counted object does not escape (#105338)
Introducing a plain version of `AbstractRefCounted` as a compromise.
This saves a bunch of allocations and a circular reference to the object
holding the ref counted instance, making smaller SearchHit instances
etc. cheaper. We could get an even more direct solution here by making
these extend `AbstractRefCounted` but that would lose us the ability to
leak-track in tests, so doing it this way (same way Netty does it on
their end) as a compromise.
2024-02-10 14:50:12 +01:00
Ryan Ernst
dd51f6b187
Add classpath based SPI for jna native provider (#105320)
Native lib provider is normally run modular, but since tests run on the
classpath it also needs to work with old style SPI.
2024-02-08 17:31:57 -08:00
Armin Braun
cf27a501aa
Introduce StreamInput.readSlicedBytesReference (#105262)
This is mainly added as a prerequisite to slicing doc sources out of
bulk index requests. The few usages for it added in this PR have limited
performance impact but demonstrate correct functioning of the
implementations.

Co-authored-by: David Turner <david.turner@elastic.co>
2024-02-09 02:30:30 +01:00
Dmitry Cherniachenko
263ea5e987
Replace generic HashSet / HashMap with more efficient EnumSet / EnumMap (#105238) 2024-02-08 13:43:14 +00:00
Ryan Ernst
6375e9f443
Add native access library (#105100)
Elasticsearch requires access to some native functions. Historically
this has been achieved with the JNA library. However, JNA is a
complicated, magical library, and has caused various problems booting
Elasticsearch over the years. The new Java Foreign Function and Memory
API allows access to call native functions directly from Java. It also
has the advantage of tight integration with hotspot which can improve
performance of these functions (though performance of Elasticsearch's
native calls has never been much of an issue since they are mostly at
boot time).

This commit adds a new native lib that is internal to Elasticsearch. It
is built to use the foreign function api starting with Java 21, and
continue using JNA with Java versions below that.

Only one function, checking whether Elasticsearch is running as root, is
migrated. Future changes will migrate other native functions.
2024-02-07 18:27:09 -05:00
Ryan Ernst
18a1ac09e7
Use open and fstat in preallocate (#105171)
Preallocate opens a FileInputStream in order to get a native file
desctiptor to pass to native functions. However, getting at the file
descriptor requires breaking modular access. This commit adds native
posix functions for opening/closing and retrieving stats on a file in
order to avoid requiring additional permissions.
2024-02-07 13:40:05 -05:00
Ryan Ernst
2ca6df71d6
Make ProviderLocator aware of boot qualified exports (#105250)
Qualfied exports in the boot layer only work when they are to other boot
modules. Yet Elasticsearch has dynamically loaded modules as in plugins.
For this purpose we have ModuleQualifiedExportsService. This commit
moves loading of ModuleQualfiedExportService instances in the boot layer
into core so that it can be reused by ProviderLocator when a qualified
export applies to an embedded module.
2024-02-07 09:43:22 -08:00
David Turner
3b7b86c507
Simplify ChunkedToXContentHelper#singleChunk (#105225)
There's no need for this helper to take more than one argument. Almost
all the usages only passed in a single argument, and the few cases that
supplied more than one can be rewritten as a single argument to save
allocating all those extra lambdas.
2024-02-07 03:53:02 -05:00
Ryan Ernst
b250f06b09
Add a gradle plugin for embedded providers (#105094)
x-content embeds its jackson implementation inside its jar. This commit
formalizes the setup for this embedding with a gradle plugin so that it
can be reused by other libs.
2024-02-05 15:21:52 -05:00
Armin Braun
18bd6c4238
Fix Releasables.close performance issues (#104970)
It's less code and it actually inlines (avoiding virtual calls in most
cases) to just do the null check here instead of delegating to IOUtils
and then catching the impossible IOException. Also, no need to use
`Releaseables` in 2 spots where try-with-resources works as well and
needs less code.

Noticed this when I saw that we had a lot of strange CPU overhead in
this call in some hot loops like translog writes.
2024-01-31 08:21:59 -05:00
Armin Braun
50bafd306c
Save allocating enum values array in two hot spots (#104952)
Our readEnum code instantiates/clones enum value arrays on read.
Normally, this doesn't matter much but the two spots adjusted here are
visibly hot during bulk indexing, causing GBs of allocations during e.g.
the http_logs indexing run.
2024-01-31 11:26:36 +01:00
Ryan Ernst
d5e727e362
Add plugin for creating MRJARs (#104883)
This commit adds an elasticsearch gradle plugin which sets up a project
to build an MRJAR. By applying the plugin, the src dir is checked for
any directories matching mainXX where XX is the java version number.
A source set is automatically setup, an appropriate compiler tied to
that source set, and it's output placed in the correct part of the final
jar. Additionally, the sourceset allows use of preview features in that
verison of Java, and the preview bits are stripped from the resulting
class files.
2024-01-29 21:06:19 -08:00
Jan Kuipers
5dec83f69e
Endpoint to test Grok pattern (#104394)
* Add extract match ranges functionality to Grok.

* TestGrokPatternAction and Request

* TestGrokPattern response

* Update docs/changelog/104394.yaml

* Polish validation error message

* Improve test_grok_pattern API

* Add explicit CharSet

* Add endpoint to operator constants

* Add TransportTestGrokPatternActionTests

* REST API spec

* One more TransportTestGrokPatternActionTest

* Fix API spec

* Refactor REST API spec

* Polish code

* Replace TransportTestGrokPatternActionTests by a YAML REST test

* Add ecs_compatibility

* Always return arrays in the API

* Documentation

* YAML test for ecs_compatibility

* Rename doc fileø

* serverless scope

* Fix docs (hopefully)

* Update docs/reference/rest-api/index.asciidoc

Co-authored-by: István Zoltán Szabó <istvan.szabo@elastic.co>

* Add "text structure APIs" header in docs TOC

* Move file

* Remove test grok from main index

* typo

* Nested APIs underneath text structure

---------

Co-authored-by: István Zoltán Szabó <istvan.szabo@elastic.co>
2024-01-24 09:35:59 +01:00
William Brafford
d07651f8b9
Checkstyle: require braces around do, for, and while clauses (#103217)
* Checkstyle requires braces after for, do, while
2024-01-09 16:03:45 -05:00
Simon Cooper
0d53be3bed
Expand uses of matchers for Optionals (#104123)
Also add variants to assert for specific values
2024-01-09 12:55:29 +00:00
Ryan Ernst
2f5247117e
Upgrade ASM to 9.6 for Java 22 support (#104085)
This commit upgrades the version of asm used by the build and plugins in
order to support Java 22 version format.

closes #104065 relates #103963
2024-01-08 15:03:40 -05:00
Stuart Tettemer
a359b1f648
Relax limit on max string size in CBOR, Smile, YAML (#103930)
Remove the rough limit on string length from Jackson 2.15. The limit was already relaxed for JSON in #96031, this extends that change to other XContent types.

Refs: #96031
Fixes: #104009
2024-01-08 13:31:54 -06:00
Ignacio Vera
a6b36eb20a
Add the possibility to transform WKT to WKB directly (#104030)
enhancement to geo utilities.
2024-01-08 16:10:32 +01:00
Armin Braun
78c365fc96
Introduce a noop, never-released ref counted constant (#103931)
This is needed for the search response pooling work. Also, the one usage
in `ReleasableBytesReference` actually makes outright sense. We
shouldn't be ref-counting on a global constant, that just needlessly
introduces contention that isn't entirely obvious. This change required
a couple tests to be adjusted where we were checking release mechanics
on noop instances.
2024-01-04 13:33:07 -05:00
David Turner
6c13a815bd
Refcount responses in TransportNodesAction (#103254)
Today we `decRef()` the per-node responses just after adding them to the
`responses` collection, but in fact we should keep them alive until
we've constructed the final response. This commit does that.
2024-01-02 13:38:02 +00:00
Moritz Mack
9f8088daec
Adjust terminal tests to new behavior in JDK 22. (#103614)
JDK 22 may return a console even if the terminal is redirected. These cases are detected using the new Console#isTerminal() to maintain the current behavior (closes #98033).
2023-12-21 14:36:53 +01:00
Armin Braun
49f1b5b787
Make sure to close XContentParser in more spots (#103504)
We're leaking quite a few of these parsers. That doesn't seem to be much
of a problem but results in some memory inefficiencies in Jackson here
and there. This PR bulk fixes a bunch of instances that I could easily
automatically fix. I'll open a follow-up for closing the parser on the
document parsing context which also suffers from this but is non-trivial
to fix.
2023-12-19 10:26:06 +01:00
Armin Braun
1b84ea7421
Delete all unused private methods (#98111)
Pretty straight forward dead-code cleanup I think. Just delete all
private methods or methods in private classes that aren't used.
2023-11-25 22:21:59 +01:00
David Turner
b2127ec2f9
Introduce RefCounted#mustIncRef (#102515)
In several places we acquire a ref to a resource that we are certain is
not closed, so this commit adds a utility for asserting this to be the
case. This also helps a little with mocks since boolean methods like
`tryIncRef()` return `false` on mock objects by default, but void
methods like `mustIncRef()` default to being a no-op.
2023-11-23 16:40:43 -05:00
David Turner
5e20253fe8
Add @UpdateForV9 markers on versions (#102441)
We probably wouldn't forget these, but for the sake of completeness this
commit marks several lists of versions with the `@UpdateForV9`
annotation.
2023-11-22 08:09:34 +00:00
Jake Landis
17a46a6e9f
upgrade bouncy castle jars (#100923)
This commit upgrades the Bouncy Castle jars. Bouncy Castle is used for 
some internal build concners as well as a comnand line application. 
Most notably Bouncy Castle is also used as the FIPs certified JCE/JSEE provider 
we use to test our ability to use a FIPs compliant crypto provider. 

The following changes here are a result of the upgraded Bouncy Castle jars:
* TLSv1.3 is now supported when running in FIPs mode 
* RSA PKCS#1 v1.5 is no longer allowed in FIPS mode
* Triple DES (3DES) is no longer allowed in FIPS mode
* Minor updates the security manager configuration used to test FIPs (to read permissions from the security provider)
* Minor adjustments to tests to accommodate the above changes. 
* Minor adjustments to the gradle build to accommodate new dependencies 

Note - update to the documentation will come in a later commit.
2023-11-21 11:14:41 -06:00
Alexander Spies
92fb7780f9
ESQL: Make blocks ref counted (#100408)
This allows to replace deep copying of blocks by simply calling
Block::incRef - the block then has to be closed (or decRefed) one
additional time for each call to incRef (and tryIncRef, if successfull).
2023-11-20 14:09:15 +01:00
Ignacio Vera
c579ab2d4a
Remove HighLevelRestClient from CCSDuelIT (#102222) 2023-11-16 12:18:03 +01:00
Lorenzo Dematté
71238981c8
Create version-specific helper for poison pills (#101767)
* Add static assertRemoveBeforeV9()

* Switch from assertion to annotation + some usage examples

* Fixup ReplicationTracker

* Update name, use annotation on fields

---------

Co-authored-by: David Turner <david.turner@elastic.co>
2023-11-15 09:21:32 +01:00
William Brafford
8e6e0e59ea
Make some classes final to avoid suppressing "this-escape" warning (#101699)
* Avoid "this-escape" by making classes final

The "this-escape" compiler warning is intended to alert
developers to potential bugs in object initialization due to
subclassing. This class of bugs cannot occur when a class is
final. Here, we take cases where a class has no implementations
but generates a "this-escape" warning, and we make those
classes final rather than suppressing the compiler warning.
This makes the remaining suppressions more meaningful, since
they now indicate places where we may want to look for
initialization bugs.

In a few cases, making a class final meant changing some of its
protected fields and methods to private or default
accessibility.

Some classes with no implementations are mocked in testing.
Since making those classes final would involve non-trivial
rewrites of tests, I've left them alone.

* Spotless, remove redundant modifiers, clean up "protected" usage

* Revert a few more mocked classes
2023-11-02 08:34:02 -04:00
Rene Groeschke
f7ba5efcb0
Fix generation of xcontent provider Manifest (#101200)
Fixes #101191
2023-10-23 06:35:02 -04:00
Rene Groeschke
d9ca42bf7d
Use custom task implementation for use generate manifest (#101165)
Follow up on #101161 to make this behave better when using gradle
configuration cache
2023-10-19 17:18:21 -04:00
Ignacio Vera
9fb550be44
WellKnownBinary#toWKB should not throw an IOException (#100669)
The only reason this method is throwing an exception is because the
method ByteArrayOutputStream#close() is declaring it although it is a
noop. Therefore it can be safely ignored.

Thanks @romseygeek for bringing into attention.
2023-10-11 08:24:32 -04:00
Armin Braun
b7eafce32c
Make some practically static methods static (#97565)
Another round of automated fixes to this, marking things that can be
made static as static. Saves some JIT cycles but also turns some lambdas
from capturing to non-capturing and makes the "utilityness" of some
classes visible.
2023-10-06 23:37:07 +02:00
Nik Everett
0e219307f2
ESQL: Track blocks (#100025)
This tracks blocks from topn and a few other places. We're going to try
and track blocks all the places.
2023-09-28 13:17:08 -04:00
Tim Vernum
d411acecbc
Suppress this-escape warning for JDK21 (#99848)
Adds @SuppressWarnings("this-escape") to all necessary places to that
Elasticsearch can compile with -Werror on JDK21

No investigation has been done to determine whether any of the cases
are a potential source of errors - we have simply suppressed all
existing occurrences.

Resolves: #99845
2023-09-25 18:30:21 +10:00
Kostas Krikellas
0247cfe442
Use long in Centroid count (#99491)
* Use long in Centroid count

Centroids currently use integers to track how many samples their mean
tracks. This can overflow in case the digest tracks billions of samples
or more.

TDigestState already serializes the count as VLong, so it can be read as
VInt without compatibility issues.

Fixes #80153

* Update docs/changelog/99491.yaml

* More test fixes

* Bump TransportVersion

* Revert TransportVersion change
2023-09-13 17:37:34 +03:00
Armin Braun
16dd1e69e9
Add some type specific overrides to XContentBuilder (#99110)
We can add a couple more overrides here that resolve just fine to avoid
the slow `field(Object)` path here and there.
2023-09-01 08:01:13 +02:00
Armin Braun
37d55dac1c
Speed up String array writes to XContent (#98957)
Jackson has a direct method for writing string arrays
that saves us some of the indirection we have when looping
over a string array. This normally doesn't gain much, but for extreme
cases like long index name lists in field caps it saves a couple percent
in CPU time.
2023-08-30 12:02:41 +02:00
Ryan Ernst
a9e6da7336
Don't use test name in jarhell test (#98950)
This commit fixes a jarhell test to create an unnamed temp dir, instead
of the existing creation which uses the test method name. The reason
this causes problems is when running with many iterations, the test
method name is artificially adjusted to include seed information, using
special characters that are potentially invalid path characters.

closes #98949
2023-08-28 14:02:42 -07:00
Matteo Piergiovanni
392c497551
Automatically flatten objects when subobjects:false (#97972)
While ingesting documents that contain nested objects and the
mapping property subobjects is set to false instead of throwing
a mapping exception and dropping the document(s), we map only
leaf field(s) with their full path as their name separated by dots.
2023-08-24 18:28:57 +02:00
Chris Hegarty
7e884239f1
Make GrokCaptureType public (#97659) 2023-07-14 10:31:30 +01:00
Kostas Krikellas
816c857b46
Simplify TDigestTests.testFewValues (#97407)
TDigests are known to be inaccurate when they only contain a
handful of singletons.
2023-07-06 11:35:34 +03:00
Rene Groeschke
b8627079b4
Update Gradle Wrapper to 8.2 (#96686)
- Convention usage has been deprecated and was fixed in our build files
- Fix test dependencies and deprecation
2023-07-04 15:35:15 +02:00
Armin Braun
63e64ae61b
Cleanup Stream usage in various spots (#97306)
Lots of spots where we did weird things around streams like redundant stream creation, redundant collecting
before adding all the collected elements to another collection or so, redundant streams for joining strings
and using less efficient `Collectors.toList` and in a few cases also incorrectly relying on the result being mutable.
2023-07-03 14:24:57 +02:00
Chris Hegarty
f59035eb7b
Update plugin cli/scanner to ASM 9.5 (#97296)
This commit updates the plugin cli and scanner components to use ASM 9.5.

The update is required to successfully test with JDK 21. Tests in this component programatically run the java source compiler, which generates class files with major version 65, then tries to parse those generated class files. Without this change the tests fail with java.lang.IllegalArgumentException: Unsupported class file major version 65.
2023-07-01 20:29:10 +01:00
Mary Gouseti
f87c2c7758
Introduce downsampling configuration for data stream lifecycle (#97041)
This PR introduces downsampling configuration to the data stream lifecycle. Keep in mind downsampling implementation will come in a follow up PR. Configuration looks like this:
```
{
  "lifecycle": {
    "data_retention": "90d",
    "downsampling": [
      {
        "after": "1d",
        "fixed_interval": "2h"
      },
      { "after": "15d", "fixed_interval": "1d" },
      { "after": "30d", "fixed_interval": "1w" }
    ]
  }
}
```
We will also support using `null` to unset downsampling configuration during template composition:
```
{
  "lifecycle": {
    "data_retention": "90d",
    "downsampling": null
  }
}
```
2023-06-29 16:41:17 +03:00
Kostas Krikellas
d984a14f66
Skip SortingDigest when merging a large digest in HybridDigest (#97099)
* Skip SortingDigest when merging a large digest in HybridDigest.

This is a small performance optimization that avoids creating an
intermediate SortingDigest when merging a digest tracking many samples.
The current behavior is to keep adding values to SortingDigest until we
cross the threshold for switching to MergingDigest, at which point we
copy all values from SortingDigest to MergingDigest and release the
former.

As a side cleanup, remove the methods for adding a list of digests. It's
not used anywhere and it can be tricky to get right - the current
implementation for HybridDigest is buggy.

* Update docs/changelog/97099.yaml
2023-06-26 15:16:04 +03:00
Chris Hegarty
bdd38c6876
Add exit code to CLI failure termination message (#97004)
Add exit code to CLI failure termination message, to help with loopy diagnosis.
2023-06-22 11:56:16 +01:00