How to get partial udpate count when a timeout occurs?

When executing an update query that exceeds the timeout, I noticed that the update statement still updates some of the data (which is to be expected). I would like to know is there a known way to get the partial count from the query?

I tried doing the following, but the resultset is null (not surprisingly).

public void executeQuery(N1qlQuery query) {
    
    N1qlQueryResult resultset = null;

    try {
        resultset = bucket.query(query, configuration.getSelectTimeoutMs(), TimeUnit.MILLISECONDS);

        if(!resultset.parseSuccess()) {
            LOG.error("Couldn't parse query");
        } else if(!resultset.finalSuccess()) {
            LOG.error("Couldn't execute query");
        } else {
            LOG.debug("Successfully executed query");
        }

    } catch(RuntimeException r) {
        LOG.error("TIMEOUT: Failed to successfully execute query in {} ms: ", configuration.getSelectTimeoutMs(), r);
    } catch(Exception e) {
        LOG.error("Failed to successfully execute query due to {}: ", e.getMessage(), e);
    } finally {
        int mutationCount = 0;
        if(resultset != null && resultset.info() != null) {
            mutationCount = resultset.info().mutationCount();
        } 
        LOG.debug("Document count [{}] from query", mutationCount);
    }
}

A work around that I could do is that I could simply run a count query before and after the update query, to see the difference, although it might not be 100% accurate since things can change during this time.

https://docs.couchbase.com/sdk-api/couchbase-java-client-2.2.0/com/couchbase/client/java/query/N1qlMetrics.html#mutationCount--

Metrics should have mutation count. When timedout It will return status as Timeout and error is set and also mutation Count is returned (this may off by little bit).

update default set b = 14 ;
{
    "requestID": "3a5a5a92-fc3b-4aaf-97a6-d069f039720c",
    "signature": null,
    "results": [
    ],
    "errors": [
        {
            "code": 1080,
            "msg": "Timeout 20ms exceeded"
        }
    ],
    "status": "timeout",
    "metrics": {
        "elapsedTime": "20.938809ms",
        "executionTime": "20.835284ms",
        "resultCount": 0,
        "resultSize": 0,
        "mutationCount": 16,
        "errorCount": 1
    }
}

If you take above example the right approach will be

UPDATE default
SET b = 14
WHERE b != 14 ;

whether to mutate document or not only depends on WHERE clause. In the absence of WHERE clause it will mutate all documents. by doing b !=14 you can only when value is different from what you are setting. On timeout you can try same statement and that will not mutate if already done. Also you can add LIMIT 1000 and repeat in loop until mutationCount is zero.

Thanks for the reply, but I have tried doing that already, unless I have done something wrong…

My query is something like the following:

UPDATE default
SET p = 1
WHERE id != "x"
LIMIT 1000;

I should mention that, based on the user’s configuration, the might not be a limit, hence the possibility of a timeout, however the timeout might also occur if the machine is too slow or something.

As for retrieving the N1qlMetrics, I am trying to fetch it in my finally clause

resultset.info()

however, the resultset is null because of the timeout.

Am I setting this up incorrectly in the code?

You should remove try-catch-finally and try it. Based on results success/failure/error etc you should take action instead of catch block which might be not setting value