Skip to content

Commit ff1e3b9

Browse files
committed
Add data tiers preference for snapshot blob cache system index (elastic#64004)
In elastic#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 cad8817 commit ff1e3b9

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
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.plugins.Plugin;
3434
import org.elasticsearch.snapshots.SnapshotId;
3535
import org.elasticsearch.test.InternalTestCluster;
36+
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
3637
import org.elasticsearch.xpack.core.ClientHelper;
3738
import org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotShardStats;
3839
import org.elasticsearch.xpack.searchablesnapshots.BaseSearchableSnapshotsIntegTestCase;
@@ -60,6 +61,7 @@
6061
import static org.elasticsearch.repositories.blobstore.BlobStoreRepository.INDEX_SHARD_SNAPSHOT_FORMAT;
6162
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
6263
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
64+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
6365
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_BLOB_CACHE_INDEX;
6466
import static org.hamcrest.Matchers.equalTo;
6567
import static org.hamcrest.Matchers.greaterThan;
@@ -170,6 +172,16 @@ public void testBlobStoreCache() throws Exception {
170172
logger.info("--> verifying cached documents in system index [{}]", SNAPSHOT_BLOB_CACHE_INDEX);
171173
assertCachedBlobsInSystemIndex(repositoryName, blobsInSnapshot);
172174

175+
logger.info("--> verifying system index [{}] data tiers preference", SNAPSHOT_BLOB_CACHE_INDEX);
176+
assertThat(
177+
systemClient().admin()
178+
.indices()
179+
.prepareGetSettings(SNAPSHOT_BLOB_CACHE_INDEX)
180+
.get()
181+
.getSetting(SNAPSHOT_BLOB_CACHE_INDEX, DataTierAllocationDecider.INDEX_ROUTING_PREFER),
182+
equalTo(DATA_TIERS_PREFERENCE)
183+
);
184+
173185
final long numberOfCachedBlobs = systemClient().prepareSearch(SNAPSHOT_BLOB_CACHE_INDEX).get().getHits().getTotalHits().value;
174186
final long numberOfCacheWrites = systemClient().admin()
175187
.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
@@ -40,6 +40,8 @@
4040
import org.elasticsearch.repositories.RepositoriesService;
4141
import org.elasticsearch.snapshots.SnapshotId;
4242
import org.elasticsearch.snapshots.SnapshotInfo;
43+
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
44+
import org.elasticsearch.xpack.core.DataTier;
4345
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
4446
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
4547
import org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotShardStats;
@@ -73,6 +75,7 @@
7375
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
7476
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
7577
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
78+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
7679
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_DIRECTORY_FACTORY_KEY;
7780
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_RECOVERY_STATE_FACTORY_KEY;
7881
import static org.hamcrest.Matchers.anyOf;
@@ -167,6 +170,14 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
167170
} else {
168171
expectedReplicas = 0;
169172
}
173+
final String expectedDataTiersPreference;
174+
if (randomBoolean()) {
175+
expectedDataTiersPreference = String.join(",", randomSubsetOf(DataTier.ALL_DATA_TIERS));
176+
indexSettingsBuilder.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, expectedDataTiersPreference);
177+
} else {
178+
expectedDataTiersPreference = DATA_TIERS_PREFERENCE;
179+
}
180+
170181
final MountSearchableSnapshotRequest req = new MountSearchableSnapshotRequest(
171182
restoredIndexName,
172183
fsRepoName,
@@ -195,6 +206,7 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
195206
assertTrue(SearchableSnapshots.SNAPSHOT_INDEX_ID_SETTING.exists(settings));
196207
assertThat(IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(settings).toString(), equalTo("false"));
197208
assertThat(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(settings), equalTo(expectedReplicas));
209+
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(settings), equalTo(expectedDataTiersPreference));
198210

199211
assertTotalHits(restoredIndexName, originalAllHits, originalBarHits);
200212
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
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.threadpool.ScalingExecutorBuilder;
5353
import org.elasticsearch.threadpool.ThreadPool;
5454
import org.elasticsearch.watcher.ResourceWatcherService;
55+
import org.elasticsearch.xpack.core.DataTier;
5556
import org.elasticsearch.xpack.core.XPackPlugin;
5657
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
5758
import org.elasticsearch.xpack.core.searchablesnapshots.SearchableSnapshotsFeatureSet;
@@ -150,6 +151,11 @@ public class SearchableSnapshots extends Plugin implements IndexStorePlugin, Eng
150151
Setting.Property.NotCopyableOnResize
151152
);
152153

154+
/**
155+
* Prefer to allocate to the cold tier, then the warm tier, then the hot tier
156+
*/
157+
public static final String DATA_TIERS_PREFERENCE = String.join(",", DataTier.DATA_COLD, DataTier.DATA_WARM, DataTier.DATA_HOT);
158+
153159
private volatile Supplier<RepositoriesService> repositoriesServiceSupplier;
154160
private final SetOnce<BlobStoreCacheService> blobStoreCacheService = new SetOnce<>();
155161
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;
@@ -49,6 +48,7 @@
4948

5049
import static org.elasticsearch.index.IndexModule.INDEX_RECOVERY_TYPE_SETTING;
5150
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
51+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.DATA_TIERS_PREFERENCE;
5252

5353
/**
5454
* Action that mounts a snapshot as a searchable snapshot, by converting the mount request into a restore request with specific settings
@@ -184,11 +184,7 @@ protected void masterOperation(
184184
Settings.builder()
185185
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) // can be overridden
186186
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, false) // can be overridden
187-
// prefer to allocate to the cold tier, then the warm tier, then the hot tier
188-
.put(
189-
DataTierAllocationDecider.INDEX_ROUTING_PREFER,
190-
String.join(",", DataTier.DATA_COLD, DataTier.DATA_WARM, DataTier.DATA_HOT)
191-
)
187+
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DATA_TIERS_PREFERENCE)
192188
.put(request.indexSettings())
193189
.put(buildIndexSettings(request.repositoryName(), snapshotId, indexId))
194190
.build()

0 commit comments

Comments
 (0)