-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix resync request serialization #27418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0a98db6
Fix resync request serialization
jasontedor 04fe32c
Remove writable
jasontedor 72964b2
Rename methods
jasontedor e6b51e4
Nit
jasontedor 9e5e810
Fix indentation
jasontedor 7333e04
Assert!
jasontedor 4113e60
Symmetry
jasontedor abe6285
More symmetry
jasontedor 29dd62a
Iteration
jasontedor 42ee8af
Javadocs
jasontedor 22a223b
Bail ASAP
jasontedor a9cfe36
Explain
jasontedor 918aa79
More Javadocs
jasontedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/test/java/org/elasticsearch/action/resync/ResyncReplicationRequestTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.action.resync; | ||
|
|
||
| import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.lucene.uid.Versions; | ||
| import org.elasticsearch.index.Index; | ||
| import org.elasticsearch.index.VersionType; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.index.translog.Translog; | ||
| import org.elasticsearch.test.ESTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class ResyncReplicationRequestTests extends ESTestCase { | ||
|
|
||
| public void testSerialization() throws IOException { | ||
| final byte[] bytes = "{}".getBytes(Charset.forName("UTF-8")); | ||
| final Translog.Index index = new Translog.Index("type", "id", 0, Versions.MATCH_ANY, VersionType.INTERNAL, bytes, null, null, -1); | ||
| final ShardId shardId = new ShardId(new Index("index", "uuid"), 0); | ||
| final ResyncReplicationRequest before = new ResyncReplicationRequest(shardId, new Translog.Operation[]{index}); | ||
|
|
||
| final BytesStreamOutput out = new BytesStreamOutput(); | ||
| before.writeTo(out); | ||
|
|
||
| final StreamInput in = out.bytes().streamInput(); | ||
| final ResyncReplicationRequest after = new ResyncReplicationRequest(); | ||
| after.readFrom(in); | ||
|
|
||
| assertThat(after, equalTo(before)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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't we keep the
Writeableand instead force each of the impls to serialize the type? I also wonder if we should rather make it an abstract class and impl. the default writing part inOperation. That way we can keep usingwrite/readListwhich I'd prefer. The reading part can still be a privat ctor, +1 to 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.
+1 to this.
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.
@s1monw We can do that, but then there's still the possibility of mistakenly calling the inner write implementations from within
Translog.java(because now there will be a visible abstractwritemethod onOperationwhereas with what we have here there is no such method). I wonder if this is enough to address keeping serialization simple (i.e., not a manual iteration):Then we can keep the inner
writemethod that should never be invoked except fromwriteOperationoff of the abstractOperation.What do you think?
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.
Actually we can make it slightly cleaner with:
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.
what is wrong with this:
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.
writeable is the interface we should use for this. there is no reason to add another abstraction for it. we have a special case here so special case 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 guess somebody has to move... so lets go with this but please make
ResyncReplicationRequest#operationsand array 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.
@s1monw There's no new abstraction being added here, only reusing existing ones? The only addition is a method that serializes an array with a
Writer<T>(the functional interface is not new) but that only makes it symmetric with an existing method to de-serialize an array with aReader<T>.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 am talking about the writeArray method. Anyway go for 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.
Thanks @s1monw. I pushed, can you take another look? I am happy to keep iterating on this if you feel differently after seeing the change.