Skip to content
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
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ testClusters.integTest {
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.autoscaling_feature_flag_registered', 'true'
systemProperty 'es.eql_feature_flag_registered', 'true'
systemProperty 'es.searchable_snapshots_feature_enabled', 'true'
}
setting 'xpack.autoscaling.enabled', 'true'
setting 'xpack.eql.enabled', 'true'
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugin/searchable-snapshots/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.elasticsearch.gradle.info.BuildParams

apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
Expand All @@ -14,6 +16,9 @@ integTest.runner {

testClusters.integTest {
testDistribution = 'DEFAULT'
if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.searchable_snapshots_feature_enabled', 'true'
}
setting 'path.repo', repoDir.absolutePath
}

Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugin/searchable-snapshots/qa/s3/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
import org.elasticsearch.gradle.info.BuildParams

apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test'
Expand Down Expand Up @@ -52,6 +53,10 @@ testClusters.integTest {
testDistribution = 'DEFAULT'
plugin file(repositoryPlugin.bundlePlugin.archiveFile)

if (BuildParams.isSnapshotBuild() == false) {
systemProperty 'es.searchable_snapshots_feature_enabled', 'true'
}

keystore 's3.client.searchable_snapshots.access_key', s3AccessKey
keystore 's3.client.searchable_snapshots.secret_key', s3SecretKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.elasticsearch.xpack.searchablesnapshots;

import org.apache.lucene.util.SetOnce;
import org.elasticsearch.Build;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.client.Client;
Expand Down Expand Up @@ -69,6 +70,23 @@
*/
public class SearchableSnapshots extends Plugin implements IndexStorePlugin, RepositoryPlugin, EnginePlugin, ActionPlugin, ClusterPlugin {

private static final boolean SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED;

static {
final String property = System.getProperty("es.searchable_snapshots_feature_enabled");
if ("true".equals(property)) {
SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = true;
} else if ("false".equals(property)) {
SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = false;
} else if (property == null) {
SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = Build.CURRENT.isSnapshot();
} else {
throw new IllegalArgumentException(
"expected es.searchable_snapshots_feature_enabled to be unset or [true|false] but was [" + property + "]"
);
}
}

public static final Setting<String> SNAPSHOT_REPOSITORY_SETTING =
Setting.simpleString("index.store.snapshot.repository_name", Setting.Property.IndexScope, Setting.Property.PrivateIndex);
public static final Setting<String> SNAPSHOT_SNAPSHOT_NAME_SETTING =
Expand Down Expand Up @@ -101,16 +119,20 @@ public SearchableSnapshots(final Settings settings) {

@Override
public List<Setting<?>> getSettings() {
return List.of(SNAPSHOT_REPOSITORY_SETTING,
SNAPSHOT_SNAPSHOT_NAME_SETTING,
SNAPSHOT_SNAPSHOT_ID_SETTING,
SNAPSHOT_INDEX_ID_SETTING,
SNAPSHOT_CACHE_ENABLED_SETTING,
SNAPSHOT_CACHE_EXCLUDED_FILE_TYPES_SETTING,
SNAPSHOT_UNCACHED_CHUNK_SIZE_SETTING,
CacheService.SNAPSHOT_CACHE_SIZE_SETTING,
CacheService.SNAPSHOT_CACHE_RANGE_SIZE_SETTING
);
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
return List.of(SNAPSHOT_REPOSITORY_SETTING,
SNAPSHOT_SNAPSHOT_NAME_SETTING,
SNAPSHOT_SNAPSHOT_ID_SETTING,
SNAPSHOT_INDEX_ID_SETTING,
SNAPSHOT_CACHE_ENABLED_SETTING,
SNAPSHOT_CACHE_EXCLUDED_FILE_TYPES_SETTING,
SNAPSHOT_UNCACHED_CHUNK_SIZE_SETTING,
CacheService.SNAPSHOT_CACHE_SIZE_SETTING,
CacheService.SNAPSHOT_CACHE_RANGE_SIZE_SETTING
);
} else {
return List.of();
}
}

@Override
Expand All @@ -125,10 +147,13 @@ public Collection<Object> createComponents(
final NodeEnvironment nodeEnvironment,
final NamedWriteableRegistry registry,
final IndexNameExpressionResolver resolver) {

final CacheService cacheService = new CacheService(settings);
this.cacheService.set(cacheService);
return List.of(cacheService);
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
final CacheService cacheService = new CacheService(settings);
this.cacheService.set(cacheService);
return List.of(cacheService);
} else {
return List.of();
}
}

@Override
Expand All @@ -139,25 +164,30 @@ public void onRepositoriesModule(RepositoriesModule repositoriesModule) {

@Override
public void onIndexModule(IndexModule indexModule) {
if (isSearchableSnapshotStore(indexModule.getSettings())) {
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED && isSearchableSnapshotStore(indexModule.getSettings())) {
indexModule.addIndexEventListener(new SearchableSnapshotIndexEventListener());
}
}

@Override
public Map<String, DirectoryFactory> getDirectoryFactories() {
return Map.of(SNAPSHOT_DIRECTORY_FACTORY_KEY, (indexSettings, shardPath) -> {
final RepositoriesService repositories = repositoriesService.get();
assert repositories != null;
final CacheService cache = cacheService.get();
assert cache != null;
return SearchableSnapshotDirectory.create(repositories, cache, indexSettings, shardPath, System::nanoTime);
});
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
return Map.of(SNAPSHOT_DIRECTORY_FACTORY_KEY, (indexSettings, shardPath) -> {
final RepositoriesService repositories = repositoriesService.get();
assert repositories != null;
final CacheService cache = cacheService.get();
assert cache != null;
return SearchableSnapshotDirectory.create(repositories, cache, indexSettings, shardPath, System::nanoTime);
});
} else {
return Map.of();
}
}

@Override
public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
if (isSearchableSnapshotStore(indexSettings.getSettings())
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED
&& isSearchableSnapshotStore(indexSettings.getSettings())
&& indexSettings.getSettings().getAsBoolean("index.frozen", false) == false) {
return Optional.of(engineConfig -> new ReadOnlyEngine(engineConfig, null, new TranslogStats(), false, Function.identity()));
}
Expand All @@ -166,27 +196,39 @@ public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return List.of(
new ActionHandler<>(SearchableSnapshotsStatsAction.INSTANCE, TransportSearchableSnapshotsStatsAction.class),
new ActionHandler<>(ClearSearchableSnapshotsCacheAction.INSTANCE, TransportClearSearchableSnapshotsCacheAction.class),
new ActionHandler<>(MountSearchableSnapshotAction.INSTANCE, TransportMountSearchableSnapshotAction.class)
);
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
return List.of(
new ActionHandler<>(SearchableSnapshotsStatsAction.INSTANCE, TransportSearchableSnapshotsStatsAction.class),
new ActionHandler<>(ClearSearchableSnapshotsCacheAction.INSTANCE, TransportClearSearchableSnapshotsCacheAction.class),
new ActionHandler<>(MountSearchableSnapshotAction.INSTANCE, TransportMountSearchableSnapshotAction.class)
);
} else {
return List.of();
}
}

public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return List.of(
new RestSearchableSnapshotsStatsAction(),
new RestClearSearchableSnapshotsCacheAction(),
new RestMountSearchableSnapshotAction()
);
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
return List.of(
new RestSearchableSnapshotsStatsAction(),
new RestClearSearchableSnapshotsCacheAction(),
new RestMountSearchableSnapshotAction()
);
} else {
return List.of();
}
}

@Override
public Map<String, ExistingShardsAllocator> getExistingShardsAllocators() {
return Collections.singletonMap(SearchableSnapshotAllocator.ALLOCATOR_NAME, new SearchableSnapshotAllocator());
if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED) {
return Collections.singletonMap(SearchableSnapshotAllocator.ALLOCATOR_NAME, new SearchableSnapshotAllocator());
} else {
return Collections.emptyMap();
}
}

static boolean isSearchableSnapshotStore(Settings indexSettings) {
Expand Down