Skip to content

Commit

Permalink
inline check
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Oct 23, 2018
1 parent c79e892 commit b279bd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.common.util.concurrent.CountDown;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.ccr.CcrLicenseChecker;
Expand Down Expand Up @@ -370,7 +371,7 @@ static List<Index> getLeaderIndicesToFollow(String clusterAlias,
// has a leader index uuid custom metadata entry that matches with uuid of leaderIndexMetaData variable
// If so then handle it differently: not follow it, but just add an entry to
// AutoFollowMetadata#followedLeaderIndexUUIDs
if (TransportPutFollowAction.canFollow(clusterAlias, leaderIndexMetaData) == null) {
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false)) {
leaderIndicesToFollow.add(leaderIndexMetaData.getIndex());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ protected void masterOperation(
createFollowerIndexAndFollowRemoteIndex(request, leaderCluster, leaderIndex, listener);
}

/**
* Pre-flight check if the given index can be a leader index.
* This method returns {@code null} if no issue found; otherwise it returns the first issue that it found.
*/
static Exception canFollow(String leaderCluster, IndexMetaData leaderIndexMetaData) {
Objects.requireNonNull(leaderIndexMetaData, "leader index metadata must not be null");
// soft-deletes is mandatory for the leader index.
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false) == false) {
return new IllegalArgumentException("leader index [" + leaderCluster + ":" + leaderIndexMetaData.getIndex().getName()
+ "] does not have soft deletes enabled");
}
return null;
}

private void createFollowerIndexAndFollowRemoteIndex(
final PutFollowAction.Request request,
final String leaderCluster,
Expand All @@ -139,11 +125,9 @@ private void createFollowerIndex(
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist"));
return;
}

final Exception preFlightError = canFollow(request.getLeaderCluster(), leaderIndexMetaData);
if (preFlightError != null) {
listener.onFailure(preFlightError);
return;
if (leaderIndexMetaData.getSettings().getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), false) == false) {
listener.onFailure(
new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not enable soft-deletes"));
}

ActionListener<Boolean> handler = ActionListener.wrap(
Expand Down

0 comments on commit b279bd7

Please sign in to comment.