Skip to content

Commit

Permalink
Make default value for _tier_preference be "data_frozen" for frozen SBIs
Browse files Browse the repository at this point in the history
  • Loading branch information
dakrone committed Apr 5, 2021
1 parent f2dd315 commit 9bab290
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.core.DataTier.DATA_FROZEN;
Expand Down Expand Up @@ -66,8 +67,8 @@ public class DataTierAllocationDecider extends AllocationDecider {
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<String> INDEX_ROUTING_EXCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_EXCLUDE,
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<String> INDEX_ROUTING_PREFER_SETTING = Setting.simpleString(INDEX_ROUTING_PREFER,
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<String> INDEX_ROUTING_PREFER_SETTING = new Setting<>(new Setting.SimpleKey(INDEX_ROUTING_PREFER),
DataTierValidator::getDefaultTierPreference, Function.identity(), VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope);

private static void validateTierSetting(String setting) {
if (Strings.hasText(setting)) {
Expand All @@ -84,6 +85,14 @@ private static class DataTierValidator implements Setting.Validator<String> {
private static final Collection<Setting<?>> dependencies = List.of(IndexModule.INDEX_STORE_TYPE_SETTING,
SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING);

public static String getDefaultTierPreference(Settings settings) {
if (SearchableSnapshotsConstants.isPartialSearchableSnapshotIndex(settings)) {
return DATA_FROZEN;
} else {
return "";
}
}

@Override
public void validate(String value) {
validateTierSetting(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public static boolean isPartialSearchableSnapshotIndex(Map<Setting<?>, Object> i
&& (boolean) indexSettings.get(SNAPSHOT_PARTIAL_SETTING);
}

public static boolean isPartialSearchableSnapshotIndex(Settings indexSettings) {
return SNAPSHOT_DIRECTORY_FACTORY_KEY.equals(INDEX_STORE_TYPE_SETTING.get(indexSettings))
&& SNAPSHOT_PARTIAL_SETTING.get(indexSettings);
}

public static final String CACHE_FETCH_ASYNC_THREAD_POOL_NAME = "searchable_snapshots_cache_fetch_async";
public static final String CACHE_FETCH_ASYNC_THREAD_POOL_SETTING = "xpack.searchable_snapshots.cache_fetch_async_thread_pool";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ public void testNonFrozenIllegalForPartialSnapshot() {
Randomness.shuffle(tierList);

String value = Strings.join(tierList, ",");
logger.info("--> value: {}", value);
Settings.Builder builder = Settings.builder().put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, value);
builder.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsConstants.SNAPSHOT_DIRECTORY_FACTORY_KEY);
builder.put(SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING.getKey(), true);
Expand All @@ -764,6 +763,17 @@ public void testNonFrozenIllegalForPartialSnapshot() {
assertThat(e.getMessage(), containsString("only the [data_frozen] tier preference may be used for partial searchable snapshots"));
}

public void testDefaultValueForPreference() {
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(Settings.EMPTY), equalTo(""));

Settings.Builder builder = Settings.builder();
builder.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), SearchableSnapshotsConstants.SNAPSHOT_DIRECTORY_FACTORY_KEY);
builder.put(SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING.getKey(), true);

Settings settings = builder.build();
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(settings), equalTo(DATA_FROZEN));
}

public Setting<String> randomTierSetting() {
//noinspection unchecked
return randomFrom(
Expand Down

0 comments on commit 9bab290

Please sign in to comment.