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 cluster block that allows to delete indices that are read-only #24678

Merged
merged 6 commits into from
May 16, 2017

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented May 15, 2017

Today when an index is read-only the index is also blocked from
being deleted which sometimes is undesired since in-order to make
changes to a cluster indices must be deleted to free up space. This is
a likely scenario in a hosted environment when disk-space is limited to switch
indices read-only but allow deletions to free up space.

Today when an index is `read-only` the index is also blocked from
being deleted which sometimes is undesired since in-order to make
changes to a cluster indices must be deleted to free up space. This is
a likely scenario in a hosted enviroment when disk-space is limited to switch
indices read-only but allow deletions to free up space.
@s1monw
Copy link
Contributor Author

s1monw commented May 15, 2017

Relates to #24299

Copy link
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left some nitty comments. Feel free to accept or reject.

(request.persistentSettings().isEmpty() && request.transientSettings().size() == 1 &&
MetaData.SETTING_READ_ONLY_SETTING.exists(request.transientSettings()))) {
return null;
if (request.transientSettings().size() + request.persistentSettings().size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy pants 😄

@@ -62,7 +62,10 @@ protected ClusterBlockException checkBlock(UpdateSettingsRequest request, Cluste
if (globalBlock != null) {
return globalBlock;
}
if (request.settings().size() == 1 && IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) || IndexMetaData.INDEX_READ_ONLY_SETTING.exists(request.settings())) {
if (request.settings().size() == 1 && // we have to allow resetting these settings otherwise users can't unblock a cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit : unblock an index (says cluster in comment)

@@ -203,6 +203,29 @@ public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, St
return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet())));
}

public ClusterBlockException indicesAllowReleaseResources(String[] indices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I ask for some java docs? I get the name indicesAllowReleaseResources because I know the context of this change, but I think it's good to give some context as to what it checks.

indexIsBlocked = true;
}
}
if (globalBlocked(ClusterBlockLevel.METADATA_WRITE) == false && indexIsBlocked == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems indexBlocked already checks for the global blocks, so another check here is redundant. The only exception is if someone passes in an empty array but that is not the intended use of the method.

if (globalBlocked(ClusterBlockLevel.METADATA_WRITE) == false && indexIsBlocked == false) {
return null;
}
Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(ClusterBlockLevel.METADATA_WRITE, index)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the first part of the method to shortcut this second half in the case we have no blocks? can't we make do with the second part only?

public static final ClusterBlock INDEX_READ_BLOCK = new ClusterBlock(7, "index read (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.READ), false);
public static final ClusterBlock INDEX_WRITE_BLOCK = new ClusterBlock(8, "index write (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE), false);
public static final ClusterBlock INDEX_METADATA_BLOCK = new ClusterBlock(9, "index metadata (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.METADATA_WRITE, ClusterBlockLevel.METADATA_READ), false);
public static final ClusterBlock INDEX_READ_ONLY_ALLOW_DELETE_BLOCK = new ClusterBlock(12, "index read-only / allow delete (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.METADATA_WRITE, ClusterBlockLevel.WRITE), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if the booleans were together... but this is really a nit... so keep as is if you prefer it like this.

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").setType("doc").setId("2").setSource("foo", "bar"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also check that metadata changes are rejected?

assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get());

} finally {
Settings s = Settings.builder().putNull(MetaData.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.getKey()).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is funky - we can remove the previous non finaly logic

@s1monw
Copy link
Contributor Author

s1monw commented May 16, 2017

@bleskes thanks for the review - I addressed all the comments

Copy link
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still LGTM

@s1monw s1monw merged commit 1cae850 into elastic:master May 16, 2017
s1monw added a commit that referenced this pull request May 16, 2017
…24678)

Today when an index is `read-only` the index is also blocked from
being deleted which sometimes is undesired since in-order to make
changes to a cluster indices must be deleted to free up space. This is
a likely scenario in a hosted environment when disk-space is limited to switch
indices read-only but allow deletions to free up space.
s1monw added a commit that referenced this pull request May 16, 2017
@clintongormley clintongormley added :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. and removed :Cluster labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Settings Settings infrastructure and APIs :Distributed Indexing/Distributed A catch all label for anything in the Distributed Area. Please avoid if you can. >enhancement v5.5.0 v6.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants