Hi, we are using Derby as the backing message store for Qpid-Broker-J.  We
have a continuous data flow into Qpid so each message gets persisted to the
Derby message store as data comes in and then it is deleted from the Derby
message store as data is picked up and processed.  The data flow is pretty
constant, there are peaks and valleys but basically data is always coming
in so there are LOTS of inserts and deletes.  Over time we found that the
Derby message store fills up the disk drive until it runs out of space and
in general the workaround to that has been to stop Qpid and remove the
message store (i.e. the Derby directory), which loses data.

My attempted solution to this was to extend Qpid's DerbyMessageStore with a
DerbyRepackingMessageStore that executes the
SYSCS_UTIL.SYSCS_COMPRESS_TABLE procedure based on a timer.  However, on a
test system with flowing data, this always has a deadlock exception and
some data (the aborted transaction) is lost.  An example is:

Caused by: org.apache.derby.shared.common.error.StandardException: A lock
could not be obtained due to a deadlock, cycle of locks and waiters is:
message_id , meta_data ) values (?, ?)
  Granted XID : {501214829, X}
  Waiting XID : {501214829, X} , APP, alter table
  Granted XID : {501214829, S} , {501214865, S} , {501214885, S}
. The selected victim is XID : 501214885.

My understanding of that is that the deadlock is occurring because the
insert has a shared lock on the sysconglomerates row and wants an exclusive
lock on the qpid_message_metadata table, while the compress has an
exclusive lock on the qpid_message_metadata table and wants an exclusive
lock on the sysconglomerates row, so they block each other.

I found this thread from May of 2009 which had a similar issue:
https://lists.apache.org/thread/b8p7kzcc0clo45o2drs5rttsx5gqq49f  I would
expect the compress command to go for the lock(s), wait until it gets the
lock(s), then block the other threads and do the compress.  But it
deadlocks instead.

Based on this ticket, https://issues.apache.org/jira/browse/DERBY-3683, I
tried using a non-autocommit connection and locking the table exclusively
before calling compress and then commit, but that got the same errors.
Based on this thread,
https://lists.apache.org/thread/38qg7nkqolssc1jhdkhgnrl7vbkwq0vw, I tried
the in place compress and it succeeds without deadlock.  However, it is
significantly slower, too slow to be a workable solution for my use case
and it also doesn't return as much space to the operating system.

Does this look like a Derby bug where the compress command will deadlock if
there are inserts happening at roughly the same time?  Or is this
expected?  Do both the inserts and compress need a sysconglomerates row
lock?  Is there a way the compress command could get both its locks at the
same time to avoid the deadlock?

Reply via email to