fix wait for active shards

2.2.1.6
Jörg Prante 5 years ago
parent 41b18f4ae7
commit 37b664f1b6

@ -438,14 +438,11 @@ public abstract class AbstractExtendedClient implements ExtendedClient {
public boolean waitForRecovery(String index, long maxWaitTime, TimeUnit timeUnit) { public boolean waitForRecovery(String index, long maxWaitTime, TimeUnit timeUnit) {
ensureActive(); ensureActive();
ensureIndexGiven(index); ensureIndexGiven(index);
RecoveryRequest recoveryRequest = new RecoveryRequest(); GetSettingsRequest settingsRequest = new GetSettingsRequest();
recoveryRequest.indices(index); settingsRequest.indices(index);
recoveryRequest.activeOnly(true); GetSettingsResponse settingsResponse = client.execute(GetSettingsAction.INSTANCE, settingsRequest).actionGet();
RecoveryResponse recoveryResponse = client.execute(RecoveryAction.INSTANCE, recoveryRequest).actionGet(); int shards = settingsResponse.getIndexToSettings().get(index).getAsInt("index.number_of_shards", -1);
if (recoveryResponse.hasRecoveries()) { if (shards > 0) {
int shards = recoveryResponse.getTotalShards();
logger.info("shards = {}", shards);
logger.info(recoveryResponse.shardRecoveryStates());
TimeValue timeout = toTimeValue(maxWaitTime, timeUnit); TimeValue timeout = toTimeValue(maxWaitTime, timeUnit);
ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest() ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest()
.indices(new String[]{index}) .indices(new String[]{index})

Loading…
Cancel
Save