I sometimes get the following exception when running one of my
unittests against ES. The exception is returned to me in a
ActionListener.onFailure object that I give as a
parameter when I call execute on SearchRequestBuilder. I never get the
exception when running the test on my local Mac, but when the test is
run on our TeamCity machine (Ubuntu) the exception occurs 90% of the
time.
org.elasticsearch.cluster.block.ClusterBlockException: blocked by: [1/
state not recovered / initialized];[2/no master];
at
org.elasticsearch.cluster.block.ClusterBlocks.indexBlockedException(ClusterBlocks.java:
131)
at
org.elasticsearch.cluster.block.ClusterBlocks.indexBlockedRaiseException(ClusterBlocks.java:
115)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.(TransportSearchTypeAction.java:116)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.(TransportSearchQueryThenFetchAction.java:72)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.(TransportSearchQueryThenFetchAction.java:63)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:
60)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:
52)
at
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:
61)
at
org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:
112)
at
org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:
49)
at
org.elasticsearch.action.support.BaseAction.execute(BaseAction.java:
61)
at org.elasticsearch.client.node.NodeClient.search(NodeClient.java:
186)
at
org.elasticsearch.client.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:
589)
at
org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
56)
at ... my junit-test code ...
The test is running 10 threads doing indexing (inserting) and
reindexing (updating) the on "the same" documents in ES, so it relying
on the "optimistic locking based on versioning" and "unique constraint
on _id" to work perfectly (they probably are, but I am not able to
interpret the exception here).
I imagine that it might be because the node hasnt completely started
before I start using it. I do the following in a @Before in my
unittest:
Node node = nodeBuilder()
.local(true)
.settings(ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", shards)
.put("index.number_of_replicas", replicas).build())
.build()
.start();
Can I somehow wait for the node to be completely started? Looking at
the code I do not see a way to do that?
I imagine that it might be because the node hasnt completely started
before I start using it. I do the following in a @Before in my
unittest:
Node node = nodeBuilder()
.local(true)
.settings(ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", shards)
.put("index.number_of_replicas", replicas).build())
.build()
.start();
Can I somehow wait for the node to be completely started? Looking at
the code I do not see a way to do that?
I know it is not what Karussell suggested, but now I have the
following in my unittest class, and it never fails on the first test
but often on the second test. Guess it is due to the node not finished
its close before another note is started. Can anyone be more detailed
about what to do in @BeforeClass, @AfterClass, @Before and @After in
unittests to write good stable tests against ES. Thanks!
Karussell suggests to wait for yellow to be sure that the node has
completely started. But waiting for yellow requires an index.
Basically I just want to know when the node has completely started -
even though there might be no indexes yet.
I imagine that it might be because the node hasnt completely started
before I start using it. I do the following in a @Before in my
unittest:
Node node = nodeBuilder()
.local(true)
.settings(ImmutableSettings.settingsBuilder()
.put("index.number_of_shards", shards)
.put("index.number_of_replicas", replicas).build())
.build()
.start();
Can I somehow wait for the node to be completely started? Looking at
the code I do not see a way to do that?
I know it is not what Karussell suggested, but now I have the
following in my unittest class, and it never fails on the first test
but often on the second test. Guess it is due to the node not finished
its close before another note is started. Can anyone be more detailed
about what to do in @BeforeClass, @AfterClass, @Before and @After in
unittests to write good stable tests against ES. Thanks!
Karussell suggests to wait for yellow to be sure that the node has
completely started. But waiting for yellow requires an index.
Basically I just want to know when the node has completely started -
even though there might be no indexes yet.
Regards, Per Steffensen
Forgot to say that the tests themselves create the indices they need
and add them to the list createdIndices, so that they will be deleted
in after(). The tests use the following code to create the indices
they need:
My problem seemed to be due to the fact that all the threads in the
test used their own node/client. I have changed so that they all share
the same node/client, and now the test is constantly green. Guess
conclusion is that you should not have more than one node/client in
the same JVM
You can have more than one instance of a local node in the same JVM, but,
they will discover each other (within the same classloader, using static
vars). I am not sure what your tests do, but if you need them to use
different "clusters", you can use a different cluster name for the node(s)
you start per test.
My problem seemed to be due to the fact that all the threads in the
test used their own node/client. I have changed so that they all share
the same node/client, and now the test is constantly green. Guess
conclusion is that you should not have more than one node/client in
the same JVM
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.