Async search: create internal index only before storing initial response#54619
Conversation
…initial response We currently create the .async-search index if necessary before performing any action (index, update or delete). Truth is that this is needed only before storing the initial response. The other operations are either update or delete, which will anyways not find the document to update/delete even if the index gets created when missing. This also caused `testCancellation` failures as we were trying to delete the document twice from the .async-search index, once from `TransportDeleteAsyncSearchAction` and once as a consequence of the search task being completed. The latter may be called after the test is completed, but before the cluster is shut down and causing problems to the after test checks, for instance if it happens after all the indices have been cleaned up. It is totally fine to try to delete a response that is no longer found, but not quite so if such call will also trigger an index creation. With this commit we remove all the calls to createIndexIfNecessary from the update/delete operation, and we leave one call only from storeInitialResponse which is where the index is expected to be created. Closes elastic#54180
|
Pinging @elastic/es-search (:Search/Search) |
| logger.error(() -> new ParameterizedMessage("failed to clean async-search [{}]", searchId.getEncoded()), exc); | ||
| listener.onFailure(exc); | ||
| })), | ||
| listener::onFailure)); |
There was a problem hiding this comment.
I tried to make this logic more readable. I found the boolean flag hard to reason about especially as it was provided true only once. I moved the listener wrapping to the callers, where each caller needs to do something different.
| //don't even log when: the async search document or its index is not found. That can happen if an invalid | ||
| //search id is provided and no async search initial response has been stored yet. | ||
| if (exc.getCause() instanceof DocumentMissingException == false | ||
| && exc.getCause() instanceof IndexNotFoundException == false) { |
There was a problem hiding this comment.
I was wondering if we are sure about exc.getCause here. What's the top level exception?
There was a problem hiding this comment.
A RemoteTransportException. Maybe we can replace the instanceof with ExceptionsHelper.status(exc) != RestStatus.NOT_FOUND ?
There was a problem hiding this comment.
the problem I have with ExceptionsHelper.status(exc) is that it does not look at the cause at all and it gives 500 if it does not know any better. How about ExceptionsHelper.status(ExceptionsHelper.unwrapCause(exc)) ?
jimczi
left a comment
There was a problem hiding this comment.
This makes sense to me. I left some comments.
| logger.error(() -> new ParameterizedMessage("failed to clean async-search [{}]", searchId.getEncoded()), exc); | ||
| listener.onFailure(exc); | ||
| })), | ||
| listener::onFailure)); |
| //don't even log when: the async search document or its index is not found. That can happen if an invalid | ||
| //search id is provided and no async search initial response has been stored yet. | ||
| if (exc.getCause() instanceof DocumentMissingException == false | ||
| && exc.getCause() instanceof IndexNotFoundException == false) { |
There was a problem hiding this comment.
A RemoteTransportException. Maybe we can replace the instanceof with ExceptionsHelper.status(exc) != RestStatus.NOT_FOUND ?
| r -> listener.onResponse(new AcknowledgedResponse(true)), | ||
| exc -> { | ||
| //the index may not be there (no initial async search response stored yet?): we still want to return 200 | ||
| if (exc.getCause() instanceof IndexNotFoundException) { |
There was a problem hiding this comment.
We shouldn't fail If the document is missing:
| if (exc.getCause() instanceof IndexNotFoundException) { | |
| if (ExceptionsHelper.status(exc) == RestStatus.NOT_FOUND) { |
There was a problem hiding this comment.
we don't, document missing does not come back as a failure. Yet, I agree on changing the condition as exc.getCause() instanceof IndexNotFoundException is not great
…nse (#54619) We currently create the .async-search index if necessary before performing any action (index, update or delete). Truth is that this is needed only before storing the initial response. The other operations are either update or delete, which will anyways not find the document to update/delete even if the index gets created when missing. This also caused `testCancellation` failures as we were trying to delete the document twice from the .async-search index, once from `TransportDeleteAsyncSearchAction` and once as a consequence of the search task being completed. The latter may be called after the test is completed, but before the cluster is shut down and causing problems to the after test checks, for instance if it happens after all the indices have been cleaned up. It is totally fine to try to delete a response that is no longer found, but not quite so if such call will also trigger an index creation. With this commit we remove all the calls to createIndexIfNecessary from the update/delete operation, and we leave one call only from storeInitialResponse which is where the index is expected to be created. Closes #54180
…nse (#54619) We currently create the .async-search index if necessary before performing any action (index, update or delete). Truth is that this is needed only before storing the initial response. The other operations are either update or delete, which will anyways not find the document to update/delete even if the index gets created when missing. This also caused `testCancellation` failures as we were trying to delete the document twice from the .async-search index, once from `TransportDeleteAsyncSearchAction` and once as a consequence of the search task being completed. The latter may be called after the test is completed, but before the cluster is shut down and causing problems to the after test checks, for instance if it happens after all the indices have been cleaned up. It is totally fine to try to delete a response that is no longer found, but not quite so if such call will also trigger an index creation. With this commit we remove all the calls to createIndexIfNecessary from the update/delete operation, and we leave one call only from storeInitialResponse which is where the index is expected to be created. Closes #54180
We currently create the .async-search index if necessary before performing any action (index, update or delete). Truth is that this is needed only before storing the initial response. The other operations are either update or delete, which will anyways not find the document to update/delete even if the index gets created when missing. This also caused
testCancellationfailures as we were trying to delete the document twice from the .async-search index, once fromTransportDeleteAsyncSearchActionand once as a consequence of the search task being completed. The latter may be called after the test is completed, but before the cluster is shut down and causing problems to the after test checks, for instance if it happens after all the indices have been cleaned up. It is totally fine to try to delete a response that is no longer found, but not quite so if such call will also trigger an index creation.With this commit we remove all the calls to createIndexIfNecessary from the update/delete operation, and we leave one call only from storeInitialResponse which is where the index is expected to be created.
Closes #54180