6
6
package org .elasticsearch .xpack .searchablesnapshots ;
7
7
8
8
import org .apache .lucene .util .SetOnce ;
9
+ import org .elasticsearch .Build ;
9
10
import org .elasticsearch .action .ActionRequest ;
10
11
import org .elasticsearch .action .ActionResponse ;
11
12
import org .elasticsearch .client .Client ;
69
70
*/
70
71
public class SearchableSnapshots extends Plugin implements IndexStorePlugin , RepositoryPlugin , EnginePlugin , ActionPlugin , ClusterPlugin {
71
72
73
+ private static final boolean SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ;
74
+
75
+ static {
76
+ final String property = System .getProperty ("es.searchable_snapshots_feature_enabled" );
77
+ if ("true" .equals (property )) {
78
+ SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = true ;
79
+ } else if ("false" .equals (property )) {
80
+ SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = false ;
81
+ } else if (property == null ) {
82
+ SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED = Build .CURRENT .isSnapshot ();
83
+ } else {
84
+ throw new IllegalArgumentException (
85
+ "expected es.searchable_snapshots_feature_enabled to be unset or [true|false] but was [" + property + "]"
86
+ );
87
+ }
88
+ }
89
+
72
90
public static final Setting <String > SNAPSHOT_REPOSITORY_SETTING =
73
91
Setting .simpleString ("index.store.snapshot.repository_name" , Setting .Property .IndexScope , Setting .Property .PrivateIndex );
74
92
public static final Setting <String > SNAPSHOT_SNAPSHOT_NAME_SETTING =
@@ -101,16 +119,20 @@ public SearchableSnapshots(final Settings settings) {
101
119
102
120
@ Override
103
121
public List <Setting <?>> getSettings () {
104
- return List .of (SNAPSHOT_REPOSITORY_SETTING ,
105
- SNAPSHOT_SNAPSHOT_NAME_SETTING ,
106
- SNAPSHOT_SNAPSHOT_ID_SETTING ,
107
- SNAPSHOT_INDEX_ID_SETTING ,
108
- SNAPSHOT_CACHE_ENABLED_SETTING ,
109
- SNAPSHOT_CACHE_EXCLUDED_FILE_TYPES_SETTING ,
110
- SNAPSHOT_UNCACHED_CHUNK_SIZE_SETTING ,
111
- CacheService .SNAPSHOT_CACHE_SIZE_SETTING ,
112
- CacheService .SNAPSHOT_CACHE_RANGE_SIZE_SETTING
113
- );
122
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
123
+ return List .of (SNAPSHOT_REPOSITORY_SETTING ,
124
+ SNAPSHOT_SNAPSHOT_NAME_SETTING ,
125
+ SNAPSHOT_SNAPSHOT_ID_SETTING ,
126
+ SNAPSHOT_INDEX_ID_SETTING ,
127
+ SNAPSHOT_CACHE_ENABLED_SETTING ,
128
+ SNAPSHOT_CACHE_EXCLUDED_FILE_TYPES_SETTING ,
129
+ SNAPSHOT_UNCACHED_CHUNK_SIZE_SETTING ,
130
+ CacheService .SNAPSHOT_CACHE_SIZE_SETTING ,
131
+ CacheService .SNAPSHOT_CACHE_RANGE_SIZE_SETTING
132
+ );
133
+ } else {
134
+ return List .of ();
135
+ }
114
136
}
115
137
116
138
@ Override
@@ -125,10 +147,13 @@ public Collection<Object> createComponents(
125
147
final NodeEnvironment nodeEnvironment ,
126
148
final NamedWriteableRegistry registry ,
127
149
final IndexNameExpressionResolver resolver ) {
128
-
129
- final CacheService cacheService = new CacheService (settings );
130
- this .cacheService .set (cacheService );
131
- return List .of (cacheService );
150
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
151
+ final CacheService cacheService = new CacheService (settings );
152
+ this .cacheService .set (cacheService );
153
+ return List .of (cacheService );
154
+ } else {
155
+ return List .of ();
156
+ }
132
157
}
133
158
134
159
@ Override
@@ -139,25 +164,30 @@ public void onRepositoriesModule(RepositoriesModule repositoriesModule) {
139
164
140
165
@ Override
141
166
public void onIndexModule (IndexModule indexModule ) {
142
- if (isSearchableSnapshotStore (indexModule .getSettings ())) {
167
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED && isSearchableSnapshotStore (indexModule .getSettings ())) {
143
168
indexModule .addIndexEventListener (new SearchableSnapshotIndexEventListener ());
144
169
}
145
170
}
146
171
147
172
@ Override
148
173
public Map <String , DirectoryFactory > getDirectoryFactories () {
149
- return Map .of (SNAPSHOT_DIRECTORY_FACTORY_KEY , (indexSettings , shardPath ) -> {
150
- final RepositoriesService repositories = repositoriesService .get ();
151
- assert repositories != null ;
152
- final CacheService cache = cacheService .get ();
153
- assert cache != null ;
154
- return SearchableSnapshotDirectory .create (repositories , cache , indexSettings , shardPath , System ::nanoTime );
155
- });
174
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
175
+ return Map .of (SNAPSHOT_DIRECTORY_FACTORY_KEY , (indexSettings , shardPath ) -> {
176
+ final RepositoriesService repositories = repositoriesService .get ();
177
+ assert repositories != null ;
178
+ final CacheService cache = cacheService .get ();
179
+ assert cache != null ;
180
+ return SearchableSnapshotDirectory .create (repositories , cache , indexSettings , shardPath , System ::nanoTime );
181
+ });
182
+ } else {
183
+ return Map .of ();
184
+ }
156
185
}
157
186
158
187
@ Override
159
188
public Optional <EngineFactory > getEngineFactory (IndexSettings indexSettings ) {
160
- if (isSearchableSnapshotStore (indexSettings .getSettings ())
189
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED
190
+ && isSearchableSnapshotStore (indexSettings .getSettings ())
161
191
&& indexSettings .getSettings ().getAsBoolean ("index.frozen" , false ) == false ) {
162
192
return Optional .of (engineConfig -> new ReadOnlyEngine (engineConfig , null , new TranslogStats (), false , Function .identity ()));
163
193
}
@@ -166,27 +196,39 @@ public Optional<EngineFactory> getEngineFactory(IndexSettings indexSettings) {
166
196
167
197
@ Override
168
198
public List <ActionHandler <? extends ActionRequest , ? extends ActionResponse >> getActions () {
169
- return List .of (
170
- new ActionHandler <>(SearchableSnapshotsStatsAction .INSTANCE , TransportSearchableSnapshotsStatsAction .class ),
171
- new ActionHandler <>(ClearSearchableSnapshotsCacheAction .INSTANCE , TransportClearSearchableSnapshotsCacheAction .class ),
172
- new ActionHandler <>(MountSearchableSnapshotAction .INSTANCE , TransportMountSearchableSnapshotAction .class )
173
- );
199
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
200
+ return List .of (
201
+ new ActionHandler <>(SearchableSnapshotsStatsAction .INSTANCE , TransportSearchableSnapshotsStatsAction .class ),
202
+ new ActionHandler <>(ClearSearchableSnapshotsCacheAction .INSTANCE , TransportClearSearchableSnapshotsCacheAction .class ),
203
+ new ActionHandler <>(MountSearchableSnapshotAction .INSTANCE , TransportMountSearchableSnapshotAction .class )
204
+ );
205
+ } else {
206
+ return List .of ();
207
+ }
174
208
}
175
209
176
210
public List <RestHandler > getRestHandlers (Settings settings , RestController restController , ClusterSettings clusterSettings ,
177
211
IndexScopedSettings indexScopedSettings , SettingsFilter settingsFilter ,
178
212
IndexNameExpressionResolver indexNameExpressionResolver ,
179
213
Supplier <DiscoveryNodes > nodesInCluster ) {
180
- return List .of (
181
- new RestSearchableSnapshotsStatsAction (),
182
- new RestClearSearchableSnapshotsCacheAction (),
183
- new RestMountSearchableSnapshotAction ()
184
- );
214
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
215
+ return List .of (
216
+ new RestSearchableSnapshotsStatsAction (),
217
+ new RestClearSearchableSnapshotsCacheAction (),
218
+ new RestMountSearchableSnapshotAction ()
219
+ );
220
+ } else {
221
+ return List .of ();
222
+ }
185
223
}
186
224
187
225
@ Override
188
226
public Map <String , ExistingShardsAllocator > getExistingShardsAllocators () {
189
- return Collections .singletonMap (SearchableSnapshotAllocator .ALLOCATOR_NAME , new SearchableSnapshotAllocator ());
227
+ if (SEARCHABLE_SNAPSHOTS_FEATURE_ENABLED ) {
228
+ return Collections .singletonMap (SearchableSnapshotAllocator .ALLOCATOR_NAME , new SearchableSnapshotAllocator ());
229
+ } else {
230
+ return Collections .emptyMap ();
231
+ }
190
232
}
191
233
192
234
static boolean isSearchableSnapshotStore (Settings indexSettings ) {
0 commit comments