Merge pull request #14169 from s1monw/issues/14168
Add option to disable closing indices
This commit is contained in:
commit
14aaeea25a
|
@ -36,15 +36,15 @@ import org.elasticsearch.node.settings.NodeSettingsService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close index action
|
* Close index action
|
||||||
*/
|
*/
|
||||||
public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIndexRequest, CloseIndexResponse> {
|
public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIndexRequest, CloseIndexResponse> implements NodeSettingsService.Listener {
|
||||||
|
|
||||||
private final MetaDataIndexStateService indexStateService;
|
private final MetaDataIndexStateService indexStateService;
|
||||||
private final DestructiveOperations destructiveOperations;
|
private final DestructiveOperations destructiveOperations;
|
||||||
|
private volatile boolean closeIndexEnabled;
|
||||||
|
public static final String SETTING_CLUSTER_INDICES_CLOSE_ENABLE = "cluster.indices.close.enable";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportCloseIndexAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
public TransportCloseIndexAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||||
|
@ -54,6 +54,8 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIn
|
||||||
super(settings, CloseIndexAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, CloseIndexRequest::new);
|
super(settings, CloseIndexAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, CloseIndexRequest::new);
|
||||||
this.indexStateService = indexStateService;
|
this.indexStateService = indexStateService;
|
||||||
this.destructiveOperations = destructiveOperations;
|
this.destructiveOperations = destructiveOperations;
|
||||||
|
this.closeIndexEnabled = settings.getAsBoolean(SETTING_CLUSTER_INDICES_CLOSE_ENABLE, true);
|
||||||
|
nodeSettingsService.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,6 +72,9 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIn
|
||||||
@Override
|
@Override
|
||||||
protected void doExecute(CloseIndexRequest request, ActionListener<CloseIndexResponse> listener) {
|
protected void doExecute(CloseIndexRequest request, ActionListener<CloseIndexResponse> listener) {
|
||||||
destructiveOperations.failDestructive(request.indices());
|
destructiveOperations.failDestructive(request.indices());
|
||||||
|
if (closeIndexEnabled == false) {
|
||||||
|
throw new IllegalStateException("closing indices is disabled - set [" + SETTING_CLUSTER_INDICES_CLOSE_ENABLE + ": true] to enable it. NOTE: closed indices still consume a significant amount of diskspace");
|
||||||
|
}
|
||||||
super.doExecute(request, listener);
|
super.doExecute(request, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,4 +104,13 @@ public class TransportCloseIndexAction extends TransportMasterNodeAction<CloseIn
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRefreshSettings(Settings settings) {
|
||||||
|
final boolean enable = settings.getAsBoolean(SETTING_CLUSTER_INDICES_CLOSE_ENABLE, this.closeIndexEnabled);
|
||||||
|
if (enable != this.closeIndexEnabled) {
|
||||||
|
logger.info("updating [{}] from [{}] to [{}]", SETTING_CLUSTER_INDICES_CLOSE_ENABLE, this.closeIndexEnabled, enable);
|
||||||
|
this.closeIndexEnabled = enable;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.cluster;
|
package org.elasticsearch.cluster;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
|
||||||
import org.elasticsearch.action.support.DestructiveOperations;
|
import org.elasticsearch.action.support.DestructiveOperations;
|
||||||
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
||||||
import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction;
|
import org.elasticsearch.cluster.action.index.NodeIndexDeletedAction;
|
||||||
|
@ -202,6 +203,7 @@ public class ClusterModule extends AbstractModule {
|
||||||
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_INCLUDE + ".*", Validator.EMPTY);
|
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_INCLUDE + ".*", Validator.EMPTY);
|
||||||
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_EXCLUDE, Validator.EMPTY);
|
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_EXCLUDE, Validator.EMPTY);
|
||||||
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_EXCLUDE + ".*", Validator.EMPTY);
|
registerClusterDynamicSetting(TransportService.SETTING_TRACE_LOG_EXCLUDE + ".*", Validator.EMPTY);
|
||||||
|
registerClusterDynamicSetting(TransportCloseIndexAction.SETTING_CLUSTER_INDICES_CLOSE_ENABLE, Validator.BOOLEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerBuiltinIndexSettings() {
|
private void registerBuiltinIndexSettings() {
|
||||||
|
|
|
@ -21,7 +21,9 @@ package org.elasticsearch.indices.state;
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||||
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
|
import org.elasticsearch.action.admin.indices.close.CloseIndexResponse;
|
||||||
|
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
|
||||||
import org.elasticsearch.action.support.DestructiveOperations;
|
import org.elasticsearch.action.support.DestructiveOperations;
|
||||||
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
|
@ -32,7 +34,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
@ClusterScope(scope= Scope.TEST, numDataNodes =2)
|
@ClusterScope(scope=Scope.TEST, numDataNodes=2)
|
||||||
public class CloseIndexDisableCloseAllIT extends ESIntegTestCase {
|
public class CloseIndexDisableCloseAllIT extends ESIntegTestCase {
|
||||||
// Combined multiple tests into one, because cluster scope is test.
|
// Combined multiple tests into one, because cluster scope is test.
|
||||||
// The cluster scope is test b/c we can't clear cluster settings.
|
// The cluster scope is test b/c we can't clear cluster settings.
|
||||||
|
@ -83,6 +85,20 @@ public class CloseIndexDisableCloseAllIT extends ESIntegTestCase {
|
||||||
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test3", "test2").execute().actionGet();
|
CloseIndexResponse closeIndexResponse = client().admin().indices().prepareClose("test3", "test2").execute().actionGet();
|
||||||
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
|
assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
|
||||||
assertIndexIsClosed("test2", "test3");
|
assertIndexIsClosed("test2", "test3");
|
||||||
|
|
||||||
|
// disable closing
|
||||||
|
Client client = client();
|
||||||
|
createIndex("test_no_close");
|
||||||
|
healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
|
||||||
|
assertThat(healthResponse.isTimedOut(), equalTo(false));
|
||||||
|
client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(TransportCloseIndexAction.SETTING_CLUSTER_INDICES_CLOSE_ENABLE, false)).get();
|
||||||
|
|
||||||
|
try {
|
||||||
|
client.admin().indices().prepareClose("test_no_close").execute().actionGet();
|
||||||
|
fail("exception expected");
|
||||||
|
} catch (IllegalStateException ex) {
|
||||||
|
assertEquals(ex.getMessage(), "closing indices is disabled - set [cluster.indices.close.enable: true] to enable it. NOTE: closed indices still consume a significant amount of diskspace");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertIndexIsClosed(String... indices) {
|
private void assertIndexIsClosed(String... indices) {
|
||||||
|
|
|
@ -27,3 +27,7 @@ or specifying patterns that identify them all (e.g. `*`).
|
||||||
Identifying indices via wildcards or `_all` can be disabled by setting the
|
Identifying indices via wildcards or `_all` can be disabled by setting the
|
||||||
`action.destructive_requires_name` flag in the config file to `true`.
|
`action.destructive_requires_name` flag in the config file to `true`.
|
||||||
This setting can also be changed via the cluster update settings api.
|
This setting can also be changed via the cluster update settings api.
|
||||||
|
|
||||||
|
Closed indices consume a significant amount of disk-space which can cause problems
|
||||||
|
issues in managed environments. Closing indices can be disabled via the cluster settings
|
||||||
|
API by setting `cluster.indices.close.enable` to `false`. The default is `true`.
|
Loading…
Reference in New Issue