Claus Ibsen created CAMEL-27617:
-----------------------------------

             Summary: camel-elasticsearch: scroll with disconnect, skipped 
cleanup on failure, sniffer delay unused
                 Key: CAMEL-27617
                 URL: https://issues.apache.org/jira/browse/CAMEL-27617
             Project: Camel
          Issue Type: Bug
          Components: camel-elasticsearch
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while improving the option descriptions of camel-elasticsearch for 
CAMEL-23832 (PR https://github.com/apache/camel/pull/30954).
These are separate problems of the component; the descriptions PR only 
documents the current behavior.

h4. 1. useScroll with disconnect=true closes the client before the scroll is 
read
In {{ElasticsearchProducer.process()}}, the Search case with useScroll creates 
the {{ElasticsearchScrollRequestIterator}}, which sends the first search in its 
constructor. The producer then calls {{cleanup(ctx)}} at once. With 
disconnect=true, {{cleanup()}} calls {{closeClient()}} and closes the transport.
The iterator sends its later scroll requests, and the clear-scroll request of 
{{close()}}, with that closed client. So a scroll with more hits than one page 
fails while the route reads the body.
Proposed change: with useScroll, close the client when the iterator is closed 
rather than in {{cleanup()}}, or reject useScroll together with disconnect.

h4. 2. The cleanup is skipped when a request fails
{{ElasticsearchProducer.onComplete()}} chains the cleanup as 
{{future.thenAccept(setBody).thenAccept(r -> cleanup(ctx))}}. When the future 
completes exceptionally, the cleanup stage does not run. An exception that 
{{process()}} throws before it sends the request, such as a body the converter 
cannot handle, skips the cleanup too.
The CamelElasticsearchIndexName, CamelElasticsearchSize, CamelElasticsearchFrom 
and CamelElasticsearchWaitForActiveShards headers that the producer copied from 
the endpoint options then stay on the message. A later elasticsearch endpoint, 
in an error handler for example, uses them instead of its own options. This is 
the case that the comment in {{cleanup()}} protects against. With 
disconnect=true, the client is also not closed after the failed exchange.
Proposed change: run the cleanup in {{whenComplete}}, and in the catch block of 
{{process()}}, so that it runs on success and on failure.

h4. 3. The CamelElasticsearchEnableDocumentOnlyMode header is never removed
{{ElasticsearchProducer.process()}} sets the 
CamelElasticsearchEnableDocumentOnlyMode header from the enableDocumentOnlyMode 
option when the message has none. {{cleanup()}} does not remove it, unlike the 
other headers that it sets from the options.
When the message then goes to another elasticsearch endpoint, that endpoint 
uses the first endpoint's value instead of its own enableDocumentOnlyMode 
option.
Proposed change: track this header in {{ActionContext}} like the others and 
remove it in {{cleanup()}}.

h4. 4. sniffAfterFailureDelay has no effect
{{ElasticsearchProducer.createClient()}} passes sniffAfterFailureDelay to 
{{SnifferBuilder.setSniffAfterFailureDelayMillis()}}. The Sniffer uses this 
delay only in {{Sniffer.sniffOnFailure()}}, which only a 
{{SniffOnFailureListener}} registered on the RestClient calls. The producer 
does not register one, so the option does nothing.
Proposed change: when enableSniffer is set, register a 
{{SniffOnFailureListener}} with {{RestClientBuilder.setFailureListener()}} and 
pass it the Sniffer, or deprecate the option.

h4. 5. No hostAddresses and no client fail late with a NullPointerException
When neither hostAddresses nor the client option of the component is set, 
{{ElasticsearchProducer.startClient()}} only logs "Incorrect ip address and 
port parameters settings for Elasticsearch cluster". The producer starts, and 
each exchange then builds a {{RestClientTransport}} with a null RestClient. The 
request fails with a NullPointerException that does not name the missing option.
Proposed change: fail at endpoint creation or producer start with a message 
that says hostAddresses or the client option is required.

h4. 6. The component option certificatePath has no supportFileReference
The endpoint option certificatePath in {{ElasticsearchConfiguration}} has 
{{@Metadata(supportFileReference = true)}}, but the component option in 
{{ElasticsearchComponent}} does not. Both values are loaded the same way, with 
{{ResourceHelper.resolveMandatoryResourceAsInputStream()}}, so tooling shows a 
difference that does not exist.
Proposed change: add {{supportFileReference = true}} to the {{@Metadata}} of 
the component field.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to