Skip to content
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

Add a new write_only_allow_delete indexing block #12385

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;

public class PendingTasksBlocksIT extends OpenSearchIntegTestCase {

Expand All @@ -57,7 +58,8 @@ public void testPendingTasksWithIndexBlocks() {
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_BLOCKS_METADATA,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -60,7 +61,8 @@ public void testClearIndicesCacheWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
Expand Down Expand Up @@ -102,7 +104,8 @@ public void testClearIndicesFileCacheWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.action.admin.indices.delete;

import org.opensearch.action.support.IndicesOptions;
import org.opensearch.cluster.block.ClusterBlock;
import org.opensearch.cluster.block.ClusterBlockException;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.Metadata;
Expand All @@ -56,35 +57,10 @@ public void testDeleteIndexWithBlocks() {
}

public void testDeleteIndexOnIndexReadOnlyAllowDeleteSetting() {
createIndex("test");
ensureGreen("test");
client().prepareIndex().setIndex("test").setId("1").setSource("foo", "bar").get();
refresh();
try {
Settings settings = Settings.builder().put(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, true).build();
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settings).get());
assertSearchHits(client().prepareSearch().get(), "1");
assertBlocked(
client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"),
IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK
);
assertBlocked(
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 2)),
IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK
);
assertSearchHits(client().prepareSearch().get(), "1");
assertAcked(client().admin().indices().prepareDelete("test"));
} finally {
Settings settings = Settings.builder().putNull(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE).build();
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setSettings(settings)
.get()
);
}
assertDeleteIndexOnAllowDeleteSetting(
IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE,
IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK
);
}

public void testClusterBlockMessageHasIndexName() {
Expand Down Expand Up @@ -137,4 +113,40 @@ public void testDeleteIndexOnClusterReadOnlyAllowDeleteSetting() {
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get());
}
}

public void testDeleteIndexOnIndexWriteOnlyAllowDeleteSetting() {
assertDeleteIndexOnAllowDeleteSetting(
IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE,
IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK
);
}

private void assertDeleteIndexOnAllowDeleteSetting(String settingName, ClusterBlock blockToAssert) {
createIndex("test");
ensureGreen("test");
client().prepareIndex().setIndex("test").setId("1").setSource("foo", "bar").get();
refresh();
try {
Settings settings = Settings.builder().put(settingName, true).build();
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settings).get());
assertSearchHits(client().prepareSearch().get(), "1");
assertBlocked(client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"), blockToAssert);
assertBlocked(
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 2)),
blockToAssert
);
assertSearchHits(client().prepareSearch().get(), "1");
assertAcked(client().admin().indices().prepareDelete("test"));
} finally {
Settings settings = Settings.builder().putNull(settingName).build();
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setSettings(settings)
.get()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;

Expand All @@ -64,7 +65,8 @@ public void testFlushWithBlocks() {
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_BLOCKS_METADATA,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -73,7 +74,12 @@ public void testForceMergeWithBlocks() {
}

// Request is blocked
for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, SETTING_READ_ONLY_ALLOW_DELETE)) {
for (String blockSetting : Arrays.asList(
SETTING_READ_ONLY,
SETTING_BLOCKS_METADATA,
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
assertBlocked(client().admin().indices().prepareForceMerge("test"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -213,7 +214,13 @@ public void testEmptyMixedFeatures() {
}

public void testGetIndexWithBlocks() {
for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE)) {
for (String block : Arrays.asList(
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("idx", block);
GetIndexResponse response = client().admin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;

Expand All @@ -59,7 +60,8 @@ public void testRefreshWithBlocks() {
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_BLOCKS_METADATA,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures;

Expand All @@ -62,7 +63,8 @@ public void testIndicesSegmentsWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test-blocks", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;

@ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST)
public class IndicesStatsBlocksIT extends OpenSearchIntegTestCase {
Expand All @@ -56,7 +57,8 @@ public void testIndicesStatsWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("ro", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static org.opensearch.action.support.IndicesOptions.lenientExpandOpen;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.search.internal.SearchContext.TRACK_TOTAL_HITS_ACCURATE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
Expand Down Expand Up @@ -201,6 +202,16 @@ private void setIndexReadOnly(String index, Object value) {
assertThat(settingsResponse, notNullValue());
}

private void setIndexWriteOnlyDeleteAllow(String index, Object value) {
HashMap<String, Object> newSettings = new HashMap<>();
newSettings.put(SETTING_WRITE_ONLY_ALLOW_DELETE, value);

UpdateSettingsRequestBuilder settingsRequest = client().admin().indices().prepareUpdateSettings(index);
settingsRequest.setSettings(newSettings);
AcknowledgedResponse settingsResponse = settingsRequest.execute().actionGet();
assertThat(settingsResponse, notNullValue());
}

public void testAddBlocksWhileExistingBlocks() {
createIndex("test");
ensureGreen("test");
Expand All @@ -223,7 +234,12 @@ public void testAddBlocksWhileExistingBlocks() {
}
}

for (APIBlock block : Arrays.asList(APIBlock.READ_ONLY, APIBlock.METADATA, APIBlock.READ_ONLY_ALLOW_DELETE)) {
for (APIBlock block : Arrays.asList(
APIBlock.READ_ONLY,
APIBlock.METADATA,
APIBlock.READ_ONLY_ALLOW_DELETE,
APIBlock.WRITE_ONLY_ALLOW_DELETE
)) {
boolean success = false;
try {
enableIndexBlock("test", block.settingName());
Expand Down Expand Up @@ -542,6 +558,33 @@ public void testAddBlockWhileDeletingIndices() throws Exception {
}
}

public void testVerifyIndexWriteOnlyAllowDelete() {
// newly created an index has no plocks
canCreateIndex("test1");
canIndexDocument("test1");
canIndexExists("test1");

// adds index write-only-allow-delete block
setIndexWriteOnlyDeleteAllow("test1", "true");
assertIndexHasBlock(APIBlock.WRITE_ONLY_ALLOW_DELETE, "test1");
canNotIndexDocument("test1");
canIndexExists("test1");

// other indices not blocked
canCreateIndex("test2");
canIndexDocument("test2");
canIndexExists("test2");

// assert index can be deleted
assertAcked(client().admin().indices().prepareDelete("test1"));

// assert block can be removed
setIndexWriteOnlyDeleteAllow("test2", "true");
assertIndexHasBlock(APIBlock.WRITE_ONLY_ALLOW_DELETE, "test2");
setIndexWriteOnlyDeleteAllow("test2", "false");
canIndexDocument("test2");
}

static void assertIndexHasBlock(APIBlock block, final String... indices) {
final ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
for (String index : indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
Expand Down Expand Up @@ -557,7 +558,8 @@ public void testClusterRerouteWithBlocks() {
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_BLOCKS_METADATA,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test-blocks", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked;
import static org.hamcrest.Matchers.equalTo;

Expand Down Expand Up @@ -182,7 +183,8 @@ public void testClusterSearchShardsWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("test-blocks", blockSetting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;

Expand Down Expand Up @@ -88,7 +89,8 @@ public void testIndicesExistsWithBlocks() {
SETTING_BLOCKS_READ,
SETTING_BLOCKS_WRITE,
SETTING_READ_ONLY,
SETTING_READ_ONLY_ALLOW_DELETE
SETTING_READ_ONLY_ALLOW_DELETE,
SETTING_WRITE_ONLY_ALLOW_DELETE
)) {
try {
enableIndexBlock("ro", blockSetting);
Expand Down
Loading
Loading