99
1010package org .elasticsearch .action .admin .indices .flush ;
1111
12+ import org .elasticsearch .TransportVersions ;
1213import org .elasticsearch .action .ActionListener ;
1314import org .elasticsearch .action .ActionType ;
1415import org .elasticsearch .action .support .ActionFilters ;
1718import org .elasticsearch .cluster .action .shard .ShardStateAction ;
1819import org .elasticsearch .cluster .service .ClusterService ;
1920import org .elasticsearch .common .io .stream .StreamInput ;
21+ import org .elasticsearch .common .io .stream .StreamOutput ;
2022import org .elasticsearch .common .settings .Settings ;
2123import org .elasticsearch .index .shard .IndexShard ;
24+ import org .elasticsearch .index .shard .ShardId ;
2225import org .elasticsearch .indices .IndicesService ;
2326import org .elasticsearch .injection .guice .Inject ;
27+ import org .elasticsearch .tasks .Task ;
2428import org .elasticsearch .threadpool .ThreadPool ;
29+ import org .elasticsearch .transport .AbstractTransportRequest ;
30+ import org .elasticsearch .transport .TransportChannel ;
31+ import org .elasticsearch .transport .TransportRequestHandler ;
2532import org .elasticsearch .transport .TransportService ;
2633
2734import java .io .IOException ;
@@ -57,6 +64,12 @@ public TransportShardFlushAction(
5764 PrimaryActionExecution .RejectOnOverload ,
5865 ReplicaActionExecution .SubjectToCircuitBreaker
5966 );
67+ transportService .registerRequestHandler (
68+ PRE_SYNCED_FLUSH_ACTION_NAME ,
69+ threadPool .executor (ThreadPool .Names .FLUSH ),
70+ PreShardSyncedFlushRequest ::new ,
71+ new PreSyncedFlushTransportHandler (indicesService )
72+ );
6073 }
6174
6275 @ Override
@@ -83,4 +96,43 @@ protected void shardOperationOnReplica(ShardFlushRequest request, IndexShard rep
8396 return new ReplicaResult ();
8497 }));
8598 }
99+
100+ // TODO: Remove this transition in 9.0
101+ private static final String PRE_SYNCED_FLUSH_ACTION_NAME = "internal:indices/flush/synced/pre" ;
102+
103+ private static class PreShardSyncedFlushRequest extends AbstractTransportRequest {
104+ private final ShardId shardId ;
105+
106+ private PreShardSyncedFlushRequest (StreamInput in ) throws IOException {
107+ super (in );
108+ assert in .getTransportVersion ().before (TransportVersions .V_8_0_0 ) : "received pre_sync request from a new node" ;
109+ this .shardId = new ShardId (in );
110+ }
111+
112+ @ Override
113+ public String toString () {
114+ return "PreShardSyncedFlushRequest{" + "shardId=" + shardId + '}' ;
115+ }
116+
117+ @ Override
118+ public void writeTo (StreamOutput out ) throws IOException {
119+ assert false : "must not send pre_sync request from a new node" ;
120+ throw new UnsupportedOperationException ("" );
121+ }
122+ }
123+
124+ private static final class PreSyncedFlushTransportHandler implements TransportRequestHandler <PreShardSyncedFlushRequest > {
125+ private final IndicesService indicesService ;
126+
127+ PreSyncedFlushTransportHandler (IndicesService indicesService ) {
128+ this .indicesService = indicesService ;
129+ }
130+
131+ @ Override
132+ public void messageReceived (PreShardSyncedFlushRequest request , TransportChannel channel , Task task ) {
133+ IndexShard indexShard = indicesService .indexServiceSafe (request .shardId .getIndex ()).getShard (request .shardId .id ());
134+ indexShard .flush (new FlushRequest ().force (false ).waitIfOngoing (true ));
135+ throw new UnsupportedOperationException ("Synced flush was removed and a normal flush was performed instead." );
136+ }
137+ }
86138}
0 commit comments