Skip to content

Add ?storage arg to mount API #68431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/reference/searchable-snapshots/apis/mount-snapshot.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
(Optional, Boolean) If `true`, the request blocks until the operation is complete.
Defaults to `false`.

`storage`::
+
experimental::[]
+
(Optional, string) Selects the kind of local storage used to accelerate
searches of the mounted index. If `full_copy`, each node holding a shard of the
searchable snapshot index makes a full copy of the shard to its local storage.
If `shared_cache`, the shard uses the
<<searchable-snapshots-shared-cache,shared cache>>. Defaults to `full_copy`.

[[searchable-snapshots-api-mount-request-body]]
==== {api-request-body-title}

Expand Down
10 changes: 10 additions & 0 deletions docs/reference/searchable-snapshots/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ A snapshot of a {search-snap} index contains only a small amount of metadata
which identifies its original index snapshot. It does not contain any data from
the original index. The restore of a backup will fail to restore any
{search-snap} indices whose original index snapshot is unavailable.

[discrete]
[[searchable-snapshots-shared-cache]]
=== Shared snapshot cache

experimental::[]

By default a {search-snap} copies the whole snapshot into the local cluster as
described above. Nodes can also be configured to create a shared snapshot cache
which is used to hold a copy of just the frequently-accessed parts of shards.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl
new String[]{LifecycleSettings.LIFECYCLE_NAME},
// we'll not wait for the snapshot to complete in this step as the async steps are executed from threads that shouldn't
// perform expensive operations (ie. clusterStateProcessed)
false);
false,
// restoring into the cold tier, so use a full local copy
MountSearchableSnapshotRequest.Storage.FULL_COPY);
getClient().execute(MountSearchableSnapshotAction.INSTANCE, mountSearchableSnapshotRequest,
ActionListener.wrap(response -> {
if (response.status() != RestStatus.OK && response.status() != RestStatus.ACCEPTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants;

import java.io.IOException;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Collectors;

Expand All @@ -37,12 +40,13 @@ public class MountSearchableSnapshotRequest extends MasterNodeRequest<MountSearc
"mount_searchable_snapshot", true,
(a, request) -> new MountSearchableSnapshotRequest(
Objects.requireNonNullElse((String)a[1], (String)a[0]),
request.param("repository"),
request.param("snapshot"),
Objects.requireNonNull(request.param("repository")),
Objects.requireNonNull(request.param("snapshot")),
(String)a[0],
Objects.requireNonNullElse((Settings)a[2], Settings.EMPTY),
Objects.requireNonNullElse((String[])a[3], Strings.EMPTY_ARRAY),
request.paramAsBoolean("wait_for_completion", false)));
request.paramAsBoolean("wait_for_completion", false),
Storage.valueOf(request.param("storage", Storage.FULL_COPY.toString()).toUpperCase(Locale.ROOT))));

private static final ParseField INDEX_FIELD = new ParseField("index");
private static final ParseField RENAMED_INDEX_FIELD = new ParseField("renamed_index");
Expand All @@ -65,19 +69,28 @@ public class MountSearchableSnapshotRequest extends MasterNodeRequest<MountSearc
private final Settings indexSettings;
private final String[] ignoredIndexSettings;
private final boolean waitForCompletion;
private final Storage storage;

/**
* Constructs a new mount searchable snapshot request, restoring an index with the settings needed to make it a searchable snapshot.
*/
public MountSearchableSnapshotRequest(String mountedIndexName, String repositoryName, String snapshotName, String snapshotIndexName,
Settings indexSettings, String[] ignoredIndexSettings, boolean waitForCompletion) {
public MountSearchableSnapshotRequest(
String mountedIndexName,
String repositoryName,
String snapshotName,
String snapshotIndexName,
Settings indexSettings,
String[] ignoredIndexSettings,
boolean waitForCompletion,
Storage storage) {
this.mountedIndexName = Objects.requireNonNull(mountedIndexName);
this.repositoryName = Objects.requireNonNull(repositoryName);
this.snapshotName = Objects.requireNonNull(snapshotName);
this.snapshotIndexName = Objects.requireNonNull(snapshotIndexName);
this.indexSettings = Objects.requireNonNull(indexSettings);
this.ignoredIndexSettings = Objects.requireNonNull(ignoredIndexSettings);
this.waitForCompletion = waitForCompletion;
this.storage = storage;
}

public MountSearchableSnapshotRequest(StreamInput in) throws IOException {
Expand All @@ -89,6 +102,11 @@ public MountSearchableSnapshotRequest(StreamInput in) throws IOException {
this.indexSettings = readSettingsFromStream(in);
this.ignoredIndexSettings = in.readStringArray();
this.waitForCompletion = in.readBoolean();
if (in.getVersion().onOrAfter(SearchableSnapshotsConstants.SHARED_CACHE_VERSION)) {
this.storage = Storage.readFromStream(in);
} else {
this.storage = Storage.FULL_COPY;
}
}

@Override
Expand All @@ -101,6 +119,12 @@ public void writeTo(StreamOutput out) throws IOException {
writeSettingsToStream(indexSettings, out);
out.writeStringArray(ignoredIndexSettings);
out.writeBoolean(waitForCompletion);
if (out.getVersion().onOrAfter(SearchableSnapshotsConstants.SHARED_CACHE_VERSION)) {
storage.writeTo(out);
} else if (storage != Storage.FULL_COPY) {
throw new UnsupportedOperationException(
"storage type [" + storage + "] is not supported on version [" + out.getVersion() + "]");
}
}

@Override
Expand Down Expand Up @@ -162,6 +186,13 @@ public String[] ignoreIndexSettings() {
return ignoredIndexSettings;
}

/**
* @return how nodes will use their local storage to accelerate searches of this snapshot
*/
public Storage storage() {
return storage;
}

@Override
public String getDescription() {
return "mount snapshot [" + repositoryName + ":" + snapshotName + ":" + snapshotIndexName + "] as [" + mountedIndexName + "]";
Expand All @@ -173,6 +204,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
MountSearchableSnapshotRequest that = (MountSearchableSnapshotRequest) o;
return waitForCompletion == that.waitForCompletion &&
storage == that.storage &&
Objects.equals(mountedIndexName, that.mountedIndexName) &&
Objects.equals(repositoryName, that.repositoryName) &&
Objects.equals(snapshotName, that.snapshotName) &&
Expand All @@ -185,7 +217,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = Objects.hash(mountedIndexName, repositoryName, snapshotName, snapshotIndexName, indexSettings, waitForCompletion,
masterNodeTimeout);
masterNodeTimeout, storage);
result = 31 * result + Arrays.hashCode(ignoredIndexSettings);
return result;
}
Expand All @@ -194,4 +226,21 @@ public int hashCode() {
public String toString() {
return getDescription();
}

/**
* Enumerates the different ways that nodes can use their local storage to accelerate searches of a snapshot.
*/
public enum Storage implements Writeable {
FULL_COPY,
SHARED_CACHE;

public static Storage readFromStream(StreamInput in) throws IOException {
return in.readEnum(Storage.class);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeEnum(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.searchablesnapshots;

import org.elasticsearch.Version;
import org.elasticsearch.common.settings.Settings;

import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
Expand All @@ -27,4 +28,6 @@ public static boolean isSearchableSnapshotStore(Settings indexSettings) {

public static final String SNAPSHOT_BLOB_CACHE_INDEX = ".snapshot-blob-cache";

public static final Version SHARED_CACHE_VERSION = Version.V_8_0_0;

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ protected void mountSnapshot(
.put(restoredIndexSettings)
.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, mountRequest).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void testRepositoriesServiceClusterStateApplierIsCalledBeforeIndicesClust
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public void testSearchableSnapshotShardsAreSkippedWithoutQueryingAnyNodeWhenThey
indexOutsideSearchRange,
restoredIndexSettings,
Strings.EMPTY_ARRAY,
false
false,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);
client().execute(MountSearchableSnapshotAction.INSTANCE, mountRequest).actionGet();

Expand Down Expand Up @@ -267,7 +268,8 @@ public void testQueryPhaseIsExecutedInAnAvailableNodeWhenAllShardsCanBeSkipped()
indexOutsideSearchRange,
restoredIndexSettings,
Strings.EMPTY_ARRAY,
false
false,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);
client().execute(MountSearchableSnapshotAction.INSTANCE, mountRequest).actionGet();
final int searchableSnapshotShardCount = indexOutsideSearchRangeShardCount;
Expand Down Expand Up @@ -375,7 +377,8 @@ public void testSearchableSnapshotShardsThatHaveMatchingDataAreNotSkippedOnTheCo
indexWithinSearchRange,
restoredIndexSettings,
Strings.EMPTY_ARRAY,
false
false,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);
client().execute(MountSearchableSnapshotAction.INSTANCE, mountRequest).actionGet();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ public void testCreateAndRestoreSearchableSnapshot() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down Expand Up @@ -446,7 +447,7 @@ public void testCreateAndRestorePartialSearchableSnapshot() throws Exception {
assertAcked(client().admin().indices().prepareClose(indexName));
}

logger.info("--> restoring partial index [{}] with cache enabled");
logger.info("--> restoring partial index [{}] with cache enabled", restoredIndexName);

Settings.Builder indexSettingsBuilder = Settings.builder()
.put(SearchableSnapshots.SNAPSHOT_CACHE_ENABLED_SETTING.getKey(), true)
Expand Down Expand Up @@ -478,7 +479,6 @@ public void testCreateAndRestorePartialSearchableSnapshot() throws Exception {
} else {
expectedDataTiersPreference = DATA_TIERS_PREFERENCE;
}
indexSettingsBuilder.put(SearchableSnapshots.SNAPSHOT_PARTIAL_SETTING.getKey(), true);

final MountSearchableSnapshotRequest req = new MountSearchableSnapshotRequest(
restoredIndexName,
Expand All @@ -487,7 +487,8 @@ public void testCreateAndRestorePartialSearchableSnapshot() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.SHARED_CACHE
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down Expand Up @@ -728,7 +729,8 @@ public void testCanMountSnapshotTakenWhileConcurrentlyIndexing() throws Exceptio
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down Expand Up @@ -783,7 +785,8 @@ public void testMaxRestoreBytesPerSecIsUsed() throws Exception {
indexName,
Settings.builder().put(IndexSettings.INDEX_CHECK_ON_STARTUP.getKey(), Boolean.FALSE.toString()).build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restore = client().execute(MountSearchableSnapshotAction.INSTANCE, mount).get();
Expand Down Expand Up @@ -862,7 +865,8 @@ public void testMountedSnapshotHasNoReplicasByDefault() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down Expand Up @@ -896,7 +900,8 @@ public void testMountedSnapshotHasNoReplicasByDefault() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down Expand Up @@ -929,7 +934,8 @@ public void testMountedSnapshotHasNoReplicasByDefault() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void createAndMountSearchableSnapshot() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
randomFrom(MountSearchableSnapshotRequest.Storage.values())
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand All @@ -96,7 +97,8 @@ public void testMountRequiresLicense() {
indexName,
Settings.EMPTY,
Strings.EMPTY_ARRAY,
randomBoolean()
randomBoolean(),
randomFrom(MountSearchableSnapshotRequest.Storage.values())
);

final ActionFuture<RestoreSnapshotResponse> future = client().execute(MountSearchableSnapshotAction.INSTANCE, req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ public void testConcurrentPrewarming() throws Exception {
indexName,
restoredIndexSettings,
Strings.EMPTY_ARRAY,
true
true,
MountSearchableSnapshotRequest.Storage.FULL_COPY
)
).get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void createAndMountSearchableSnapshot() throws Exception {
indexName,
indexSettingsBuilder.build(),
Strings.EMPTY_ARRAY,
true
true,
randomFrom(MountSearchableSnapshotRequest.Storage.values())
);

final RestoreSnapshotResponse restoreSnapshotResponse = client().execute(MountSearchableSnapshotAction.INSTANCE, req).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ private void executeTest(final String indexName, final Client client) throws Exc
indexName,
Settings.builder().put(IndexMetadata.SETTING_INDEX_HIDDEN, randomBoolean()).build(),
Strings.EMPTY_ARRAY,
true
true,
randomFrom(MountSearchableSnapshotRequest.Storage.values())
);

final ElasticsearchException exception = expectThrows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public void testMountFailsIfSnapshotChanged() throws Exception {
indexName,
Settings.EMPTY,
Strings.EMPTY_ARRAY,
true
true,
randomFrom(MountSearchableSnapshotRequest.Storage.values())
);

final ActionFuture<RestoreSnapshotResponse> responseFuture = client().execute(MountSearchableSnapshotAction.INSTANCE, req);
Expand Down
Loading