Skip to content
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

Transport: allow to de-serialize arbitrary objects given their name #12393

Closed

Conversation

javanna
Copy link
Member

@javanna javanna commented Jul 22, 2015

This commit makes it possible to serialize arbitrary objects by having them extend Writeable. When reading them though, we need to be able to identify which object we have to create, based on its name. This is useful for queries once we move to parsing on the coordinating node, as well as with aggregations and so on.

Introduced a new abstraction called NamedWriteable, which is supported by StreamOutput and StreamInput through writeNamedWriteable and readNamedWriteable methods. A new NamedWriteableRegistry is introduced also where named writeable prototypes need to be registered so that we are able to retrieve the proper instance of the writeable given its name and then de-serialize it calling readFrom against it.

Note that this same change was previously reviewed and pushed to the query-refactoring branch (#11553), the goal of this PR is to backport the change to master.

The main question is whether we should use this mechanism for exceptions or not. It seems like it would require a class per exception, maybe a bit too verbose compared to the switch that we have in StreamInput#readThrowable and StreamOutput#writeThrowable. Looking for a second opinion there.

This commit makes it possible to serialize arbitrary objects by having them extend Writeable. When reading them though, we need to be able to identify which object we have to create, based on its name. This is useful for queries once we move to parsing on the coordinating node, as well as with aggregations and so on.

Introduced a new abstraction called NamedWriteable, which is supported by StreamOutput and StreamInput through writeNamedWriteable and readNamedWriteable methods. A new NamedWriteableRegistry is introduced also where named writeable prototypes need to be registered so that we are able to retrieve the proper instance of the writeable given its name and then de-serialize it calling readFrom against it.
@colings86
Copy link
Contributor

LGTM but I'm not too familiar with the Netty stuff so might be worth getting someone to look at that bit. I don't have a strong opinion on the Throwable stuff but it might be nice if everything uses the same mechanism.

@javanna
Copy link
Member Author

javanna commented Jul 22, 2015

maybe @jpountz can have a look?

@jpountz
Copy link
Contributor

jpountz commented Jul 22, 2015

The main question is whether we should use this mechanism for exceptions or not. It seems like it would require a class per exception, maybe a bit too verbose compared to the switch that we have in StreamInput#readThrowable and StreamOutput#writeThrowable. Looking for a second opinion there.

I like the current logic as it prevents from being tempted to make exception types pluggable?

/**
* Returns the name of the writeable object
*/
String getWriteableName();
Copy link
Contributor

Choose a reason for hiding this comment

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

Or just getName()?

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 is getName on the query-refactoring branch, but then classes that implement this interface might already have a getName method (e.g. aggs), which is why I went for this more specific method name.

@jpountz
Copy link
Contributor

jpountz commented Jul 22, 2015

I'm a bit concerned that this pull request adds coupling between StreamInput and NamedWriteableRegistry on one hand, and transport modules and NamedWriteableRegistry on the other hand.

Could we only have this NamedWriteableRegistry handling in a subclass of StreamInput so that StreamInput would remain unaware of NamedWriteableRegistry? Also I think it would be cleaner if every component maintained its own registry (could be eg. one for queries, one for aggs, etc.) instead of sharing a single one for everything?

@javanna
Copy link
Member Author

javanna commented Jul 31, 2015

Replaced by #12571 .

@javanna javanna closed this Jul 31, 2015
javanna added a commit to javanna/elasticsearch that referenced this pull request Aug 6, 2015
This commit makes it possible to serialize arbitrary objects by having them extend Writeable. When reading them though, we need to be able to identify which object we have to create, based on its name. This is useful for queries once we move to parsing on the coordinating node, as well as with aggregations and so on.

Introduced a new abstraction called NamedWriteable, which is supported by StreamOutput and StreamInput through writeNamedWriteable and readNamedWriteable methods. A new NamedWriteableRegistry is introduced also where named writeable prototypes need to be registered so that we are able to retrieve the proper instance of the writeable given its name and then de-serialize it calling readFrom against it.

Closes elastic#12393
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.

None yet

3 participants