-
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
Begin moving XContent to a separate lib/artifact #29300
Conversation
This commit moves a large portion of the XContent code from the `server` project to the `libs/xcontent` project. For the pieces that have been moved, some helpers have been duplicated to allow them to be decoupled from ES helper classes. In addition, `Booleans` and `CheckedFunction` have been moved to the `elasticsearch-core` project. This decoupling is a move so that we can eventually make things like the high-level REST client not rely on the entire ES jar, only the parts it needs. There are some pieces that are still not decoupled, in particular some of the XContent tests still remain in the server project, this is because they test a large portion of the pluggable xcontent pieces through `XContentElasticsearchException`. They may be decoupled in future work. Additionally, there may be more piecese that we want to move to the xcontent lib in the future that are not part of this PR, this is a starting point. Relates to elastic#28504
Pinging @elastic/es-core-infra |
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.
I left a few things. The biggest one to me is simpleMatch
which I think we should keep in :server
if we can.
libs/xcontent/build.gradle
Outdated
dependencies { | ||
compile "org.elasticsearch:elasticsearch-core:${version}" | ||
|
||
// json and yaml |
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.
This comment doesn't help me to understand the file better. Maybe remove it?
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.
I see. It came from :server
's javadoc. I think it isn't worth keeping.
libs/xcontent/build.gradle
Outdated
testCompile "junit:junit:${versions.junit}" | ||
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}" | ||
|
||
if (isEclipse == false || project.path == ":libs:elasticsearch-xcontent-tests") { |
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.
:libs:xcontent-tests
maybe?
libs/xcontent/build.gradle
Outdated
} | ||
|
||
forbiddenApisMain { | ||
// elasticsearch-xcontent does not depend on server |
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.
s/elasticsearch-xcontent/xcontent/ i think.
libs/xcontent/build.gradle
Outdated
|
||
forbiddenApisMain { | ||
// elasticsearch-xcontent does not depend on server | ||
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core |
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.
I think you mean that we should have more forbidden signatures here than just what is in jdk-signatures
but less than everything in the normal elasticsearch signatures.
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.
If so, then that makes sense to me and I'm happy to think of that in a followup.
libs/xcontent/build.gradle
Outdated
if (isEclipse) { | ||
// in eclipse the project is under a fake root, we need to change around the source sets | ||
sourceSets { | ||
if (project.path == ":libs:elasticsearch-xcontent") { |
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.
I believe this needs the new name as well.
@@ -106,4 +108,88 @@ XContentParser createParser(NamedXContentRegistry xContentRegistry, | |||
*/ | |||
XContentParser createParser(NamedXContentRegistry xContentRegistry, | |||
DeprecationHandler deprecationHandler, Reader reader) throws IOException; | |||
|
|||
/** | |||
* Low level implementation detail of {@link XContentGenerator#copyCurrentStructure(XContentParser)}. |
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.
Should it be in the XContentGenerator
class then?
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.
That way it can be private. Which just feels better to me.
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.
This can't be private (it's used elsewhere here and in x-pack), I can move it if you want but I'm not sure it should go in Generator since it deals with both the Generator and a Parser (which is why I picked XContent)
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.
Can all the call sites call the method on XContentBuilder
? I think the difference is that that one might use jackson APIs sometimes but I'm not sure why we wouldn't want that.
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.
Can all the call sites call the method on XContentBuilder?
No, this version of copyCurrentStructure supports copying across different types of XContent (so you can copy from a CborParser into a JsonGenerator), that's the difference between using the XContentType-specific one and this generic one
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.
Oh I think I understand more what you're saying now, let me look into it and see if it can be made protected
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.
Okay, I was able to do this, it's private now.
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.
❤️
@@ -740,7 +739,8 @@ private void unknownValue(Object value, boolean ensureNoSelfReferences) throws I | |||
//Path implements Iterable<Path> and causes endless recursion and a StackOverFlow if treated as an Iterable here | |||
value((Path) value); | |||
} else if (value instanceof Map) { | |||
map((Map<String,?>) value, ensureNoSelfReferences); | |||
@SuppressWarnings("unchecked") final Map<String, ?> valueMap = (Map<String, ?>) value; |
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.
I tend to put a line break after the annotation. Force of habit, really.
return next; | ||
} | ||
return null; | ||
} | ||
|
||
/** |
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.
I don't really want to leak our "funny" simpleMatch behavior into different places. I wonder if can accept two nullable TokenFilter
s and the caller can use FilterPath
if it wants.
@@ -349,7 +349,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep | |||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, | |||
LoggingDeprecationHandler.INSTANCE, document)) { | |||
parser.nextToken(); | |||
XContentHelper.copyCurrentStructure(builder.generator(), parser); | |||
XContent.copyCurrentStructure(builder.generator(), parser); |
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.
can we call builder.copyCurrentStructure(parser)
instead?
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.
Yep, this is done now
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.
I left a few thoughts.
libs/xcontent/build.gradle
Outdated
*/ | ||
|
||
apply plugin: 'elasticsearch.build' | ||
apply plugin: 'nebula.optional-base' |
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.
Is this needed? I don't see the optional
configuration used here?
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.
This is copied from libs/elasticsearch-core
, I don't actually know what it does, should I remove it?
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.
Yes, remove (it's not needed anywhere except in server).
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.
I believe it makes it easy to declare dependencies as optional. https://github.com/nebula-plugins/gradle-extra-configurations-plugin
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.
If we aren't using it we may as well remove it so we no one gets confused.
libs/xcontent/build.gradle
Outdated
|
||
forbiddenApisMain { | ||
// elasticsearch-xcontent does not depend on server | ||
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to core |
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.
We should have a followup item to separate out forbidden signatures that are truly server specific (eg log4j apis that require server deps) and those that should really be shared by all. We already have an "es-all-signatures", that should probably be used here as a start (in addition to jdk signatures)?
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.
++
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.
This is copied from the elasticsearch-core build.gradle file, is there already a followup item for this then?
Can you explain what you mean by using the "es-all-signatures" here? (like I said, I copied it, so I'm not that familiar yet with configuring it)
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.
We have a number of different signature files. In particular, in addition to the jdk signatures provided by forbiddenapis itself, we have an "es-all" signature file that is supposed to apply across main and test code. Then we have "es-server" and "es-test". We should at least be using the es-all here I think (it only contains jdk methods, I believe). es-server is a little more convoluted, because it has mostly jdk methods, but also some ES server specific code (PathUtils.get), or ES server specific dependency code (log4j methods). So here I am suggesting starting by adding the es-all signatures file. I don't think we have an existing issue to split the signature files more, but it is worth a discussion on where the breakdown should be (how fine grained we should get).
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.
I checked into adding the es-all-signatures here, but it fails because it is checking for a Lucene forbiddenapi, which isn't on the classpath for xcontent (since no lucene dependency)
* @return the number of bytes copied | ||
* @throws IOException in case of I/O errors | ||
*/ | ||
private static long copyStream(InputStream in, OutputStream out) throws IOException { |
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.
Just a note: java 9 provides this for us, we may want to copy Streams
(at least this method) to core and then make core a MR JAR so we can make use of the java 9 method:
https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#transferTo-java.io.OutputStream-
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.
++, though maybe it'd be simpler to do that in a followup?
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.
Sounds good, I can do that in a follow up (just to keep this a bit smaller) if that's okay with you
* @param str the String to match | ||
* @return whether the String matches the given pattern | ||
*/ | ||
private static boolean simpleMatch(String pattern, String str) { |
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.
I think we should have the discussion for each of these copied methods whether it is worthwhile to move these into core. While I'm not a fan of this method (or the naming, since it is really a glob), there seem to be enough uses at a glance (at least, some that will also likely move into libs, like ingest) that it could warrant moving there.
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.
Yeah, if we're already going to want it for ingest, maybe we should move it there.
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.
Okay, I'll move this to core and rename it to have a better name (probably globMatch
)
* @param str the String to match | ||
* @return whether the String matches the given pattern | ||
*/ | ||
public static boolean globMatch(String pattern, String str) { |
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.
++
build.gradle
Outdated
@@ -196,6 +196,7 @@ subprojects { | |||
"org.elasticsearch:elasticsearch-cli:${version}": ':server:cli', | |||
"org.elasticsearch:elasticsearch-core:${version}": ':libs:elasticsearch-core', | |||
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:elasticsearch-nio', | |||
"org.elasticsearch:elasticsearch-xcontent:${version}": ':libs:xcontent', |
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.
Please make this x-content
. This is consistent with established naming conventions. Sorry.
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.
LGTM. Thank you! ❤️
@elasticmachine please run packaging tests |
run packaging tests |
This moves the method `Streams.copy(InputStream in, OutputStream out)` into the `elasticsearch-core` project (inside the `o.e.core.internal.io` package). It also makes this class into a multi-release class where the Java 9 equivalent uses `InputStream#transferTo`. This is a followup from elastic#29300 (comment)
* Begin moving XContent to a separate lib/artifact This commit moves a large portion of the XContent code from the `server` project to the `libs/xcontent` project. For the pieces that have been moved, some helpers have been duplicated to allow them to be decoupled from ES helper classes. In addition, `Booleans` and `CheckedFunction` have been moved to the `elasticsearch-core` project. This decoupling is a move so that we can eventually make things like the high-level REST client not rely on the entire ES jar, only the parts it needs. There are some pieces that are still not decoupled, in particular some of the XContent tests still remain in the server project, this is because they test a large portion of the pluggable xcontent pieces through `XContentElasticsearchException`. They may be decoupled in future work. Additionally, there may be more piecese that we want to move to the xcontent lib in the future that are not part of this PR, this is a starting point. Relates to #28504
* master: (80 commits) Remove HTTP max content length leniency (elastic#29337) Begin moving XContent to a separate lib/artifact (elastic#29300) Java versions for ci (elastic#29320) Minor cleanup in the InternalEngine (elastic#29241) Clarify expectations of false positives/negatives (elastic#27964) Update docs on vertex ordering (elastic#27963) Revert "REST high-level client: add support for Indices Update Settings API (elastic#28892)" (elastic#29323) [test] remove Streamable serde assertions (elastic#29307) Improve query string docs (elastic#28882) fix query string example for boolean query (elastic#28881) Resolve unchecked cast warnings introduced with elastic#28892 REST high-level client: add support for Indices Update Settings API (elastic#28892) Search: Validate script query is run with a single script (elastic#29304) [DOCS] Added info on WGS-84. Closes issue elastic#3590 (elastic#29305) Increase timeout on Netty client latch for tests Build: Use branch specific refspec sysprop for bwc builds (elastic#29299) TEST: trim unsafe commits before opening engine Move trimming unsafe commits from engine ctor to store (elastic#29260) Fix incorrect geohash for lat 90, lon 180 (elastic#29256) Do not load global state when deleting a snapshot (elastic#29278) ...
* master: Build: Fix Java9 MR build (elastic#29312) Reindex: Fix error in delete-by-query rest spec (elastic#29318) Improve similarity integration. (elastic#29187) Fix some query extraction bugs. (elastic#29283) [Docs] Correct experimental note formatting Move Nullable into core (elastic#29341) [Docs] Update getting-started.asciidoc (elastic#29294) Elasticsearch 6.3.0 is now on Lucene 7.3. [DOCS] Refer back to index API for full-document updates in _update API section (elastic#28677) Fix missing comma in ingest-node.asciidoc (elastic#29343) Improve exception handling on TransportMasterNodeAction (elastic#29314) Don't break allocation if resize source index is missing (elastic#29311) Use fixture to test repository-s3 plugin (elastic#29296) Fix NDCG for empty search results (elastic#29267) Pass through script params in scripted metric agg (elastic#29154) Fix Eclipse build. Upgrade to lucene-7.3.0-snapshot-98a6b3d. (elastic#29298) Painless: Remove extraneous INLINE constant. (elastic#29340) Remove HTTP max content length leniency (elastic#29337) Begin moving XContent to a separate lib/artifact (elastic#29300)
#29322) * Move Streams.copy into elasticsearch-core and make a multi-release jar This moves the method `Streams.copy(InputStream in, OutputStream out)` into the `elasticsearch-core` project (inside the `o.e.core.internal.io` package). It also makes this class into a multi-release class where the Java 9 equivalent uses `InputStream#transferTo`. This is a followup from #29300 (comment)
#29322) * Move Streams.copy into elasticsearch-core and make a multi-release jar This moves the method `Streams.copy(InputStream in, OutputStream out)` into the `elasticsearch-core` project (inside the `o.e.core.internal.io` package). It also makes this class into a multi-release class where the Java 9 equivalent uses `InputStream#transferTo`. This is a followup from #29300 (comment)
This commit moves a large portion of the XContent code from the
server
projectto the
libs/xcontent
project. For the pieces that have been moved, somehelpers have been duplicated to allow them to be decoupled from ES helper
classes. In addition,
Booleans
andCheckedFunction
have been moved to theelasticsearch-core
project.This decoupling is a move so that we can eventually make things like the
high-level REST client not rely on the entire ES jar, only the parts it needs.
There are some pieces that are still not decoupled, in particular some of the
XContent tests still remain in the server project, this is because they test a
large portion of the pluggable xcontent pieces through
XContentElasticsearchException
. They may be decoupled in future work.Additionally, there may be more piecese that we want to move to the xcontent lib
in the future that are not part of this PR, this is a starting point.
Relates to #28504