-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Use write block on archive indices #85102
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
113 changes: 113 additions & 0 deletions
113
.../internalClusterTest/java/org/elasticsearch/xpack/lucene/bwc/AbstractArchiveTestCase.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,113 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.lucene.bwc; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.RepositoryMetadata; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.BigArrays; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.indices.recovery.RecoverySettings; | ||
import org.elasticsearch.license.License; | ||
import org.elasticsearch.license.PostStartTrialAction; | ||
import org.elasticsearch.license.PostStartTrialRequest; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.plugins.RepositoryPlugin; | ||
import org.elasticsearch.repositories.IndexId; | ||
import org.elasticsearch.repositories.Repository; | ||
import org.elasticsearch.repositories.RepositoryData; | ||
import org.elasticsearch.repositories.fs.FsRepository; | ||
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase; | ||
import org.elasticsearch.snapshots.SnapshotId; | ||
import org.elasticsearch.snapshots.mockstore.MockRepository; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.xcontent.NamedXContentRegistry; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
@ESIntegTestCase.ClusterScope(supportsDedicatedMasters = false, numClientNodes = 0, scope = ESIntegTestCase.Scope.TEST) | ||
public abstract class AbstractArchiveTestCase extends AbstractSnapshotIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(LocalStateOldLuceneVersions.class, TestRepositoryPlugin.class, MockRepository.Plugin.class); | ||
} | ||
|
||
public static class TestRepositoryPlugin extends Plugin implements RepositoryPlugin { | ||
public static final String FAKE_VERSIONS_TYPE = "fakeversionsrepo"; | ||
|
||
@Override | ||
public Map<String, Repository.Factory> getRepositories( | ||
Environment env, | ||
NamedXContentRegistry namedXContentRegistry, | ||
ClusterService clusterService, | ||
BigArrays bigArrays, | ||
RecoverySettings recoverySettings | ||
) { | ||
return Map.of( | ||
FAKE_VERSIONS_TYPE, | ||
metadata -> new FakeVersionsRepo(metadata, env, namedXContentRegistry, clusterService, bigArrays, recoverySettings) | ||
); | ||
} | ||
|
||
// fakes an old index version format to activate license checks | ||
private static class FakeVersionsRepo extends FsRepository { | ||
FakeVersionsRepo( | ||
RepositoryMetadata metadata, | ||
Environment env, | ||
NamedXContentRegistry namedXContentRegistry, | ||
ClusterService clusterService, | ||
BigArrays bigArrays, | ||
RecoverySettings recoverySettings | ||
) { | ||
super(metadata, env, namedXContentRegistry, clusterService, bigArrays, recoverySettings); | ||
} | ||
|
||
@Override | ||
public IndexMetadata getSnapshotIndexMetaData(RepositoryData repositoryData, SnapshotId snapshotId, IndexId index) | ||
throws IOException { | ||
final IndexMetadata original = super.getSnapshotIndexMetaData(repositoryData, snapshotId, index); | ||
return IndexMetadata.builder(original) | ||
.settings( | ||
Settings.builder() | ||
.put(original.getSettings()) | ||
.put( | ||
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), | ||
metadata.settings() | ||
.getAsVersion("version", randomBoolean() ? Version.fromString("5.0.0") : Version.fromString("6.0.0")) | ||
) | ||
) | ||
.build(); | ||
} | ||
} | ||
} | ||
|
||
protected static final String repoName = "test-repo"; | ||
protected static final String indexName = "test-index"; | ||
protected static final String snapshotName = "test-snapshot"; | ||
|
||
@Before | ||
public void createAndRestoreArchive() throws Exception { | ||
createRepository(repoName, TestRepositoryPlugin.FAKE_VERSIONS_TYPE); | ||
createIndex(indexName); | ||
createFullSnapshot(repoName, snapshotName); | ||
|
||
assertAcked(client().admin().indices().prepareDelete(indexName)); | ||
|
||
PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true); | ||
client().execute(PostStartTrialAction.INSTANCE, request).get(); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...usterTest/java/org/elasticsearch/xpack/lucene/bwc/ArchiveSettingValidationIntegTests.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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.lucene.bwc; | ||
|
||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.common.settings.Settings; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ArchiveSettingValidationIntegTests extends AbstractArchiveTestCase { | ||
public void testCannotRemoveWriteBlock() throws ExecutionException, InterruptedException { | ||
final RestoreSnapshotRequest req = new RestoreSnapshotRequest(repoName, snapshotName).indices(indexName).waitForCompletion(true); | ||
|
||
final RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().restoreSnapshot(req).get(); | ||
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0)); | ||
ensureGreen(indexName); | ||
|
||
final IllegalArgumentException iae = expectThrows( | ||
IllegalArgumentException.class, | ||
() -> client().admin() | ||
.indices() | ||
.prepareUpdateSettings(indexName) | ||
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), false)) | ||
.get() | ||
); | ||
assertThat( | ||
iae.getMessage(), | ||
containsString("illegal value can't update [" + IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey() + "] from [true] to [false]") | ||
); | ||
assertNotNull(iae.getCause()); | ||
assertThat(iae.getCause().getMessage(), containsString("Cannot remove write block from archive index")); | ||
|
||
client().admin() | ||
.indices() | ||
.prepareUpdateSettings(indexName) | ||
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true)) | ||
.get(); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all this code has just been extracted to a base class