-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New setting to prevent automatically importing dangling indices (#49174)
Introduce a new static setting, `gateway.auto_import_dangling_indices`, which prevents dangling indices from being automatically imported. Part of #48366.
- Loading branch information
1 parent
770a794
commit f8e39d2
Showing
6 changed files
with
188 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
server/src/test/java/org/elasticsearch/indices/recovery/DanglingIndicesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.indices.recovery; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.test.InternalTestCluster; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.elasticsearch.cluster.metadata.IndexGraveyard.SETTING_MAX_TOMBSTONES; | ||
import static org.elasticsearch.gateway.DanglingIndicesState.AUTO_IMPORT_DANGLING_INDICES_SETTING; | ||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
@ClusterScope(numDataNodes = 0, scope = ESIntegTestCase.Scope.TEST) | ||
public class DanglingIndicesIT extends ESIntegTestCase { | ||
private static final String INDEX_NAME = "test-idx-1"; | ||
|
||
private Settings buildSettings(boolean importDanglingIndices) { | ||
return Settings.builder() | ||
// Don't keep any indices in the graveyard, so that when we delete an index, | ||
// it's definitely considered to be dangling. | ||
.put(SETTING_MAX_TOMBSTONES.getKey(), 0) | ||
.put(AUTO_IMPORT_DANGLING_INDICES_SETTING.getKey(), importDanglingIndices) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Check that when dangling indices are discovered, then they are recovered into | ||
* the cluster, so long as the recovery setting is enabled. | ||
*/ | ||
public void testDanglingIndicesAreRecoveredWhenSettingIsEnabled() throws Exception { | ||
final Settings settings = buildSettings(true); | ||
internalCluster().startNodes(3, settings); | ||
|
||
createIndex(INDEX_NAME, Settings.builder().put("number_of_replicas", 2).build()); | ||
|
||
// Restart node, deleting the index in its absence, so that there is a dangling index to recover | ||
internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { | ||
|
||
@Override | ||
public Settings onNodeStopped(String nodeName) throws Exception { | ||
assertAcked(client().admin().indices().prepareDelete(INDEX_NAME)); | ||
return super.onNodeStopped(nodeName); | ||
} | ||
}); | ||
|
||
assertBusy(() -> assertTrue("Expected dangling index " + INDEX_NAME + " to be recovered", indexExists(INDEX_NAME))); | ||
} | ||
|
||
/** | ||
* Check that when dangling indices are discovered, then they are not recovered into | ||
* the cluster when the recovery setting is disabled. | ||
*/ | ||
public void testDanglingIndicesAreNotRecoveredWhenSettingIsDisabled() throws Exception { | ||
internalCluster().startNodes(3, buildSettings(false)); | ||
|
||
createIndex(INDEX_NAME, Settings.builder().put("number_of_replicas", 2).build()); | ||
|
||
// Restart node, deleting the index in its absence, so that there is a dangling index to recover | ||
internalCluster().restartRandomDataNode(new InternalTestCluster.RestartCallback() { | ||
|
||
@Override | ||
public Settings onNodeStopped(String nodeName) throws Exception { | ||
assertAcked(client().admin().indices().prepareDelete(INDEX_NAME)); | ||
return super.onNodeStopped(nodeName); | ||
} | ||
}); | ||
|
||
// Since index recovery is async, we can't prove index recovery will never occur, just that it doesn't occur within some reasonable | ||
// amount of time | ||
assertFalse( | ||
"Did not expect dangling index " + INDEX_NAME + " to be recovered", | ||
waitUntil(() -> indexExists(INDEX_NAME), 1, TimeUnit.SECONDS) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters