Skip to content

Handle ix_addk rcode correctly during master swing - #6132

Open
riverszhang89 wants to merge 1 commit into
bloomberg:mainfrom
riverszhang89:upsert_bug
Open

Handle ix_addk rcode correctly during master swing#6132
riverszhang89 wants to merge 1 commit into
bloomberg:mainfrom
riverszhang89:upsert_bug

Conversation

@riverszhang89

Copy link
Copy Markdown
Contributor

ERR_NOMASTER is treated as a duplicate key error, which causes upsert to misbehave during master swing: an upsert may miss its index entry, or may fail incorrectly during verify-retry.

Case 1) upsert misses its index entry

mydb4> create table t2 (i int primary key)$$
[create table t2 (i int primary key)] rc 0

Upsert receives a good rcode, but misses its index entry:

mydb4> insert into t2 values(3) on conflict do nothing
(rows inserted=1)
[insert into t2 values(3) on conflict do nothing] rc 0
mydb4> select * from t2
(i=3)

mydb4> select count(*) from t2 where i = 3
(count(*)=0)

Case 2) upsert fails incorrectly during verify-retry

Insert-on-conflict-do-nothing, still receives a dupkey error:

mydb4> begin
[begin] rc 0
mydb4> insert into t2 values(6) on conflict do nothing
[insert into t2 values(6) on conflict do nothing] rc 0
mydb4> insert into t2 values(6) on conflict do nothing
[insert into t2 values(6) on conflict do nothing] rc 0
mydb4> update t2 set i = sleep(1) where i = 1
[update t2 set i = sleep(1) where i = 1] rc 0
mydb4> commit
[commit] failed with rc 2 Transaction is uncommittable: Duplicate insert on key 'COMDB2_PK' in table 't2' index 0

Database logs the following:

[ERROR] Forced VERIFY-FAIL for uncommittable blocksql transaction

ERR_NOMASTER is treated as a duplicate key error, which causes
upsert to misbehave during master swing: an upsert may miss its
index entry, or may fail incorrectly during verify-retry.

Case 1) upsert misses its index entry

```
mydb4> create table t2 (i int primary key)$$
[create table t2 (i int primary key)] rc 0
```

Upsert receives a good rcode, but misses its index entry:
```
mydb4> insert into t2 values(3) on conflict do nothing
(rows inserted=1)
[insert into t2 values(3) on conflict do nothing] rc 0
mydb4> select * from t2
(i=3)

mydb4> select count(*) from t2 where i = 3
(count(*)=0)
```

Case 2) upsert fails incorrectly during verify-retry

Insert-on-conflict-do-nothing, still receives a dupkey error:

```
mydb4> begin
[begin] rc 0
mydb4> insert into t2 values(6) on conflict do nothing
[insert into t2 values(6) on conflict do nothing] rc 0
mydb4> insert into t2 values(6) on conflict do nothing
[insert into t2 values(6) on conflict do nothing] rc 0
mydb4> update t2 set i = sleep(1) where i = 1
[update t2 set i = sleep(1) where i = 1] rc 0
mydb4> commit
[commit] failed with rc 2 Transaction is uncommittable: Duplicate insert on key 'COMDB2_PK' in table 't2' index 0
```

Database logs the following:

```
[ERROR] Forced VERIFY-FAIL for uncommittable blocksql transaction
```

Signed-off-by: Rivers Zhang <hzhang320@bloomberg.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant