Skip to content

Template allows creation of index with 0 primary shards #12865

Closed
@pickypg

Description

@pickypg

If you create a template with number_of_shards set to 0, then it accepts it and the eventual index fails. Attempted in ES 1.7.1. (If you try to do this directly with the index, then it will appropriately block the attempt.)

# Create the template
PUT /_template/test_shards
{
  "template": "test_shards*",
  "settings": {
    "number_of_shards" : 0
  }
}

# Create the index
PUT /test_shards

Once created, the cluster is in a red state because no primaries are allocated, which is kind of odd on its own because no primaries are missing.

DELETE /test_shards

When trying to delete the index, an exception is logged:

[2015-08-13 18:49:11,042][WARN ][cluster.action.index     ] [WallE] [test_shards]failed to ack index store deleted for index
java.lang.IllegalArgumentException: settings must contain a non-null > 0 number of shards
    at org.elasticsearch.env.NodeEnvironment.lockAllForIndex(NodeEnvironment.java:445)
    at org.elasticsearch.indices.IndicesService.processPendingDeletes(IndicesService.java:733)
    at org.elasticsearch.cluster.action.index.NodeIndexDeletedAction.lockIndexAndAck(NodeIndexDeletedAction.java:125)
    at org.elasticsearch.cluster.action.index.NodeIndexDeletedAction.access$500(NodeIndexDeletedAction.java:49)
    at org.elasticsearch.cluster.action.index.NodeIndexDeletedAction$1.doRun(NodeIndexDeletedAction.java:94)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:36)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

However, after an usually long delay, it eventually responds with success. Looking on disk, the index's directory still exists, but it is appropriately empty.

Workaround

You can fix the issue by updating the template to fix the issue, creating the index, and then deleting it. (You can also just specify the number_of_shards directly at index time to override them template, but fixing the template is the appropriate fix if you run into this issue!)

# Recreate the index
PUT /test_shards
{
  "settings" : {
    "number_of_shards" : 1
  }
}

# Clean it up
DELETE /test_shards

This will appropriately cleanup the directory.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions