Index Blocks: Add index.blocks.write, index.blocks.read, and index.blocks.metadata settings, closes #1771.
This commit is contained in:
parent
3789983c7a
commit
e707e93942
|
@ -56,9 +56,15 @@ public class IndexMetaData {
|
|||
.add(IndexMetaData.SETTING_NUMBER_OF_REPLICAS)
|
||||
.add(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS)
|
||||
.add(IndexMetaData.SETTING_READ_ONLY)
|
||||
.add(IndexMetaData.SETTING_BLOCKS_READ)
|
||||
.add(IndexMetaData.SETTING_BLOCKS_WRITE)
|
||||
.add(IndexMetaData.SETTING_BLOCKS_METADATA)
|
||||
.build();
|
||||
|
||||
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(5, "index read-only (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA);
|
||||
public static final ClusterBlock INDEX_READ_BLOCK = new ClusterBlock(7, "index read (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.READ);
|
||||
public static final ClusterBlock INDEX_WRITE_BLOCK = new ClusterBlock(8, "index write (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.WRITE);
|
||||
public static final ClusterBlock INDEX_METADATA_BLOCK = new ClusterBlock(9, "index metadata (api)", false, false, RestStatus.FORBIDDEN, ClusterBlockLevel.METADATA);
|
||||
|
||||
public static ImmutableSet<String> dynamicSettings() {
|
||||
return dynamicSettings;
|
||||
|
@ -116,6 +122,9 @@ public class IndexMetaData {
|
|||
public static final String SETTING_NUMBER_OF_REPLICAS = "index.number_of_replicas";
|
||||
public static final String SETTING_AUTO_EXPAND_REPLICAS = "index.auto_expand_replicas";
|
||||
public static final String SETTING_READ_ONLY = "index.blocks.read_only";
|
||||
public static final String SETTING_BLOCKS_READ = "index.blocks.read";
|
||||
public static final String SETTING_BLOCKS_WRITE = "index.blocks.write";
|
||||
public static final String SETTING_BLOCKS_METADATA = "index.blocks.metadata";
|
||||
public static final String SETTING_VERSION_CREATED = "index.version.created";
|
||||
|
||||
private final String index;
|
||||
|
|
|
@ -175,6 +175,38 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
|
|||
}
|
||||
}
|
||||
}
|
||||
Boolean updateMetaDataBlock = openSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_METADATA, null);
|
||||
if (updateMetaDataBlock != null) {
|
||||
for (String index : actualIndices) {
|
||||
if (updateMetaDataBlock) {
|
||||
blocks.addIndexBlock(index, IndexMetaData.INDEX_METADATA_BLOCK);
|
||||
} else {
|
||||
blocks.removeIndexBlock(index, IndexMetaData.INDEX_METADATA_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Boolean updateWriteBlock = openSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_WRITE, null);
|
||||
if (updateWriteBlock != null) {
|
||||
for (String index : actualIndices) {
|
||||
if (updateWriteBlock) {
|
||||
blocks.addIndexBlock(index, IndexMetaData.INDEX_WRITE_BLOCK);
|
||||
} else {
|
||||
blocks.removeIndexBlock(index, IndexMetaData.INDEX_WRITE_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Boolean updateReadBlock = openSettings.getAsBoolean(IndexMetaData.SETTING_BLOCKS_READ, null);
|
||||
if (updateReadBlock != null) {
|
||||
for (String index : actualIndices) {
|
||||
if (updateReadBlock) {
|
||||
blocks.addIndexBlock(index, IndexMetaData.INDEX_READ_BLOCK);
|
||||
} else {
|
||||
blocks.removeIndexBlock(index, IndexMetaData.INDEX_READ_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// allow to change any settings to a close index, and only allow dynamic settings to be changed
|
||||
// on an open index
|
||||
|
|
|
@ -262,6 +262,15 @@ public class GatewayService extends AbstractLifecycleComponent<GatewayService> i
|
|||
if (indexMetaData.settings().getAsBoolean(IndexMetaData.SETTING_READ_ONLY, false)) {
|
||||
blocks.addIndexBlock(indexMetaData.index(), IndexMetaData.INDEX_READ_ONLY_BLOCK);
|
||||
}
|
||||
if (indexMetaData.settings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_READ, false)) {
|
||||
blocks.addIndexBlock(indexMetaData.index(), IndexMetaData.INDEX_READ_BLOCK);
|
||||
}
|
||||
if (indexMetaData.settings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_WRITE, false)) {
|
||||
blocks.addIndexBlock(indexMetaData.index(), IndexMetaData.INDEX_WRITE_BLOCK);
|
||||
}
|
||||
if (indexMetaData.settings().getAsBoolean(IndexMetaData.SETTING_BLOCKS_METADATA, false)) {
|
||||
blocks.addIndexBlock(indexMetaData.index(), IndexMetaData.INDEX_METADATA_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
// update the state to reflect the new metadata and routing
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.test.integration.readonly;
|
||||
package org.elasticsearch.test.integration.blocks;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
|
||||
|
@ -38,11 +38,12 @@ import org.testng.annotations.Test;
|
|||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@Test
|
||||
public class ClusterAndIndexReaderOnlyTests extends AbstractNodesTests {
|
||||
public class SimpleBlocksTests extends AbstractNodesTests {
|
||||
|
||||
@AfterMethod
|
||||
public void closeNodes() {
|
||||
|
@ -50,7 +51,7 @@ public class ClusterAndIndexReaderOnlyTests extends AbstractNodesTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void verifyReadOnly() throws Exception {
|
||||
public void verifyIndexAndClusterReadOnly() throws Exception {
|
||||
Node node1 = startNode("node1");
|
||||
Client client = node1.client();
|
||||
|
||||
|
@ -96,6 +97,23 @@ public class ClusterAndIndexReaderOnlyTests extends AbstractNodesTests {
|
|||
canIndexExists(client, "ro");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexReadWriteMetaDataBlocks() {
|
||||
Node node1 = startNode("node1");
|
||||
Client client = node1.client();
|
||||
|
||||
canCreateIndex(client, "test1");
|
||||
canIndexDocument(client, "test1");
|
||||
client.admin().indices().prepareUpdateSettings("test1")
|
||||
.setSettings(settingsBuilder().put(IndexMetaData.SETTING_BLOCKS_WRITE, true))
|
||||
.execute().actionGet();
|
||||
canNotIndexDocument(client, "test1");
|
||||
client.admin().indices().prepareUpdateSettings("test1")
|
||||
.setSettings(settingsBuilder().put(IndexMetaData.SETTING_BLOCKS_WRITE, false))
|
||||
.execute().actionGet();
|
||||
canIndexDocument(client, "test1");
|
||||
}
|
||||
|
||||
private void canCreateIndex(Client client, String index) {
|
||||
try {
|
||||
CreateIndexResponse r = client.admin().indices().prepareCreate(index).execute().actionGet();
|
Loading…
Reference in New Issue