Bug #32862 Falcon: Inserting a duplicate key leads to assertion
Submitted: 30 Nov 2007 2:25 Modified: 3 Dec 2007 14:23
Reporter: Hakan Küçükyılmaz Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Falcon storage engine Severity:S1 (Critical)
Version:6.0-falcon-team bk OS:Linux
Assigned to: Kevin Lewis CPU Architecture:Any

[30 Nov 2007 2:25] Hakan Küçükyılmaz
Description:
In latest mysql-6.0-falcon-team tree we are hitting an assertion.

(gdb) f 4
#4  0x00000000007f8d0d in Table::checkUniqueRecordVersion (this=0x2aaaaf35aa08,
    recordNumber=<value optimized out>, index=0x2aaaaf35aeb0, transaction=0x2aaaaf355720,
    record=<value optimized out>, sync=0x458cb8b0) at Table.cpp:2406
2406                            ASSERT(dup->state == recDeleted);
(gdb) p dup->state
$1 = 2 '\002'
(gdb) p recDeleted
$2 = 1

#0  0x00002b1763054fcb in raise () from /lib/libpthread.so.0
#1  0x000000000082a24e in Error::debugBreak () at Error.cpp:92
#2  0x000000000082a344 in Error::error (string=<value optimized out>) at Error.cpp:69
#3  0x000000000082a3a4 in Error::assertionFailed (fileName=0x4 <Address 0x4 out of
bounds>, line=24615)
    at Error.cpp:76
#4  0x00000000007f8d0d in Table::checkUniqueRecordVersion (this=0x2aaaaf35aa08,
    recordNumber=<value optimized out>, index=0x2aaaaf35aeb0, transaction=0x2aaaaf355720,
    record=<value optimized out>, sync=0x458cb8b0) at Table.cpp:2406
#5  0x00000000007f913d in Table::checkUniqueIndex (this=0x2aaaaf35aa08,
index=0x2aaaaf35aeb0,
    transaction=0x2aaaaf355720, record=0xff8bff8, sync=0x458cb8b0) at Table.cpp:2337
#6  0x00000000007f9218 in Table::checkUniqueIndexes (this=0x2aaaaf35aa08,
transaction=0x2aaaaf355720,
    record=0xff8bff8, sync=0x458cb8b0) at Table.cpp:2311
#7  0x00000000007f9e4f in Table::insert (this=0x2aaaaf35aa08, transaction=0x2aaaaf355720,
    stream=<value optimized out>) at Table.cpp:2871
#8  0x00000000007ed621 in StorageDatabase::insert (this=<value optimized out>,
    connection=<value optimized out>, table=0x2aaaaf35aa08, stream=0x2aaaaf2ad7f0) at
StorageDatabase.cpp:226
#9  0x00000000007f14e8 in StorageTable::insert (this=0x2aaaaf2a8260) at
StorageTable.cpp:126
#10 0x00000000007ea68c in StorageInterface::write_row (this=0x12754f8, buff=0x1275790
"�\001")
    at ha_falcon.cpp:943
#11 0x0000000000732e42 in handler::ha_write_row (this=0x12754f8, buf=0x1275790 "�\001")
at handler.cc:4612
#12 0x00000000006c7df3 in write_record (thd=0xea85108, table=0x1274018, info=0x458cbc60)
at sql_insert.cc:1548
#13 0x00000000006cd5ab in mysql_insert (thd=0xea85108, table_list=0xea8f778,
fields=@0xea86fe0,
    values_list=@0xea87028, update_fields=@0xea87010, update_values=@0xea86ff8,
duplic=DUP_ERROR, ignore=false)
    at sql_insert.cc:803
#14 0x0000000000659b2e in mysql_execute_command (thd=0xea85108) at sql_parse.cc:2663
#15 0x000000000065a214 in mysql_parse (thd=0xea85108, inBuf=0xea8f688 "insert into t2
values (1, 'cdeas')",

How to repeat:
falcon_record_memory_max = 768MB

Connection 1:
create table t1 (a int auto_increment primary key, b varchar(5)) engine myisam;
insert into t1 values (DEFAULT, 'abefc');
insert into t1 (b) select b from t1;
insert into t1 (b) select b from t1;
...
...
...
insert into t1 (b) select b from t1;
select count(*) from t1;
[02:32] root@test>select count(*) from t1;
+----------+
| count(*) |
+----------+
|  1048576 |
+----------+
1 row in set (0.00 sec)

create table t2 (a int auto_increment primary key, b varchar(5)) engine falcon;
insert into t2 select * from t1;

Connection 2:
insert into t2 values (1, 'cdeas')
--> crash
[30 Nov 2007 17:03] Kevin Lewis
Normally, a record version that has been chilled is thawed during the call to fetchVersion, which makes a call to Record::getRecordData().  But in Table::checkUniqueRecordVersion(), the all the various record versions for a record number must be looked at, so there is NO call to fetchVersion(), and getRecordData() is not called.

I added a call to dup->getRecordData() just before checking dup->hasRecord() to see if the recordVersion is deleted.  This will keep the ASSERT reported in this bug from happening.
[30 Nov 2007 17:53] Kevin Lewis
tested and pushed to mysql-6.0-falcon-team
[30 Nov 2007 19:23] Hakan Küçükyılmaz
Works now without hitting the assertion:

[20:22] root@test>insert into t2 values (1, 'cdeas');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
6.0.4-alpha
[3 Dec 2007 10:02] Bugs System
Pushed into 6.0.4-alpha
[3 Dec 2007 14:23] MC Brown
A note has been added to the 6.0.4 changelog: 

Using Falcon when accessing multiple versions of the same record, certain records could fail to be retrieved from the record cache, causing an assertion failure.