-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Changes from 3 commits
90cebcb
b6f2e0b
ef359dc
6f95049
53bc8e0
f693a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit : unblock an index (says cluster in comment) |
||
IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) | ||
|| IndexMetaData.INDEX_READ_ONLY_SETTING.exists(request.settings()) | ||
|| IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.settings())) { | ||
return null; | ||
} | ||
return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, indexNameExpressionResolver.concreteIndexNames(state, request)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,11 +70,11 @@ public ImmutableOpenMap<String, Set<ClusterBlock>> indices() { | |
} | ||
|
||
public Set<ClusterBlock> global(ClusterBlockLevel level) { | ||
return levelHolders[level.id()].global(); | ||
return levelHolders[level.ordinal()].global(); | ||
} | ||
|
||
public ImmutableOpenMap<String, Set<ClusterBlock>> indices(ClusterBlockLevel level) { | ||
return levelHolders[level.id()].indices(); | ||
return levelHolders[level.ordinal()].indices(); | ||
} | ||
|
||
private Set<ClusterBlock> blocksForIndex(ClusterBlockLevel level, String index) { | ||
|
@@ -97,7 +97,7 @@ private static ImmutableLevelHolder[] generateLevelHolders(Set<ClusterBlock> glo | |
.collect(toSet()))); | ||
} | ||
|
||
levelHolders[level.id()] = new ImmutableLevelHolder(newGlobal, indicesBuilder.build()); | ||
levelHolders[level.ordinal()] = new ImmutableLevelHolder(newGlobal, indicesBuilder.build()); | ||
} | ||
return levelHolders; | ||
} | ||
|
@@ -203,6 +203,29 @@ public ClusterBlockException indicesBlockedException(ClusterBlockLevel level, St | |
return new ClusterBlockException(unmodifiableSet(blocks.collect(toSet()))); | ||
} | ||
|
||
public ClusterBlockException indicesAllowReleaseResources(String[] indices) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can I ask for some java docs? I get the name |
||
boolean indexIsBlocked = false; | ||
for (String index : indices) { | ||
if (indexBlocked(ClusterBlockLevel.METADATA_WRITE, index)) { | ||
indexIsBlocked = true; | ||
} | ||
} | ||
if (globalBlocked(ClusterBlockLevel.METADATA_WRITE) == false && indexIsBlocked == false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems |
||
return null; | ||
} | ||
Function<String, Stream<ClusterBlock>> blocksForIndexAtLevel = index -> blocksForIndex(ClusterBlockLevel.METADATA_WRITE, index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
.stream(); | ||
Stream<ClusterBlock> blocks = concat( | ||
global(ClusterBlockLevel.METADATA_WRITE).stream(), | ||
Stream.of(indices).flatMap(blocksForIndexAtLevel)).filter(clusterBlock -> clusterBlock.isAllowReleaseResources() == false); | ||
Set<ClusterBlock> clusterBlocks = unmodifiableSet(blocks.collect(toSet())); | ||
if (clusterBlocks.isEmpty()) { | ||
return null; | ||
} | ||
return new ClusterBlockException(clusterBlocks); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
if (global.isEmpty() && indices().isEmpty()) { | ||
|
@@ -270,8 +293,6 @@ public static Diff<ClusterBlocks> readDiffFrom(StreamInput in) throws IOExceptio | |
|
||
static class ImmutableLevelHolder { | ||
|
||
static final ImmutableLevelHolder EMPTY = new ImmutableLevelHolder(emptySet(), ImmutableOpenMap.of()); | ||
|
||
private final Set<ClusterBlock> global; | ||
private final ImmutableOpenMap<String, Set<ClusterBlock>> indices; | ||
|
||
|
@@ -314,30 +335,31 @@ public Builder blocks(ClusterBlocks blocks) { | |
} | ||
|
||
public Builder addBlocks(IndexMetaData indexMetaData) { | ||
String indexName = indexMetaData.getIndex().getName(); | ||
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) { | ||
addIndexBlock(indexMetaData.getIndex().getName(), MetaDataIndexStateService.INDEX_CLOSED_BLOCK); | ||
addIndexBlock(indexName, MetaDataIndexStateService.INDEX_CLOSED_BLOCK); | ||
} | ||
if (IndexMetaData.INDEX_READ_ONLY_SETTING.get(indexMetaData.getSettings())) { | ||
addIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_READ_ONLY_BLOCK); | ||
addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_BLOCK); | ||
} | ||
if (IndexMetaData.INDEX_BLOCKS_READ_SETTING.get(indexMetaData.getSettings())) { | ||
addIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_READ_BLOCK); | ||
addIndexBlock(indexName, IndexMetaData.INDEX_READ_BLOCK); | ||
} | ||
if (IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.get(indexMetaData.getSettings())) { | ||
addIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_WRITE_BLOCK); | ||
addIndexBlock(indexName, IndexMetaData.INDEX_WRITE_BLOCK); | ||
} | ||
if (IndexMetaData.INDEX_BLOCKS_METADATA_SETTING.get(indexMetaData.getSettings())) { | ||
addIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_METADATA_BLOCK); | ||
addIndexBlock(indexName, IndexMetaData.INDEX_METADATA_BLOCK); | ||
} | ||
if (IndexMetaData.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.get(indexMetaData.getSettings())) { | ||
addIndexBlock(indexName, IndexMetaData.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK); | ||
} | ||
return this; | ||
} | ||
|
||
public Builder updateBlocks(IndexMetaData indexMetaData) { | ||
removeIndexBlock(indexMetaData.getIndex().getName(), MetaDataIndexStateService.INDEX_CLOSED_BLOCK); | ||
removeIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_READ_ONLY_BLOCK); | ||
removeIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_READ_BLOCK); | ||
removeIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_WRITE_BLOCK); | ||
removeIndexBlock(indexMetaData.getIndex().getName(), IndexMetaData.INDEX_METADATA_BLOCK); | ||
// let's remove all blocks for this index and add them back -- no need to remove all individual blocks.... | ||
indices.remove(indexMetaData.getIndex().getName()); | ||
return addBlocks(indexMetaData); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,10 +131,11 @@ public static <T extends Custom> T lookupPrototypeSafe(String type) { | |
return proto; | ||
} | ||
|
||
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(5, "index read-only (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE)); | ||
public static final ClusterBlock INDEX_READ_BLOCK = new ClusterBlock(7, "index read (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.READ)); | ||
public static final ClusterBlock INDEX_WRITE_BLOCK = new ClusterBlock(8, "index write (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE)); | ||
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)); | ||
public static final ClusterBlock INDEX_READ_ONLY_BLOCK = new ClusterBlock(5, "index read-only (api)", false, false, RestStatus.FORBIDDEN, EnumSet.of(ClusterBlockLevel.WRITE, ClusterBlockLevel.METADATA_WRITE), false); | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
public enum State { | ||
OPEN((byte) 0), | ||
|
@@ -212,6 +213,10 @@ static Setting<Integer> buildNumberOfShardsSetting() { | |
public static final Setting<Boolean> INDEX_BLOCKS_METADATA_SETTING = | ||
Setting.boolSetting(SETTING_BLOCKS_METADATA, false, Property.Dynamic, Property.IndexScope); | ||
|
||
public static final String SETTING_READ_ONLY_ALLOW_DELETE = "index.blocks.read_only_allow_delete"; | ||
public static final Setting<Boolean> INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING = | ||
Setting.boolSetting(SETTING_READ_ONLY_ALLOW_DELETE, false, Property.Dynamic, Property.IndexScope); | ||
|
||
public static final String SETTING_VERSION_CREATED = "index.version.created"; | ||
public static final String SETTING_VERSION_CREATED_STRING = "index.version.created_string"; | ||
public static final String SETTING_VERSION_UPGRADED = "index.version.upgraded"; | ||
|
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.
fancy pants 😄