@@ -227,25 +227,35 @@ public ClusterState execute(ClusterState currentState) {
227
227
logger .warn ("Remote store restore is not supported for non-existent index. Skipping: {}" , index );
228
228
continue ;
229
229
}
230
- if (currentIndexMetadata .getState () != IndexMetadata .State .CLOSE ) {
231
- throw new IllegalStateException (
232
- "cannot restore index ["
233
- + index
234
- + "] because an open index "
235
- + "with same name already exists in the cluster. Close the existing index"
236
- );
237
- }
238
230
if (currentIndexMetadata .getSettings ().getAsBoolean (SETTING_REMOTE_STORE , false )) {
239
- IndexId indexId = new IndexId (index , currentIndexMetadata .getIndexUUID ());
231
+ if (currentIndexMetadata .getState () != IndexMetadata .State .CLOSE ) {
232
+ throw new IllegalStateException (
233
+ "cannot restore index ["
234
+ + index
235
+ + "] because an open index "
236
+ + "with same name already exists in the cluster. Close the existing index"
237
+ );
238
+ }
239
+ IndexMetadata updatedIndexMetadata = IndexMetadata .builder (currentIndexMetadata )
240
+ .state (IndexMetadata .State .OPEN )
241
+ .version (1 + currentIndexMetadata .getVersion ())
242
+ .mappingVersion (1 + currentIndexMetadata .getMappingVersion ())
243
+ .settingsVersion (1 + currentIndexMetadata .getSettingsVersion ())
244
+ .aliasesVersion (1 + currentIndexMetadata .getAliasesVersion ())
245
+ .build ();
246
+
247
+ IndexId indexId = new IndexId (index , updatedIndexMetadata .getIndexUUID ());
240
248
241
249
RemoteStoreRecoverySource recoverySource = new RemoteStoreRecoverySource (
242
250
restoreUUID ,
243
- currentIndexMetadata .getCreationVersion (),
251
+ updatedIndexMetadata .getCreationVersion (),
244
252
indexId
245
253
);
246
- rtBuilder .addAsRemoteStoreRestore (currentIndexMetadata , recoverySource );
254
+ rtBuilder .addAsRemoteStoreRestore (updatedIndexMetadata , recoverySource );
255
+ blocks .updateBlocks (updatedIndexMetadata );
256
+ mdBuilder .put (updatedIndexMetadata , true );
247
257
indicesToBeRestored .add (index );
248
- totalShards += currentIndexMetadata .getNumberOfShards ();
258
+ totalShards += updatedIndexMetadata .getNumberOfShards ();
249
259
} else {
250
260
logger .warn ("Remote store is not enabled for index: {}" , index );
251
261
}
0 commit comments