-
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
Remove PROTO-serialization from IndexMetaData.Custom #32749
Merged
dakrone
merged 23 commits into
elastic:master
from
imotov:remove-proto-from-indexmetadata-custom-2
Aug 30, 2018
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3f5d717
Remove PROTO-serialization from IndexMetaData.Custom (II)
imotov b8239f5
Remove automatic xcontent registry discovery
imotov 9986710
Address @dakrone's review comments
imotov d85bd10
Merge remote-tracking branch 'elastic/master' into remove-proto-from-…
imotov 290afc4
Merge remote-tracking branch 'origin/master' into remove-proto-from-i…
dakrone c1fc780
WIP
dakrone 4a95041
Merge remote-tracking branch 'origin/master' into remove-proto-from-i…
dakrone df0f86a
Remove more vestiges
dakrone f4831f2
Fix some things
dakrone 5a471f2
Fix a test
dakrone 08d3a50
AwaitsFix a test until we decide
dakrone b8c9628
Remove most of the REST-facing custom metadata parts
dakrone db11af1
More removals
dakrone ea49b8c
Merge remote-tracking branch 'origin/master' into remove-proto-from-i…
dakrone cd46e81
Implement diffs for DiffableStringMap
dakrone af115fd
Fix NativeRolesStoreTests
dakrone cdb21f9
Fix serialization for pre-7.x versions
dakrone 65c8165
Simplify DiffableStringMap
dakrone 2643723
Return an immutable map from `getCustomData(String)`
dakrone 3d15e60
Remove newline from SPI file
dakrone bf50d45
Remove logging from test
dakrone 6523d40
Add random diffing and serialization test
dakrone 81be184
Make receiving custom metadata throw real exception
dakrone 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
|
@@ -61,9 +60,9 @@ | |
import java.util.stream.Collectors; | ||
|
||
import static org.elasticsearch.action.ValidateActions.addValidationError; | ||
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; | ||
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; | ||
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream; | ||
import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS; | ||
|
||
/** | ||
* A request to create an index template. | ||
|
@@ -88,8 +87,6 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR | |
|
||
private final Set<Alias> aliases = new HashSet<>(); | ||
|
||
private Map<String, IndexMetaData.Custom> customs = new HashMap<>(); | ||
|
||
private Integer version; | ||
|
||
public PutIndexTemplateRequest() { | ||
|
@@ -353,15 +350,7 @@ public PutIndexTemplateRequest source(Map<String, Object> templateSource) { | |
} else if (name.equals("aliases")) { | ||
aliases((Map<String, Object>) entry.getValue()); | ||
} else { | ||
// maybe custom? | ||
IndexMetaData.Custom proto = IndexMetaData.lookupPrototype(name); | ||
if (proto != null) { | ||
try { | ||
customs.put(name, proto.fromMap((Map<String, Object>) entry.getValue())); | ||
} catch (IOException e) { | ||
throw new ElasticsearchParseException("failed to parse custom metadata for [{}]", name); | ||
} | ||
} | ||
throw new ElasticsearchParseException("unknown key [{}] in the template ", name); | ||
} | ||
} | ||
return this; | ||
|
@@ -395,15 +384,6 @@ public PutIndexTemplateRequest source(BytesReference source, XContentType xConte | |
return source(XContentHelper.convertToMap(source, true, xContentType).v2()); | ||
} | ||
|
||
public PutIndexTemplateRequest custom(IndexMetaData.Custom custom) { | ||
customs.put(custom.type(), custom); | ||
return this; | ||
} | ||
|
||
public Map<String, IndexMetaData.Custom> customs() { | ||
return this.customs; | ||
} | ||
|
||
public Set<Alias> aliases() { | ||
return this.aliases; | ||
} | ||
|
@@ -494,11 +474,10 @@ public void readFrom(StreamInput in) throws IOException { | |
String mappingSource = in.readString(); | ||
mappings.put(type, mappingSource); | ||
} | ||
int customSize = in.readVInt(); | ||
for (int i = 0; i < customSize; i++) { | ||
String type = in.readString(); | ||
IndexMetaData.Custom customIndexMetaData = IndexMetaData.lookupPrototypeSafe(type).readFrom(in); | ||
customs.put(type, customIndexMetaData); | ||
if (in.getVersion().before(Version.V_7_0_0_alpha1)) { | ||
// Used to be used for custom index metadata | ||
int customSize = in.readVInt(); | ||
assert customSize == 0 : "expected not to have any custom metadata"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be fatal. |
||
} | ||
int aliasesSize = in.readVInt(); | ||
for (int i = 0; i < aliasesSize; i++) { | ||
|
@@ -525,10 +504,8 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeString(entry.getKey()); | ||
out.writeString(entry.getValue()); | ||
} | ||
out.writeVInt(customs.size()); | ||
for (Map.Entry<String, IndexMetaData.Custom> entry : customs.entrySet()) { | ||
out.writeString(entry.getKey()); | ||
entry.getValue().writeTo(out); | ||
if (out.getVersion().before(Version.V_7_0_0_alpha1)) { | ||
out.writeVInt(0); | ||
} | ||
out.writeVInt(aliases.size()); | ||
for (Alias alias : aliases) { | ||
|
@@ -565,10 +542,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
} | ||
builder.endObject(); | ||
|
||
for (Map.Entry<String, IndexMetaData.Custom> entry : customs.entrySet()) { | ||
builder.field(entry.getKey(), entry.getValue(), params); | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains 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.
hmm do we need to skip the size if we are in production? I mean that assert will not trip if we run without -ea
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'm not following, do you want it to be a regular exception instead of an assert? We still need to do the
readVInt
regardless of-ea
or without, it's just the 0 size comparison that is an assert for testsThere 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 that we need to do a hard exception indeed, we won't be able to read the rest of the message at this point because we can't read the customs (no
IndexMetaData#lookupPrototypeSafe anymore
) when there are unexpected ones. That is,customSize > 0
is fatal for us.