Mutation fail may not report the error

Description

This code is there from 4.0.0 nothing new. It might be decision made at that time. We may need to revist.

 

https://github.com/couchbase/query/blob/master/datastore/couchbase/couchbase.go#L1949

performOp() function returns error at the end when len == 0
Then caller sets based on the error.

What happens if we updating 10 entries and 8 succeed and 2 failed. We log error but never return error to caller.

This code needs to be revisted.

Repro during insert case:

delete from default; insert into default values("k001",1), values("k001",1); -- success even there is primary key violation but logged in query.log _time=2021-06-08T13:58:57.717-07:00 _level=ERROR _msg=Failed to perform INSERT on key <ud>k001</ud> for Keyspace default:default._default._default. Error - <ud>Duplicate Key k001</ud> insert into default values("k001",1); -- 12009 error insert into default values("k001",{"a":1}), values("k003",{"a":1}) ; -- success (even though primary key violation one key)

Same thing can happen for cas mismatch of UPDATE

Components

Affects versions

Fix versions

Labels

Environment

None

Link to Log File, atop/blg, CBCollectInfo, Core dump

None

Release Notes Description

None

Activity

Show:

Pierre Regazzoni December 14, 2021 at 10:20 PM

Verified on 7.1.0-1901

{             "cause": {                 "distinctErrors": 20,                 "errorLimit": 20,                 "mutationCount": 10             },             "code": 1195,             "msg": "Request execution aborted as the number of errors raised has reached the maximum permitted."         }     ],     "status": "aborted",     "metrics": {         "elapsedTime": "18.254745ms",         "executionTime": "18.097222ms",         "resultCount": 0,         "resultSize": 0,         "serviceLoad": 6,         "mutationCount": 10,         "errorCount": 21     } }

Donald Haggart October 28, 2021 at 10:25 AM
Edited

To verify, run a DML statement that encounters multiple errors - e.g. a sequence of duplicate keys - and observe how many errors are reported. (Previously you might get an inconsistent number of errors + mutations.)

e.g. using default as a target and `travel-sample` as the source:

 

insert into default (key k,value v) select meta().id k, {} v from `travel-sample` order by k limit 100; insert into default (key k,value v) select meta().id k, {} v from `travel-sample` order by k limit 120;  -- should have multiple duplicate key errors.

 

Then vary the error_limit parameter (server setting and/or request setting) and observe the number of reported errors when the statement is repeated.

You can also, with the error_limit set to 20, run:

delete from default where meta().id in (select raw meta().id k from `travel-sample` order by k); insert into default (key k,value v) select meta().id k, {} v from `travel-sample` order by k offset 10 limit 50; insert into default (key k,value v) select meta().id k, {} v from `travel-sample` order by k offset 0 limit 50;

And you should see a 1195 error detailing a mutation count along with error count.

CB robot October 27, 2021 at 2:46 PM

Build couchbase-server-7.1.0-1582 contains query commit 9b60db3 with commit message:
https://couchbasecloud.atlassian.net/browse/MB-46802#icft=MB-46802 Add error_limit request-level parameter

CB robot October 20, 2021 at 5:16 PM

Build couchbase-server-7.1.0-1540 contains query commit b5f69b3 with commit message:
https://couchbasecloud.atlassian.net/browse/MB-46802#icft=MB-46802 Try to detect KEY_ENOENT / KEY_EEXISTS when wrapped in another error

CB robot October 20, 2021 at 11:00 AM

Build couchbase-server-7.1.0-1536 contains query commit b301745 with commit message:
https://couchbasecloud.atlassian.net/browse/MB-46802#icft=MB-46802 Include cause in reported delete failures

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Is this a Regression?

Unknown

Triage

Untriaged

Story Points

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created June 8, 2021 at 7:38 PM
Updated October 10, 2024 at 5:44 AM
Resolved October 28, 2021 at 10:25 AM
Instabug