Skip to content

Conversation

@tlrx
Copy link
Member

@tlrx tlrx commented Dec 16, 2016

This commit adds the parsing fromXContent() methods to the IndexResponse class. The method is based on a ObjectParser because it is easier to reuse parsing method from parent abstract classes like DocWriteResponse.

It also changes a bit the toXContent() method of ReplicationResponse.ShardInfo so that it now starts its own object. This way, the ShardInfo.fromXContent() method can be directly referenced by the IndexResponse's ObjectParser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to review this file, it comes from #22196

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only bit that changed since #22196

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think I had made you revert this change before, but maybe it's ok because we only print this section out in one place, so the _SHARDS name doesn't get copied to other places. One thing: what does this specific change improve? That ShardInfo outputs a valid object alone?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also curious to understand where the rendering of the field was moved, I don't seem to find it in this PR. What is the outer object that is calling this toXContent Method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been moved to DocWriteResponse.innerToXContent() where

shardInfo.toXContent(builder, params);

has been changed to:

builder.field(_SHARDS, shardInfo);

so that ShardInfo is now a ToXContentObject.

This is important for the ObjectParser used to parse the IndexResponse which can then directly use ShardInfo.fromXContent(p).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change comes from #22196

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also needed to upgrade the fact that you don't expect a field name to start with right? rather a start_object straightaway

@tlrx tlrx removed the review label Dec 16, 2016
@tlrx
Copy link
Member Author

tlrx commented Dec 16, 2016

Ok I removed the "review" flag because this PR is based on #22196 and brings back/duplicates many changes. I'll rebase it once #22196 is in, it will be easier to review.

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments, no particular blockers though, looks good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this thing is so un-readable :) sorry I couldn't hold it. Loops and ifs read so much easier to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think I had made you revert this change before, but maybe it's ok because we only print this section out in one place, so the _SHARDS name doesn't get copied to other places. One thing: what does this specific change improve? That ShardInfo outputs a valid object alone?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also needed to upgrade the fact that you don't expect a field name to start with right? rather a start_object straightaway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid repeating IndexResponse in all methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use convertToMap, it uses content type auto-detection while we know the content-type upfront. just create a parser and call map against it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than using a map here, couldn't you call fromXContent again? would that make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you clarify what this method parses?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it correct to do this in IndexResponse? I am a bit confused by who does what. Given the toXContent in IndexResponse that only prints out one field, I was expecting most of the parsing to be in DocWriteResponse. That may have to do again with me not understanding ObjectParser and how it works.

@tlrx tlrx force-pushed the add-fromxcontent-methods-to-IndexResponse branch 2 times, most recently from 0d657e0 to 040ea0f Compare January 10, 2017 13:00
@tlrx
Copy link
Member Author

tlrx commented Jan 10, 2017

@javanna I updated this pull request with the latest changes in master. I'll be happy if you can have a look again.

Few things to keep in mind:

  • ShardInfo now implements ToXContentObject: it is required to get it parseable using ConstructingObjectParser in IndexResponse.
  • IndexResponse uses ObjectParser instead of the "manual" parsing because I find it easier when there is a class hierarchy like IndexResponse->DocWriteResponse

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left few minors, LGTM, @cbuescher want to have a look too? You will need shard failures in search too I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is quite odd that the only info we actually can parse back out of the ShardId is the index name. no index_uuid and no shard_id. Maybe we should look into carrying around the index name only as a follow-up in DocWriteResponse. I am not sure we need more, it doesn't seem like it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that makes sense. I can change that in a follow up PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this with Luca and we both think that we should not do this change. This would impact the serialization of DocWriteResponse in core in order to simplify things and carry less information from a client side point of view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for changing this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this randomization be enabled again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a leftover.

@tlrx tlrx force-pushed the add-fromxcontent-methods-to-IndexResponse branch from 040ea0f to 64663db Compare January 10, 2017 14:23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just to understand this: this change here only affects the toString() method, not the actual rest response?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: why does this test the toString() method, the tests seems to indicate its about the xContent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right - this is because Strings.toString() uses the toXContent method internally. I can replace this by a direct usage of toXContent.

@cbuescher
Copy link
Member

@tlrx @javanna I also had a look, left a few understanding questions but other than that LGTM. Unfortunately the ReplicationResponse.Failure that is used there is slightly different from the ShardSearchFailure that is used in the SearchResponse. I will take a close look at it but at this point I think although they are quiet similar, we need to add parsing to both of them.

@tlrx
Copy link
Member Author

tlrx commented Jan 10, 2017

@javanna @cbuescher Thanks!

tlrx added 2 commits January 10, 2017 16:37
This commit adds the parsing fromXContent() methods to the IndexResponse class. The method is based on a ObjectParser because it is easier to use when parsing parent abstract classes like DocWriteResponse.

It also changes the ReplicationResponse.ShardInfo so that it now implements ToXContentObject. This way, the ShardInfo.fromXContent() method can be used by the IndexResponse's ObjectParser.
@tlrx tlrx force-pushed the add-fromxcontent-methods-to-IndexResponse branch from 64663db to fdf0830 Compare January 10, 2017 15:37
@tlrx tlrx merged commit 2dcb05f into elastic:master Jan 10, 2017
tlrx added a commit that referenced this pull request Jan 10, 2017
This commit adds the parsing fromXContent() methods to the IndexResponse class. The method is based on a ObjectParser because it is easier to use when parsing parent abstract classes like DocWriteResponse.

It also changes the ReplicationResponse.ShardInfo so that it now implements ToXContentObject. This way, the ShardInfo.fromXContent() method can be used by the IndexResponse's ObjectParser.
@tlrx tlrx deleted the add-fromxcontent-methods-to-IndexResponse branch January 12, 2017 14:01
dadoonet added a commit to dadoonet/elasticsearch that referenced this pull request Jan 19, 2017
This commit adds the parsing fromXContent() methods to the IndexResponse class.

It's a pale copy of what has been done in elastic#22229.
dadoonet added a commit to dadoonet/elasticsearch that referenced this pull request Jan 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants