Skip to content

Commit 3f8097b

Browse files
authored
Add data tiers preference for snapshot blob cache system index (#64004)
In #63204 we added a data tier preference for searchable snapshot indices (cold > warm > hot). Since these indices can use a system index (.snapshot-blob-cache) for their recoveries I think it makes sense that this internal index share the same tier preference.
1 parent 30224d0 commit 3f8097b

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
3535
import org.elasticsearch.snapshots.SnapshotId;
3636
import org.elasticsearch.test.InternalTestCluster;
37+
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
3738
import org.elasticsearch.xpack.core.ClientHelper;
3839
import org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotShardStats;
3940
import org.elasticsearch.xpack.searchablesnapshots.BaseSearchableSnapshotsIntegTestCase;
@@ -56,6 +57,7 @@
5657
import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.INDEX_SHARD_SNAPSHOT_FORMAT;
5758
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5859
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
60+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
5961
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_BLOB_CACHE_INDEX;
6062
import static org.hamcrest.Matchers.equalTo;
6163
import static org.hamcrest.Matchers.greaterThan;
@@ -164,6 +166,16 @@ public void testBlobStoreCache() throws Exception {
164166
logger.info("--> verifying cached documents in system index [{}]", SNAPSHOT_BLOB_CACHE_INDEX);
165167
assertCachedBlobsInSystemIndex(repositoryName, blobsInSnapshot);
166168

169+
logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX);
170+
assertThat(
171+
systemClient().admin()
172+
.indices()
173+
.prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX)
174+
.get()
175+
.getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER),
176+
equalTo(DATA_TIERS_PREFERENCE)
177+
);
178+
167179
final long numberOfCachedBlobs = systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX).get().getHits().getTotalHits().value;
168180
final long numberOfCacheWrites = systemClient().admin()
169181
.indices()

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsIntegTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.elasticsearch.indices.recovery.RecoveryState;
4040
import org.elasticsearch.snapshots.SnapshotId;
4141
import org.elasticsearch.snapshots.SnapshotInfo;
42+
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
43+
import org.elasticsearch.xpack.core.DataTier;
4244
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
4345
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
4446
import org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotShardStats;
@@ -72,6 +74,7 @@
7274
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
7375
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
7476
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
77+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
7578
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_DIRECTORY_FACTORY_KEY;
7679
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_RECOVERY_STATE_FACTORY_KEY;
7780
import static org.hamcrest.Matchers.anyOf;
@@ -166,6 +169,14 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
166169
} else {
167170
expectedReplicas = 0;
168171
}
172+
final String expectedDataTiersPreference;
173+
if (randomBoolean()) {
174+
expectedDataTiersPreference = String.join(",", randomSubsetOf(DataTier.ALL_DATA_TIERS));
175+
indexSettingsBuilder.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, expectedDataTiersPreference);
176+
} else {
177+
expectedDataTiersPreference = DATA_TIERS_PREFERENCE;
178+
}
179+
169180
final MountSearchableSnapshotRequest req = new MountSearchableSnapshotRequest(
170181
restoredIndexName,
171182
fsRepoName,
@@ -194,6 +205,7 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
194205
assertTrue(SearchableSnapshots.SNAPSHOT_INDEX_ID_SETTING.exists(settings));
195206
assertThat(IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(settings).toString(), equalTo("false"));
196207
assertThat(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(settings), equalTo(expectedReplicas));
208+
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(settings), equalTo(expectedDataTiersPreference));
197209

198210
assertTotalHits(restoredIndexName, originalAllHits, originalBarHits);
199211
assertRecoveryStats(restoredIndexName, preWarmEnabled);

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/blobstore/cache/BlobStoreCacheService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.node.NodeClosedException;
3535
import org.elasticsearch.threadpool.ThreadPool;
3636
import org.elasticsearch.transport.ConnectTransportException;
37+
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
3738

3839
import java.io.IOException;
3940
import java.time.Instant;
@@ -42,6 +43,7 @@
4243
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4344
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
4445
import static org.elasticsearch.xpack.core.ClientHelper.SEARCHABLE_SNAPSHOTS_ORIGIN;
46+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
4547

4648
public class BlobStoreCacheService {
4749

@@ -99,6 +101,7 @@ private static Settings indexSettings() {
99101
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
100102
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
101103
.put(IndexMetadata.SETTING_PRIORITY, "900")
104+
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DATA_TIERS_PREFERENCE)
102105
.build();
103106
}
104107

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.elasticsearch.threadpool.ScalingExecutorBuilder;
5252
import org.elasticsearch.threadpool.ThreadPool;
5353
import org.elasticsearch.watcher.ResourceWatcherService;
54+
import org.elasticsearch.xpack.core.DataTier;
5455
import org.elasticsearch.xpack.core.XPackPlugin;
5556
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
5657
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
@@ -146,6 +147,11 @@ public class SearchableSnapshots extends Plugin implements IndexStorePlugin, Eng
146147
Setting.Property.NotCopyableOnResize
147148
);
148149

150+
/**
151+
* Prefer to allocate to the cold tier, then the warm tier, then the hot tier
152+
*/
153+
public static final String DATA_TIERS_PREFERENCE = String.join(",", DataTier.DATA_COLD, DataTier.DATA_WARM, DataTier.DATA_HOT);
154+
149155
private volatile Supplier<RepositoriesService> repositoriesServiceSupplier;
150156
private final SetOnce<BlobStoreCacheService> blobStoreCacheService = new SetOnce<>();
151157
private final SetOnce<CacheService> cacheService = new SetOnce<>();

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportMountSearchableSnapshotAction.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.elasticsearch.threadpool.ThreadPool;
3535
import org.elasticsearch.transport.TransportService;
3636
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
37-
import org.elasticsearch.xpack.core.DataTier;
3837
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
3938
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
4039
import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotAllocator;
@@ -48,6 +47,7 @@
4847

4948
import static org.elasticsearch.index.IndexModule.INDEX_RECOVERY_TYPE_SETTING;
5049
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
50+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
5151

5252
/**
5353
* Action that mounts a snapshot as a searchable snapshot, by converting the mount request into a restore request with specific settings
@@ -176,11 +176,7 @@ protected void masterOperation(
176176
Settings.builder()
177177
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) // can be overridden
178178
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, false) // can be overridden
179-
// prefer to allocate to the cold tier, then the warm tier, then the hot tier
180-
.put(
181-
DataTierAllocationDecider.INDEX_ROUTING_PREFER,
182-
String.join(",", DataTier.DATA_COLD, DataTier.DATA_WARM, DataTier.DATA_HOT)
183-
)
179+
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DATA_TIERS_PREFERENCE)
184180
.put(request.indexSettings())
185181
.put(buildIndexSettings(request.repositoryName(), snapshotId, indexId))
186182
.build()

0 commit comments

Comments
 (0)