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

Deduplicate mappings in persisted cluster state #88479

Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
36ff00e
Deduplicate mappings in persisted cluster state
DaveCTurner May 25, 2022
213e933
Less noise in logs
DaveCTurner May 25, 2022
f0b88e8
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
DaveCTurner May 27, 2022
6e992c1
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
DaveCTurner Jun 27, 2022
e10e10c
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jun 28, 2022
2d2f135
Clean up this comment table
joegallo Jun 28, 2022
477f803
Fix this log message
joegallo Jun 28, 2022
cbbdcf2
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 6, 2022
5e39806
Add another fromXContent arity
joegallo Jun 28, 2022
2f9378d
Use numIndicesAdded to pass the indices count for isFullWrite
joegallo Jun 30, 2022
6493aed
Reword this log message
joegallo Jun 30, 2022
e32e523
Track mapping counts via WriterStats
joegallo Jun 30, 2022
ae65a22
Add MAPPING_TYPE_NAME and handle no docs (null scorer)
joegallo Jul 6, 2022
bdd9bdd
Fix this test
joegallo Jul 6, 2022
fa5acf6
Don't duplicate mappings here (and switch to constants)
joegallo Jul 6, 2022
3f53456
Add mappings to existing tests to exercise this code
joegallo Jul 6, 2022
0e8e39d
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 7, 2022
b230057
Add a file-counting mapping deduplication test
joegallo Jul 8, 2022
f3c57c9
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 8, 2022
a2638ae
Quick addendums to previous commit
joegallo Jul 11, 2022
b8d311a
Allow null mappings sometimes
joegallo Jul 12, 2022
3da3fc9
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 12, 2022
03c9781
Fix a placeholder comment :D
joegallo Jul 12, 2022
dc68507
Add tests for duplicated or missing mappings
joegallo Jul 13, 2022
197c0e4
Extract two utility methods to cut some repetition
joegallo Jul 13, 2022
29e79fe
Switch to an exception rather than an assertion
joegallo Jul 13, 2022
5f88e5c
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 13, 2022
3c6c73d
Update docs/changelog/88479.yaml
joegallo Jul 13, 2022
bd4b402
Rework null handling of random mapping metadata
joegallo Jul 18, 2022
f9973b7
Merge branch 'master' into 2022-05-25-deduplicate-mappings-in-persist…
joegallo Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/88479.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88479
summary: Deduplicate mappings in persisted cluster state
area: Cluster Coordination
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.function.Function;

import static org.elasticsearch.cluster.metadata.Metadata.CONTEXT_MODE_PARAM;
import static org.elasticsearch.cluster.metadata.Metadata.DEDUPLICATED_MAPPINGS_PARAM;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.validateIpValue;
Expand Down Expand Up @@ -480,6 +481,7 @@ public Iterator<Setting<?>> settings() {
static final String KEY_SETTINGS = "settings";
static final String KEY_STATE = "state";
static final String KEY_MAPPINGS = "mappings";
static final String KEY_MAPPINGS_HASH = "mappings_hash";
static final String KEY_ALIASES = "aliases";
static final String KEY_ROLLOVER_INFOS = "rollover_info";
static final String KEY_SYSTEM = "system";
Expand Down Expand Up @@ -1100,6 +1102,10 @@ public static IndexMetadata fromXContent(XContentParser parser) throws IOExcepti
return Builder.fromXContent(parser);
}

public static IndexMetadata fromXContent(XContentParser parser, Map<String, MappingMetadata> mappingsByHash) throws IOException {
return Builder.fromXContent(parser, mappingsByHash);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
Builder.toXContent(this, builder, params);
Expand Down Expand Up @@ -1834,7 +1840,12 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build
}
builder.endObject();

if (context != Metadata.XContentContext.API) {
if (context == Metadata.XContentContext.GATEWAY && params.paramAsBoolean(DEDUPLICATED_MAPPINGS_PARAM, false)) {
MappingMetadata mmd = indexMetadata.mapping();
if (mmd != null) {
builder.field(KEY_MAPPINGS_HASH, mmd.source().getSha256());
}
} else if (context != Metadata.XContentContext.API) {
builder.startArray(KEY_MAPPINGS);
MappingMetadata mmd = indexMetadata.mapping();
if (mmd != null) {
Expand Down Expand Up @@ -1915,6 +1926,10 @@ public static void toXContent(IndexMetadata indexMetadata, XContentBuilder build
}

public static IndexMetadata fromXContent(XContentParser parser) throws IOException {
return fromXContent(parser, null);
}

public static IndexMetadata fromXContent(XContentParser parser, Map<String, MappingMetadata> mappingsByHash) throws IOException {
if (parser.currentToken() == null) { // fresh parser? move to the first token
parser.nextToken();
}
Expand Down Expand Up @@ -2030,6 +2045,13 @@ public static IndexMetadata fromXContent(XContentParser parser) throws IOExcepti
}
case KEY_ROUTING_NUM_SHARDS -> builder.setRoutingNumShards(parser.intValue());
case KEY_SYSTEM -> builder.system(parser.booleanValue());
case KEY_MAPPINGS_HASH -> {
assert mappingsByHash != null : "no deduplicated mappings given";
if (mappingsByHash.containsKey(parser.text()) == false) {
throw new IllegalArgumentException("mapping with hash [" + parser.text() + "] not found");
}
builder.putMapping(mappingsByHash.get(parser.text()));
}
default -> throw new IllegalArgumentException("Unexpected field [" + currentFieldName + "]");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ default boolean isRestorable() {

public static final String CONTEXT_MODE_API = XContentContext.API.toString();

public static final String DEDUPLICATED_MAPPINGS_PARAM = "deduplicated_mappings";
public static final String GLOBAL_STATE_FILE_PREFIX = "global-";

private static final NamedDiffableValueSerializer<Custom> CUSTOM_VALUE_SERIALIZER = new NamedDiffableValueSerializer<>(Custom.class);
Expand Down
Loading