Skip to content

Commit 50dba05

Browse files
committed
Merge remote-tracking branch 'elastic/master' into minimum-java-11
* elastic/master: Fix Failing to Handle Ex. in TransportShardBulkAction (elastic#40923) Be lenient when parsing build flavor and type on the wire (elastic#40734) Make Transport Shard Bulk Action Async (elastic#39793)
2 parents e3953c2 + 8428f9c commit 50dba05

32 files changed

+732
-475
lines changed

server/src/main/java/org/elasticsearch/Build.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public String displayName() {
5757
return displayName;
5858
}
5959

60-
public static Flavor fromDisplayName(final String displayName) {
60+
public static Flavor fromDisplayName(final String displayName, final boolean strict) {
6161
switch (displayName) {
6262
case "default":
6363
return Flavor.DEFAULT;
@@ -66,7 +66,12 @@ public static Flavor fromDisplayName(final String displayName) {
6666
case "unknown":
6767
return Flavor.UNKNOWN;
6868
default:
69-
throw new IllegalStateException("unexpected distribution flavor [" + displayName + "]; your distribution is broken");
69+
if (strict) {
70+
final String message = "unexpected distribution flavor [" + displayName + "]; your distribution is broken";
71+
throw new IllegalStateException(message);
72+
} else {
73+
return Flavor.UNKNOWN;
74+
}
7075
}
7176
}
7277

@@ -91,7 +96,7 @@ public String displayName() {
9196
this.displayName = displayName;
9297
}
9398

94-
public static Type fromDisplayName(final String displayName) {
99+
public static Type fromDisplayName(final String displayName, final boolean strict) {
95100
switch (displayName) {
96101
case "deb":
97102
return Type.DEB;
@@ -106,9 +111,14 @@ public static Type fromDisplayName(final String displayName) {
106111
case "unknown":
107112
return Type.UNKNOWN;
108113
default:
109-
throw new IllegalStateException("unexpected distribution type [" + displayName + "]; your distribution is broken");
114+
if (strict) {
115+
throw new IllegalStateException("unexpected distribution type [" + displayName + "]; your distribution is broken");
116+
} else {
117+
return Type.UNKNOWN;
118+
}
110119
}
111120
}
121+
112122
}
113123

114124
static {
@@ -119,8 +129,9 @@ public static Type fromDisplayName(final String displayName) {
119129
final boolean isSnapshot;
120130
final String version;
121131

122-
flavor = Flavor.fromDisplayName(System.getProperty("es.distribution.flavor", "unknown"));
123-
type = Type.fromDisplayName(System.getProperty("es.distribution.type", "unknown"));
132+
// these are parsed at startup, and we require that we are able to recognize the values passed in by the startup scripts
133+
flavor = Flavor.fromDisplayName(System.getProperty("es.distribution.flavor", "unknown"), true);
134+
type = Type.fromDisplayName(System.getProperty("es.distribution.type", "unknown"), true);
124135

125136
final String esPrefix = "elasticsearch-" + Version.CURRENT;
126137
final URL url = getElasticsearchCodeSourceLocation();
@@ -214,12 +225,14 @@ public static Build readBuild(StreamInput in) throws IOException {
214225
final Flavor flavor;
215226
final Type type;
216227
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
217-
flavor = Flavor.fromDisplayName(in.readString());
228+
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
229+
flavor = Flavor.fromDisplayName(in.readString(), false);
218230
} else {
219231
flavor = Flavor.OSS;
220232
}
221233
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
222-
type = Type.fromDisplayName(in.readString());
234+
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
235+
type = Type.fromDisplayName(in.readString(), false);
223236
} else {
224237
type = Type.UNKNOWN;
225238
}

server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ protected void acquireReplicaOperationPermit(final IndexShard replica,
8585
}
8686

8787
@Override
88-
protected PrimaryResult<ShardRequest, ReplicationResponse> shardOperationOnPrimary(final ShardRequest shardRequest,
89-
final IndexShard primary) throws Exception {
90-
executeShardOperation(shardRequest, primary);
91-
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
88+
protected void shardOperationOnPrimary(final ShardRequest shardRequest, final IndexShard primary,
89+
ActionListener<PrimaryResult<ShardRequest, ReplicationResponse>> listener) {
90+
ActionListener.completeWith(listener, () -> {
91+
executeShardOperation(shardRequest, primary);
92+
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
93+
});
9294
}
9395

9496
@Override
95-
protected ReplicaResult shardOperationOnReplica(final ShardRequest shardRequest, final IndexShard replica) throws Exception {
97+
protected ReplicaResult shardOperationOnReplica(final ShardRequest shardRequest, final IndexShard replica) {
9698
executeShardOperation(shardRequest, replica);
9799
return new ReplicaResult();
98100
}

server/src/main/java/org/elasticsearch/action/admin/indices/flush/TransportShardFlushAction.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.admin.indices.flush;
2121

22+
import org.elasticsearch.action.ActionListener;
2223
import org.elasticsearch.action.support.ActionFilters;
2324
import org.elasticsearch.action.support.replication.ReplicationResponse;
2425
import org.elasticsearch.action.support.replication.TransportReplicationAction;
@@ -51,11 +52,13 @@ protected ReplicationResponse newResponseInstance() {
5152
}
5253

5354
@Override
54-
protected PrimaryResult<ShardFlushRequest, ReplicationResponse> shardOperationOnPrimary(ShardFlushRequest shardRequest,
55-
IndexShard primary) {
56-
primary.flush(shardRequest.getRequest());
57-
logger.trace("{} flush request executed on primary", primary.shardId());
58-
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
55+
protected void shardOperationOnPrimary(ShardFlushRequest shardRequest, IndexShard primary,
56+
ActionListener<PrimaryResult<ShardFlushRequest, ReplicationResponse>> listener) {
57+
ActionListener.completeWith(listener, () -> {
58+
primary.flush(shardRequest.getRequest());
59+
logger.trace("{} flush request executed on primary", primary.shardId());
60+
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
61+
});
5962
}
6063

6164
@Override

server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.admin.indices.refresh;
2121

22+
import org.elasticsearch.action.ActionListener;
2223
import org.elasticsearch.action.support.ActionFilters;
2324
import org.elasticsearch.action.support.replication.BasicReplicationRequest;
2425
import org.elasticsearch.action.support.replication.ReplicationResponse;
@@ -53,11 +54,13 @@ protected ReplicationResponse newResponseInstance() {
5354
}
5455

5556
@Override
56-
protected PrimaryResult<BasicReplicationRequest, ReplicationResponse> shardOperationOnPrimary(
57-
BasicReplicationRequest shardRequest, IndexShard primary) {
58-
primary.refresh("api");
59-
logger.trace("{} refresh request executed on primary", primary.shardId());
60-
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
57+
protected void shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary,
58+
ActionListener<PrimaryResult<BasicReplicationRequest, ReplicationResponse>> listener) {
59+
ActionListener.completeWith(listener, () -> {
60+
primary.refresh("api");
61+
logger.trace("{} refresh request executed on primary", primary.shardId());
62+
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
63+
});
6164
}
6265

6366
@Override

server/src/main/java/org/elasticsearch/action/bulk/MappingUpdatePerformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.bulk;
2121

22+
import org.elasticsearch.action.ActionListener;
2223
import org.elasticsearch.index.mapper.Mapping;
2324
import org.elasticsearch.index.shard.ShardId;
2425

@@ -27,6 +28,6 @@ public interface MappingUpdatePerformer {
2728
/**
2829
* Update the mappings on the master.
2930
*/
30-
void updateMappings(Mapping update, ShardId shardId, String type);
31+
void updateMappings(Mapping update, ShardId shardId, String type, ActionListener<Void> listener);
3132

3233
}

0 commit comments

Comments
 (0)