Unique index or primary key violation in cluster failover test

180 views
Skip to first unread message

Tomáš Remeš

unread,
Oct 31, 2013, 7:07:59 AM10/31/13
to h2-da...@googlegroups.com
I test HTTP session persistence to db using latest WildFly application server (Beta2 - SNAPSHOT, h2 1.3.173). I use this connection url "jdbc:h2:file;AUTO_SERVER=true;DB_CLOSE_ON_EXIT=FALSE", because I want database to survive serve shutdown. Occassionally I am facing following exception:

Unique index or primary key violation: "PRIMARY_KEY_A ON PUBLIC.""binarybased_default_host_session_db_cluster""(ID)"; SQL statement:
INSERT INTO "binarybased_default_host_session_db_cluster" (datum, version, id) VALUES(?,?,?) [23505-159]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:81)
at org.h2.index.PageBtree.find(PageBtree.java:121)
at org.h2.index.PageBtreeLeaf.addRow(PageBtreeLeaf.java:146)
at org.h2.index.PageBtreeLeaf.addRowTry(PageBtreeLeaf.java:100)
at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:105)
at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:96)
at org.h2.table.RegularTable.addRow(RegularTable.java:130)
at org.h2.command.dml.Insert.insertRows(Insert.java:124)
at org.h2.command.dml.Insert.update(Insert.java:84)
at org.h2.command.CommandContainer.update(CommandContainer.java:71)
at org.h2.command.Command.executeUpdate(Command.java:212)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:143)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:129)

You can also check full stack trace (slightly different) at https://issues.jboss.org/browse/WFLY-2409. I've taken brief look to h2 code and I would like to ask at following - looking at org.h2.index.PageBtreeLeaf  int addRow(SearchRow row, boolean tryOnly) method line 145. What should happen when entryCount variable is not equal to 0? Then it's called find(row, false, true, true), where is following code construction:

if (add && index.indexType.isUnique()) {
                    if (!index.containsNullAndAllowMultipleNull(compare)) {
                        throw index.getDuplicateKeyException(compare.toString());
                    }
                }

First condition is always true in this case and unfortunately in my case also the second condition evaluates as true. I am not really sure, what could be the problem. I'll appreciate any suggestions. Thank's in advance.  

Noel Grandin

unread,
Oct 31, 2013, 7:43:37 AM10/31/13
to h2-da...@googlegroups.com


On 2013-10-31 13:07, Tom� Reme� wrote:
> I test HTTP session persistence to db using latest WildFly application server (Beta2 - SNAPSHOT, h2 1.3.173). I use this
> connection url "jdbc:h2:file;AUTO_SERVER=true;DB_CLOSE_ON_EXIT=FALSE", because I want database to survive serve
> shutdown. Occassionally I am facing following exception:
>
> Unique index or primary key violation: "PRIMARY_KEY_A ON
> PUBLIC.""binarybased_default_host_session_db_cluster""(ID)"; SQL statement:
>

It looks like you have declared ID as the primary key of the
binarybased_default_host_session_db_cluster
table, and you are trying to insert a row that has the same ID as an existing row.

This is most likely a bug in the application logic somewhere.

Thomas Mueller

unread,
Oct 31, 2013, 4:01:13 PM10/31/13
to H2 Google Group
Hi,

Actually, you are not using H2 version 1.3.173. You are using an old version of H2 (1.3.159 according to the error code, [23505-159]). Could you try with a newer version?

Regards,
Thomas



--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages