arangodb / arangodb-java-driver

The official ArangoDB Java driver.
Apache License 2.0
201 stars 93 forks source link

ROUND_ROBIN fallback not working #525

Closed ajw227 closed 10 months ago

ajw227 commented 10 months ago

Description

In case of coordinator is down, the fallback logic does not work properly.

  1. getDocument() : work properly. (GET)
  2. query() : Error. (POST)

Looking at the code, it seems that the POST method is excluded. Please review.

Setting

Java driver

    private final ArangoDB arangoDB = new ArangoDB.Builder()
        .host("localhost", 8529)
        .host("localhost", 8530)
        .host("localhost", 8531) //Invalid host
        .loadBalancingStrategy(LoadBalancingStrategy.ROUND_ROBIN)
        .build();

Test code

    private String getQueryValue() {
        var cursor = arangoDB.db().query("RETURN \"value\"", String.class);
        var list =  cursor.asListRemaining();
        try {
            cursor.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return list.get(0);
    }

    public void test() {
        var first = getQueryValue(); // OK.
        var second = getQueryValue(); // OK.
        var third = getQueryValue(); //Connection refused: localhost/127.0.0.1:8531
    }

Related code

https://github.com/arangodb/arangodb-java-driver/blob/main/http/src/main/java/com/arangodb/http/HttpCommunication.java#L171

    private boolean isSafe(final InternalRequest request) {
        RequestType type = request.getRequestType();
        return type == RequestType.GET || type == RequestType.HEAD || type == RequestType.OPTIONS;
    }
rashtao commented 10 months ago

In case of java.net.ConnectException, the code you linked above is not executed and the request is considered safe to retry, see https://github.com/arangodb/arangodb-java-driver/blob/main/http/src/main/java/com/arangodb/http/HttpCommunication.java#L95

Which exception do you get exactly? Can you please report the full stacktrace as well?

ajw227 commented 10 months ago

@rashtao Thx for review. I found the issue.

I tested 7.1.0. Changed connect exception handling.

https://github.com/arangodb/arangodb-java-driver/commit/94a7d4e928d2f9573d4e93464dff82aea67d8678.

After changed to 7.2.0, everything is ok. 👍

rashtao commented 10 months ago

Happy to help, but note that these changes have been released in 7.3.0.