Thread: threading issue leading to LNLogEntry.writeEntry BufferOverflowException

This question is not answered. Helpful answers available: 5. Correct answers available: 1.


Permlink Replies: 3 - Pages: 1 - Last Post: May 8, 2009 11:29 AM Last Post By: Charles Lamb Threads: [ Previous | Next ]
user10649382

Posts: 3
Registered: 05/04/09
threading issue leading to LNLogEntry.writeEntry BufferOverflowException
Posted: May 4, 2009 4:46 AM
 
Click to report abuse...   Click to reply to this thread Reply
I am using BDBje 3.3.75 with Java 6 (the problem also happens with Java 5).
My application is multithreaded and use BDBje transactionality. I have observed from time to time the below stack trace (note: line number may vary as I have added a few debugging statement - read below).
After some debugging, it happens that there is a threading issue when LogManager.marshallIntoBuffer is about to write an LNLogEntry instance. The LogManager.marshallIntoBuffer (as far as I can see) get the entry size and creates a bytebuffer (step a) and then write into it (step b).
My analysis is that it happens that between (a) and (b) some other thread is changing the LNLogEntry' transaction' lastLoggedLsn field and as this one is written as a packed long, when it gets change by some other thread in the middle, it can then take more place than (a) computed which then blows the buffer in (b).

With my added debugging statements in bdbje sources I observe the following Txn dumps
for step (a) <txn id="16793"><DbLsn val="0xffffffff/0xffffffff"/></txn>
for step (b) <txn id="16793"><DbLsn val="0xe4/0x46d893"/></txn>
It took me a while to figure out which structure in the LNLogEntry was growing to blow the buffer but this is as far as I have narrowed it down.

I can probably try to reproduce this in a test case but the application flow currently producing this is rather complex.
Can you please advise on the following:
- is it expected that a LNLogEntry might be changed (in particular its transaction' lastLoggedLsn) during this BDBje LogManager.marshallIntoBuffer code sequence ?
- if so, what should the application do to avoid that, what is the likely root cause ?

I am afraid it looks like a threading issue within BDBje low layers - although I'd love to hear otherwise.

Caused by: Environment invalid because of previous exception: com.sleepycat.je.RunRecoveryException: java.nio.BufferOverflowException
at com.sleepycat.je.log.LogManager.multiLog(LogManager.java:334)
at com.sleepycat.je.log.LogManager.log(LogManager.java:280)
at com.sleepycat.je.log.LogManager.log(LogManager.java:269)
at com.sleepycat.je.log.LogManager.log(LogManager.java:200)
at com.sleepycat.je.tree.LN.log(LN.java:511)
at com.sleepycat.je.tree.LN.optionalLog(LN.java:402)
at com.sleepycat.je.tree.LN.modify(LN.java:259)
at com.sleepycat.je.dbi.CursorImpl.putCurrent(CursorImpl.java:1364)
at com.sleepycat.je.dbi.CursorImpl.put(CursorImpl.java:1078)
at com.sleepycat.je.Cursor.putAllowPhantoms(Cursor.java:1470)
at com.sleepycat.je.Cursor.putNoNotify(Cursor.java:1406)
at com.sleepycat.je.Cursor.putInternal(Cursor.java:1361)
at com.sleepycat.je.Database.putInternal(Database.java:995)
at com.sleepycat.je.Database.put(Database.java:885)
...
... 3 more
Caused by: java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:165)
at java.nio.ByteBuffer.put(ByteBuffer.java:813)
at com.sleepycat.je.log.LogUtils.writeBytesNoLength(LogUtils.java:356)
at com.sleepycat.je.log.entry.LNLogEntry.writeEntry(LNLogEntry.java:358)
at com.sleepycat.je.log.LogManager.marshallIntoBuffer(LogManager.java:632)
at com.sleepycat.je.log.LogManager.multiLog(LogManager.java:311)

Linda Lee

Posts: 267
Registered: 07/11/06
Re: threading issue leading to LNLogEntry.writeEntry BufferOverflowException
Posted: May 4, 2009 5:18 AM   in response to: user10649382 in response to: user10649382
 
Click to report abuse...   Click to reply to this thread Reply
Thanks for taking the effort to figure this out, and looking at the implementation deeply. We'll be looking at this today.

Regards,

Linda
Charles Lamb

Posts: 454
Registered: 07/30/06
Re: threading issue leading to LNLogEntry.writeEntry BufferOverflowException
Posted: May 4, 2009 7:14 AM   in response to: user10649382 in response to: user10649382
 
Click to report abuse...   Click to reply to this thread Reply
Could you please send me an email so we can discuss this offline? (charles.lamb @ o.com)

I'll bring this back on the forum when we have a resolution.

Thanks.

Charles Lamb
Charles Lamb

Posts: 454
Registered: 07/30/06
Re: threading issue leading to LNLogEntry.writeEntry BufferOverflowException
Posted: May 8, 2009 11:29 AM   in response to: Charles Lamb in response to: Charles Lamb
 
Click to report abuse...   Click to reply to this thread Reply
The resolution of this is that this is indeed a bug in JE. It can occur when two threads are concurrently writing to an Environment and sharing a Transaction handle. The fix for this will be available in JE 3.3.82 which we hope to make available relatively soon.

Charles Lamb
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums