@@ -279,6 +279,9 @@ public void testShrink() throws IOException {
279279 mappingsAndSettings .startObject ("settings" );
280280 {
281281 mappingsAndSettings .field ("index.number_of_shards" , 5 );
282+ if (minimumNodeVersion ().before (Version .V_8_0_0 ) && randomBoolean ()) {
283+ mappingsAndSettings .field (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), Boolean .toString (randomBoolean ()));
284+ }
282285 }
283286 mappingsAndSettings .endObject ();
284287 }
@@ -350,6 +353,9 @@ public void testShrinkAfterUpgrade() throws IOException {
350353 // the default number of shards is now one so we have to set the number of shards to be more than one explicitly
351354 mappingsAndSettings .startObject ("settings" );
352355 mappingsAndSettings .field ("index.number_of_shards" , 5 );
356+ if (minimumNodeVersion ().before (Version .V_8_0_0 ) && randomBoolean ()) {
357+ mappingsAndSettings .field (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), Boolean .toString (randomBoolean ()));
358+ }
353359 mappingsAndSettings .endObject ();
354360 }
355361 mappingsAndSettings .endObject ();
@@ -1310,4 +1316,77 @@ public void testTurnOffTranslogRetentionAfterUpgraded() throws Exception {
13101316 ensurePeerRecoveryRetentionLeasesRenewedAndSynced (index );
13111317 }
13121318 }
1319+
1320+ public void testResize () throws Exception {
1321+ int numDocs ;
1322+ if (isRunningAgainstOldCluster ()) {
1323+ final Settings .Builder settings = Settings .builder ()
1324+ .put (IndexMetaData .INDEX_NUMBER_OF_SHARDS_SETTING .getKey (), 3 )
1325+ .put (IndexMetaData .INDEX_NUMBER_OF_REPLICAS_SETTING .getKey (), 1 );
1326+ if (minimumNodeVersion ().before (Version .V_8_0_0 ) && randomBoolean ()) {
1327+ settings .put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), false );
1328+ }
1329+ createIndex (index , settings .build ());
1330+ numDocs = randomIntBetween (10 , 1000 );
1331+ for (int i = 0 ; i < numDocs ; i ++) {
1332+ indexDocument (Integer .toString (i ));
1333+ if (rarely ()) {
1334+ flush (index , randomBoolean ());
1335+ }
1336+ }
1337+ saveInfoDocument ("num_doc_" + index , Integer .toString (numDocs ));
1338+ ensureGreen (index );
1339+ } else {
1340+ ensureGreen (index );
1341+ numDocs = Integer .parseInt (loadInfoDocument ("num_doc_" + index ));
1342+ int moreDocs = randomIntBetween (0 , 100 );
1343+ for (int i = 0 ; i < moreDocs ; i ++) {
1344+ indexDocument (Integer .toString (numDocs + i ));
1345+ if (rarely ()) {
1346+ flush (index , randomBoolean ());
1347+ }
1348+ }
1349+ Request updateSettingsRequest = new Request ("PUT" , "/" + index + "/_settings" );
1350+ updateSettingsRequest .setJsonEntity ("{\" settings\" : {\" index.blocks.write\" : true}}" );
1351+ client ().performRequest (updateSettingsRequest );
1352+ {
1353+ final String target = index + "_shrunken" ;
1354+ Request shrinkRequest = new Request ("PUT" , "/" + index + "/_shrink/" + target );
1355+ Settings .Builder settings = Settings .builder ().put (IndexMetaData .SETTING_NUMBER_OF_SHARDS , 1 );
1356+ if (randomBoolean ()) {
1357+ settings .put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), true );
1358+ }
1359+ shrinkRequest .setJsonEntity ("{\" settings\" :" + Strings .toString (settings .build ()) + "}" );
1360+ client ().performRequest (shrinkRequest );
1361+ ensureGreenLongWait (target );
1362+ assertNumHits (target , numDocs + moreDocs , 1 );
1363+ }
1364+ {
1365+ final String target = index + "_split" ;
1366+ Settings .Builder settings = Settings .builder ().put (IndexMetaData .SETTING_NUMBER_OF_SHARDS , 6 );
1367+ if (randomBoolean ()) {
1368+ settings .put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), true );
1369+ }
1370+ Request splitRequest = new Request ("PUT" , "/" + index + "/_split/" + target );
1371+ splitRequest .setJsonEntity ("{\" settings\" :" + Strings .toString (settings .build ()) + "}" );
1372+ client ().performRequest (splitRequest );
1373+ ensureGreenLongWait (target );
1374+ assertNumHits (target , numDocs + moreDocs , 6 );
1375+ }
1376+ {
1377+ final String target = index + "_cloned" ;
1378+ client ().performRequest (new Request ("PUT" , "/" + index + "/_clone/" + target ));
1379+ ensureGreenLongWait (target );
1380+ assertNumHits (target , numDocs + moreDocs , 3 );
1381+ }
1382+ }
1383+ }
1384+
1385+ private void assertNumHits (String index , int numHits , int totalShards ) throws IOException {
1386+ Map <String , Object > resp = entityAsMap (client ().performRequest (new Request ("GET" , "/" + index + "/_search" )));
1387+ assertNoFailures (resp );
1388+ assertThat (XContentMapValues .extractValue ("_shards.total" , resp ), equalTo (totalShards ));
1389+ assertThat (XContentMapValues .extractValue ("_shards.successful" , resp ), equalTo (totalShards ));
1390+ assertThat (extractTotalHits (resp ), equalTo (numHits ));
1391+ }
13131392}
0 commit comments