18
18
import org .opensearch .client .Requests ;
19
19
import org .opensearch .cluster .ClusterState ;
20
20
import org .opensearch .cluster .metadata .IndexMetadata ;
21
+ import org .opensearch .common .Nullable ;
21
22
import org .opensearch .common .io .PathUtils ;
22
23
import org .opensearch .common .settings .Settings ;
23
24
import org .opensearch .common .util .io .IOUtils ;
46
47
import java .util .Arrays ;
47
48
import java .util .List ;
48
49
import java .util .Map ;
50
+ import java .util .Objects ;
49
51
import java .util .Optional ;
50
52
import java .util .concurrent .ExecutionException ;
51
53
import java .util .stream .Collectors ;
@@ -226,7 +228,7 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
226
228
227
229
indexDocuments (client , indexName1 , randomIntBetween (5 , 10 ));
228
230
ensureGreen (indexName1 );
229
- validatePathType (indexName1 , PathType .FIXED , PathHashAlgorithm . FNV_1A );
231
+ validatePathType (indexName1 , PathType .FIXED );
230
232
231
233
logger .info ("--> snapshot" );
232
234
SnapshotInfo snapshotInfo = createSnapshot (snapshotRepoName , snapshotName1 , new ArrayList <>(Arrays .asList (indexName1 )));
@@ -243,7 +245,7 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
243
245
.get ();
244
246
assertEquals (RestStatus .ACCEPTED , restoreSnapshotResponse .status ());
245
247
ensureGreen (restoredIndexName1version1 );
246
- validatePathType (restoredIndexName1version1 , PathType .FIXED , PathHashAlgorithm . FNV_1A );
248
+ validatePathType (restoredIndexName1version1 , PathType .FIXED );
247
249
248
250
client (clusterManagerNode ).admin ()
249
251
.cluster ()
@@ -269,16 +271,50 @@ public void testRemoteStoreCustomDataOnIndexCreationAndRestore() {
269
271
validatePathType (indexName2 , PathType .HASHED_PREFIX , PathHashAlgorithm .FNV_1A );
270
272
271
273
// Validating that custom data has not changed for indexes which were created before the cluster setting got updated
272
- validatePathType (indexName1 , PathType .FIXED , PathHashAlgorithm .FNV_1A );
274
+ validatePathType (indexName1 , PathType .FIXED );
275
+
276
+ // Create Snapshot of index 2
277
+ String snapshotName2 = "test-restore-snapshot2" ;
278
+ snapshotInfo = createSnapshot (snapshotRepoName , snapshotName2 , new ArrayList <>(List .of (indexName2 )));
279
+ assertEquals (SnapshotState .SUCCESS , snapshotInfo .state ());
280
+ assertTrue (snapshotInfo .successfulShards () > 0 );
281
+ assertEquals (snapshotInfo .totalShards (), snapshotInfo .successfulShards ());
282
+
283
+ // Update cluster settings to FIXED
284
+ client (clusterManagerNode ).admin ()
285
+ .cluster ()
286
+ .prepareUpdateSettings ()
287
+ .setTransientSettings (Settings .builder ().put (CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING .getKey (), PathType .FIXED ))
288
+ .get ();
289
+
290
+ // Close index 2
291
+ assertAcked (client ().admin ().indices ().prepareClose (indexName2 ));
292
+ restoreSnapshotResponse = client .admin ()
293
+ .cluster ()
294
+ .prepareRestoreSnapshot (snapshotRepoName , snapshotName2 )
295
+ .setWaitForCompletion (false )
296
+ .setIndices (indexName2 )
297
+ .get ();
298
+ assertEquals (RestStatus .ACCEPTED , restoreSnapshotResponse .status ());
299
+ ensureGreen (indexName2 );
300
+
301
+ // Validating that custom data has not changed for testindex2 which was created before the cluster setting got updated
302
+ validatePathType (indexName2 , PathType .HASHED_PREFIX , PathHashAlgorithm .FNV_1A );
273
303
}
274
304
275
- private void validatePathType (String index , PathType pathType , PathHashAlgorithm pathHashAlgorithm ) {
305
+ private void validatePathType (String index , PathType pathType ) {
306
+ validatePathType (index , pathType , null );
307
+ }
308
+
309
+ private void validatePathType (String index , PathType pathType , @ Nullable PathHashAlgorithm pathHashAlgorithm ) {
276
310
ClusterState state = client ().admin ().cluster ().prepareState ().execute ().actionGet ().getState ();
277
311
// Validate that the remote_store custom data is present in index metadata for the created index.
278
312
Map <String , String > remoteCustomData = state .metadata ().index (index ).getCustomData (IndexMetadata .REMOTE_STORE_CUSTOM_KEY );
279
313
assertNotNull (remoteCustomData );
280
314
assertEquals (pathType .name (), remoteCustomData .get (PathType .NAME ));
281
- assertEquals (pathHashAlgorithm .name (), remoteCustomData .get (PathHashAlgorithm .NAME ));
315
+ if (Objects .nonNull (pathHashAlgorithm )) {
316
+ assertEquals (pathHashAlgorithm .name (), remoteCustomData .get (PathHashAlgorithm .NAME ));
317
+ }
282
318
}
283
319
284
320
public void testRestoreInSameRemoteStoreEnabledIndex () throws IOException {
0 commit comments