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

Migrate Search requests to use Writeable reading strategies #26428

Merged
merged 8 commits into from
Aug 30, 2017

Conversation

talevy
Copy link
Contributor

@talevy talevy commented Aug 29, 2017

This is a continuation of the Streamable -> Writeable migration. This PR focuses on
a few of the SearchRequest-related actions.

@talevy talevy added :Core/Infra/Core Core issues without another label >non-issue v7.0.0 labels Aug 29, 2017
@talevy talevy requested a review from nik9000 August 29, 2017 21:36
@@ -749,6 +755,19 @@ private static Streamable tryCreateNewInstance(Streamable streamable) throws NoS
}
}

private static Streamable tryCreateFromStream(Streamable streamable, StreamInput in) throws NoSuchMethodException,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

forgot to add javadocs here. will do that since it is a transitional solution

assertThat(constructor, Matchers.notNullValue());
Streamable newInstance = constructor.newInstance(in);
return newInstance;
} catch (Exception e) {
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 you should catch the NoSuchMethodException explicitly, otherwise this could mask an exception thrown from the ctor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call. forgot about the good ol IOException

@@ -688,7 +689,12 @@ public static void assertVersionSerializable(Version version, Streamable streama
input = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry);
}
input.setVersion(version);
newInstance.readFrom(input);
// This is here since some Streamables are being converted into Writeables
// and the readFrom method throws an exception if called
Copy link
Member

Choose a reason for hiding this comment

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

So instead you first try and deserialize from our normal ctor. Yeah, this makes sense and the way you have it rigged looks about right for a temporary measure.

@@ -749,6 +755,19 @@ private static Streamable tryCreateNewInstance(Streamable streamable) throws NoS
}
}

private static Streamable tryCreateFromStream(Streamable streamable, StreamInput in) throws NoSuchMethodException,
InstantiationException, IllegalAccessException, InvocationTargetException {
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 indent this one more time so it doesn't look like method body?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I don't think think you throw these exceptions any more since you catch and return null.

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 you might want to let InvocationTargetException bubble up instead of return null. Those are probably serialization errors.

Copy link
Member

Choose a reason for hiding this comment

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

Or, better, maybe only return null if there isn't a StreamInput ctor, otherwise you should use it.

I think when we remove the Streamable interface we'd want to remove the null return entirely and require such a constructor here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated as Ryan suggested. so now all those are thrown again. And yes, once all are migrated. the original tryCreateNewInstance will be removed

id = in.readLong();
dfs = readAggregatedDfs(in);
originalIndices = OriginalIndices.readOriginalIndices(in);
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
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 move writeTo to be under the reading ctor when you do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in general. for all of them? So we have writeTo under the last constructor for all these objects?

Copy link
Member

Choose a reason for hiding this comment

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

For all of them, yeah. I like having the write and read on close physically so I can look at them at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool. finished moving all of them

@talevy
Copy link
Contributor Author

talevy commented Aug 29, 2017

updated to reflect your comments, thanks!

try {
Class<? extends Streamable> clazz = streamable.getClass();
Constructor<? extends Streamable> constructor = clazz.getConstructor(StreamInput.class);
assertThat(constructor, Matchers.notNullValue());
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need this assertion. I think it just throws instead, right?

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I approve. Good luck getting CI to approve. Thanks for doing this.

@talevy
Copy link
Contributor Author

talevy commented Aug 30, 2017

thanks @nik9000. I missed some reindex test failures. might come up with a few more file changes to make it green

@talevy talevy merged commit ed151d8 into elastic:master Aug 30, 2017
@talevy talevy deleted the searchrequestwriteable branch August 30, 2017 18:00
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Aug 31, 2017
* master:
  Allow abort of bulk items before processing (elastic#26434)
  [Tests] Improve testing of FieldSortBuilder (elastic#26437)
  Upgrade to lucene-7.0.0-snapshot-d94a5f0. (elastic#26441)
  Implement adaptive replica selection (elastic#26128)
  Build: Quiet bwc build output (elastic#26430)
  Migrate Search requests to use Writeable reading strategies (elastic#26428)
  Changed version from 7.0.0-alpha1 to 6.1.0 in the nested sorting serialization check.
  Remove dead path conf BWC code in build
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >non-issue v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants