@@ -200,7 +200,7 @@ protected abstract PrimaryResult<ReplicaRequest, Response> shardOperationOnPrima
200
200
201
201
/**
202
202
* Synchronously execute the specified replica operation. This is done under a permit from
203
- * {@link IndexShard#acquireReplicaOperationPermit(long, long, ActionListener, String, Object)}.
203
+ * {@link IndexShard#acquireReplicaOperationPermit(long, long, long, ActionListener, String, Object)}.
204
204
*
205
205
* @param shardRequest the request to the replica shard
206
206
* @param replica the replica shard to perform the operation on
@@ -489,6 +489,7 @@ public void messageReceived(
489
489
replicaRequest .getTargetAllocationID (),
490
490
replicaRequest .getPrimaryTerm (),
491
491
replicaRequest .getGlobalCheckpoint (),
492
+ replicaRequest .getMaxSeqNoOfUpdatesOrDeletes (),
492
493
channel ,
493
494
(ReplicationTask ) task ).run ();
494
495
}
@@ -513,6 +514,7 @@ private final class AsyncReplicaAction extends AbstractRunnable implements Actio
513
514
private final String targetAllocationID ;
514
515
private final long primaryTerm ;
515
516
private final long globalCheckpoint ;
517
+ private final long maxSeqNoOfUpdatesOrDeletes ;
516
518
private final TransportChannel channel ;
517
519
private final IndexShard replica ;
518
520
/**
@@ -528,6 +530,7 @@ private final class AsyncReplicaAction extends AbstractRunnable implements Actio
528
530
String targetAllocationID ,
529
531
long primaryTerm ,
530
532
long globalCheckpoint ,
533
+ long maxSeqNoOfUpdatesOrDeletes ,
531
534
TransportChannel channel ,
532
535
ReplicationTask task ) {
533
536
this .request = request ;
@@ -536,6 +539,7 @@ private final class AsyncReplicaAction extends AbstractRunnable implements Actio
536
539
this .targetAllocationID = targetAllocationID ;
537
540
this .primaryTerm = primaryTerm ;
538
541
this .globalCheckpoint = globalCheckpoint ;
542
+ this .maxSeqNoOfUpdatesOrDeletes = maxSeqNoOfUpdatesOrDeletes ;
539
543
final ShardId shardId = request .shardId ();
540
544
assert shardId != null : "request shardId must be set" ;
541
545
this .replica = getIndexShard (shardId );
@@ -575,7 +579,8 @@ public void onNewClusterState(ClusterState state) {
575
579
new TransportChannelResponseHandler <>(logger , channel , extraMessage ,
576
580
() -> TransportResponse .Empty .INSTANCE );
577
581
transportService .sendRequest (clusterService .localNode (), transportReplicaAction ,
578
- new ConcreteReplicaRequest <>(request , targetAllocationID , primaryTerm , globalCheckpoint ),
582
+ new ConcreteReplicaRequest <>(request , targetAllocationID , primaryTerm ,
583
+ globalCheckpoint , maxSeqNoOfUpdatesOrDeletes ),
579
584
handler );
580
585
}
581
586
@@ -613,7 +618,7 @@ protected void doRun() throws Exception {
613
618
throw new ShardNotFoundException (this .replica .shardId (), "expected aID [{}] but found [{}]" , targetAllocationID ,
614
619
actualAllocationId );
615
620
}
616
- replica .acquireReplicaOperationPermit (primaryTerm , globalCheckpoint , this , executor , request );
621
+ replica .acquireReplicaOperationPermit (primaryTerm , globalCheckpoint , maxSeqNoOfUpdatesOrDeletes , this , executor , request );
617
622
}
618
623
619
624
/**
@@ -1023,6 +1028,11 @@ public long globalCheckpoint() {
1023
1028
return indexShard .getGlobalCheckpoint ();
1024
1029
}
1025
1030
1031
+ @ Override
1032
+ public long maxSeqNoOfUpdatesOrDeletes () {
1033
+ return indexShard .getMaxSeqNoOfUpdatesOrDeletes ();
1034
+ }
1035
+
1026
1036
@ Override
1027
1037
public ReplicationGroup getReplicationGroup () {
1028
1038
return indexShard .getReplicationGroup ();
@@ -1107,15 +1117,16 @@ public void performOn(
1107
1117
final ShardRouting replica ,
1108
1118
final ReplicaRequest request ,
1109
1119
final long globalCheckpoint ,
1120
+ final long maxSeqNoOfUpdatesOrDeletes ,
1110
1121
final ActionListener <ReplicationOperation .ReplicaResponse > listener ) {
1111
1122
String nodeId = replica .currentNodeId ();
1112
1123
final DiscoveryNode node = clusterService .state ().nodes ().get (nodeId );
1113
1124
if (node == null ) {
1114
1125
listener .onFailure (new NoNodeAvailableException ("unknown node [" + nodeId + "]" ));
1115
1126
return ;
1116
1127
}
1117
- final ConcreteReplicaRequest <ReplicaRequest > replicaRequest =
1118
- new ConcreteReplicaRequest <>( request , replica .allocationId ().getId (), primaryTerm , globalCheckpoint );
1128
+ final ConcreteReplicaRequest <ReplicaRequest > replicaRequest = new ConcreteReplicaRequest <>(
1129
+ request , replica .allocationId ().getId (), primaryTerm , globalCheckpoint , maxSeqNoOfUpdatesOrDeletes );
1119
1130
sendReplicaRequest (replicaRequest , node , listener );
1120
1131
}
1121
1132
@@ -1263,15 +1274,17 @@ public String toString() {
1263
1274
protected static final class ConcreteReplicaRequest <R extends TransportRequest > extends ConcreteShardRequest <R > {
1264
1275
1265
1276
private long globalCheckpoint ;
1277
+ private long maxSeqNoOfUpdatesOrDeletes ;
1266
1278
1267
1279
public ConcreteReplicaRequest (final Supplier <R > requestSupplier ) {
1268
1280
super (requestSupplier );
1269
1281
}
1270
1282
1271
1283
public ConcreteReplicaRequest (final R request , final String targetAllocationID , final long primaryTerm ,
1272
- final long globalCheckpoint ) {
1284
+ final long globalCheckpoint , final long maxSeqNoOfUpdatesOrDeletes ) {
1273
1285
super (request , targetAllocationID , primaryTerm );
1274
1286
this .globalCheckpoint = globalCheckpoint ;
1287
+ this .maxSeqNoOfUpdatesOrDeletes = maxSeqNoOfUpdatesOrDeletes ;
1275
1288
}
1276
1289
1277
1290
@ Override
@@ -1282,6 +1295,13 @@ public void readFrom(StreamInput in) throws IOException {
1282
1295
} else {
1283
1296
globalCheckpoint = SequenceNumbers .UNASSIGNED_SEQ_NO ;
1284
1297
}
1298
+ if (in .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
1299
+ maxSeqNoOfUpdatesOrDeletes = in .readZLong ();
1300
+ } else {
1301
+ // UNASSIGNED_SEQ_NO (-2) means uninitialized, and replicas will disable
1302
+ // optimization using seq_no if its max_seq_no_of_updates is still uninitialized
1303
+ maxSeqNoOfUpdatesOrDeletes = SequenceNumbers .UNASSIGNED_SEQ_NO ;
1304
+ }
1285
1305
}
1286
1306
1287
1307
@ Override
@@ -1290,19 +1310,27 @@ public void writeTo(StreamOutput out) throws IOException {
1290
1310
if (out .getVersion ().onOrAfter (Version .V_6_0_0_alpha1 )) {
1291
1311
out .writeZLong (globalCheckpoint );
1292
1312
}
1313
+ if (out .getVersion ().onOrAfter (Version .V_7_0_0_alpha1 )) {
1314
+ out .writeZLong (maxSeqNoOfUpdatesOrDeletes );
1315
+ }
1293
1316
}
1294
1317
1295
1318
public long getGlobalCheckpoint () {
1296
1319
return globalCheckpoint ;
1297
1320
}
1298
1321
1322
+ public long getMaxSeqNoOfUpdatesOrDeletes () {
1323
+ return maxSeqNoOfUpdatesOrDeletes ;
1324
+ }
1325
+
1299
1326
@ Override
1300
1327
public String toString () {
1301
1328
return "ConcreteReplicaRequest{" +
1302
1329
"targetAllocationID='" + getTargetAllocationID () + '\'' +
1303
1330
", primaryTerm='" + getPrimaryTerm () + '\'' +
1304
1331
", request=" + getRequest () +
1305
1332
", globalCheckpoint=" + globalCheckpoint +
1333
+ ", maxSeqNoOfUpdatesOrDeletes=" + maxSeqNoOfUpdatesOrDeletes +
1306
1334
'}' ;
1307
1335
}
1308
1336
}
0 commit comments