@@ -139,7 +139,7 @@ protected NodeGatewayStartedShards nodeOperation(NodeRequest request) {
139
139
} catch (Exception exception ) {
140
140
logger .trace ("{} can't open index for shard [{}] in path [{}]" , exception , shardId , shardStateMetaData , (shardPath != null ) ? shardPath .resolveIndex () : "" );
141
141
String allocationId = shardStateMetaData .allocationId != null ? shardStateMetaData .allocationId .getId () : null ;
142
- return new NodeGatewayStartedShards (clusterService .localNode (), shardStateMetaData .version , allocationId , exception );
142
+ return new NodeGatewayStartedShards (clusterService .localNode (), shardStateMetaData .version , allocationId , shardStateMetaData . primary , exception );
143
143
}
144
144
}
145
145
// old shard metadata doesn't have the actual index UUID so we need to check if the actual uuid in the metadata
@@ -150,11 +150,11 @@ protected NodeGatewayStartedShards nodeOperation(NodeRequest request) {
150
150
} else {
151
151
logger .debug ("{} shard state info found: [{}]" , shardId , shardStateMetaData );
152
152
String allocationId = shardStateMetaData .allocationId != null ? shardStateMetaData .allocationId .getId () : null ;
153
- return new NodeGatewayStartedShards (clusterService .localNode (), shardStateMetaData .version , allocationId );
153
+ return new NodeGatewayStartedShards (clusterService .localNode (), shardStateMetaData .version , allocationId , shardStateMetaData . primary );
154
154
}
155
155
}
156
156
logger .trace ("{} no local shard info found" , shardId );
157
- return new NodeGatewayStartedShards (clusterService .localNode (), -1 , null );
157
+ return new NodeGatewayStartedShards (clusterService .localNode (), -1 , null , false );
158
158
} catch (Exception e ) {
159
159
throw new ElasticsearchException ("failed to load started shards" , e );
160
160
}
@@ -279,18 +279,20 @@ public static class NodeGatewayStartedShards extends BaseNodeResponse {
279
279
280
280
private long version = -1 ;
281
281
private String allocationId = null ;
282
+ private boolean primary = false ;
282
283
private Throwable storeException = null ;
283
284
284
285
public NodeGatewayStartedShards () {
285
286
}
286
- public NodeGatewayStartedShards (DiscoveryNode node , long version , String allocationId ) {
287
- this (node , version , allocationId , null );
287
+ public NodeGatewayStartedShards (DiscoveryNode node , long version , String allocationId , boolean primary ) {
288
+ this (node , version , allocationId , primary , null );
288
289
}
289
290
290
- public NodeGatewayStartedShards (DiscoveryNode node , long version , String allocationId , Throwable storeException ) {
291
+ public NodeGatewayStartedShards (DiscoveryNode node , long version , String allocationId , boolean primary , Throwable storeException ) {
291
292
super (node );
292
293
this .version = version ;
293
294
this .allocationId = allocationId ;
295
+ this .primary = primary ;
294
296
this .storeException = storeException ;
295
297
}
296
298
@@ -302,6 +304,10 @@ public String allocationId() {
302
304
return this .allocationId ;
303
305
}
304
306
307
+ public boolean primary () {
308
+ return this .primary ;
309
+ }
310
+
305
311
public Throwable storeException () {
306
312
return this .storeException ;
307
313
}
@@ -311,6 +317,7 @@ public void readFrom(StreamInput in) throws IOException {
311
317
super .readFrom (in );
312
318
version = in .readLong ();
313
319
allocationId = in .readOptionalString ();
320
+ primary = in .readBoolean ();
314
321
if (in .readBoolean ()) {
315
322
storeException = in .readThrowable ();
316
323
}
@@ -321,6 +328,7 @@ public void writeTo(StreamOutput out) throws IOException {
321
328
super .writeTo (out );
322
329
out .writeLong (version );
323
330
out .writeOptionalString (allocationId );
331
+ out .writeBoolean (primary );
324
332
if (storeException != null ) {
325
333
out .writeBoolean (true );
326
334
out .writeThrowable (storeException );
0 commit comments