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

Template allows creation of index with 0 primary shards #12865

Closed
pickypg opened this issue Aug 13, 2015 · 0 comments
Closed

Template allows creation of index with 0 primary shards #12865

pickypg opened this issue Aug 13, 2015 · 0 comments
Assignees
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates

Comments

@pickypg
Copy link
Member

pickypg commented Aug 13, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates
Projects
None yet
Development

No branches or pull requests

3 participants