You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Dyre Tjeldvoll <Dy...@oracle.com> on 2013/12/06 11:39:57 UTC
Is shutting down databases and the engine thread safe?
Hi,
I'm wondering if it is safe
to call to
DriverManager.getConncetion("jdbc:derby:somedb;shutdown=true") and
DriverManager.getConncetion("jdbc:derby:;shutdown=true")
from two threads simultaneously?
I seem to be in a situation where these two calls deadlock.
The first thread is at
"main" prio=10 tid=0x00007ff04c00a000 nid=0x639e waiting on condition
[0x00007ff05102d000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at
org.apache.derby.impl.store.raw.data.RAFContainer.clean(RAFContainer.java:518)
- locked <0x000000078665bbb0> (a
org.apache.derby.impl.store.raw.data.RAFContainer4)
at
org.apache.derby.impl.services.cache.ConcurrentCache.cleanAndUnkeepEntry(ConcurrentCache.java:551)
at
org.apache.derby.impl.services.cache.ConcurrentCache.cleanCache(ConcurrentCache.java:509)
at
org.apache.derby.impl.services.cache.ConcurrentCache.cleanAll(ConcurrentCache.java:460)
at
org.apache.derby.impl.store.raw.data.BaseDataFileFactory.checkpoint(BaseDataFileFactory.java:1239)
at
org.apache.derby.impl.store.raw.log.LogToFile.checkpointWithTran(LogToFile.java:1726)
at
org.apache.derby.impl.store.raw.log.LogToFile.checkpoint(LogToFile.java:1523)
at org.apache.derby.impl.store.raw.RawStore.stop(RawStore.java:365)
at
org.apache.derby.impl.services.monitor.TopService.stop(TopService.java:443)
at
org.apache.derby.impl.services.monitor.TopService.shutdown(TopService.java:394)
at
org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:229)
at
org.apache.derby.impl.services.monitor.FileMonitor.shutdown(FileMonitor.java:44)
at
org.apache.derby.impl.db.DatabaseContextImpl.cleanupOnError(DatabaseContextImpl.java:77)
at
org.apache.derby.iapi.services.context.ContextManager.cleanupOnError(ContextManager.java:347)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.cleanupOnError(TransactionResourceImpl.java:461)
at
org.apache.derby.impl.jdbc.EmbedConnection.<init>(EmbedConnection.java:658)
at
org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(InternalDriver.java:628)
at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:282)
at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:913)
at
org.apache.derby.jdbc.AutoloadedDriver.connect(AutoloadedDriver.java:147)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
while the second is at
"Thread-2" prio=10 tid=0x00007ff04c386000 nid=0x63c0 waiting on
condition [0x00007ff0442c6000]
java.lang.Thread.State: RUNNABLE
at
org.apache.derby.iapi.services.context.ContextManager.<init>(ContextManager.java:121)
at
org.apache.derby.iapi.services.context.ContextService.newContextManager(ContextService.java:520)
at
org.apache.derby.impl.services.monitor.BaseMonitor.shutdown(BaseMonitor.java:191)
at
org.apache.derby.impl.services.monitor.FileMonitor.shutdown(FileMonitor.java:44)
at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:273)
at org.apache.derby.jdbc.InternalDriver.connect(InternalDriver.java:913)
at
org.apache.derby.jdbc.AutoloadedDriver.connect(AutoloadedDriver.java:147)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
Re: Is shutting down databases and the engine thread safe?
Posted by Dyre Tjeldvoll <Dy...@oracle.com>.
On 12/06/2013 01:28 PM, Knut Anders Hatlen wrote:
> Dyre Tjeldvoll <Dy...@oracle.com> writes:
>
>> Hi,
>>
>> I'm wondering if it is safe
>>
>> to call to
>> DriverManager.getConncetion("jdbc:derby:somedb;shutdown=true") and
>> DriverManager.getConncetion("jdbc:derby:;shutdown=true")
>>
>> from two threads simultaneously?
>
> Apparently not... :-/
>
> https://issues.apache.org/jira/browse/DERBY-4447 talks about adding a
> block mechanism, where one of the goals is to allow graceful shutdowns
> when multiple threads access the database.
Well, it is not super important for me, I just keep a ref count for the
engine in the application and delay shutdown until the ref count is
zero... and that seems to work.
But I don't think the doc mentions that you should avoid this...
>
>> I seem to be in a situation where these two calls deadlock.
>>
>> The first thread is at
>>
>> "main" prio=10 tid=0x00007ff04c00a000 nid=0x639e waiting on condition
>> [0x00007ff05102d000]
>> java.lang.Thread.State: TIMED_WAITING (sleeping)
>> at java.lang.Thread.sleep(Native Method)
>> at
>> org.apache.derby.impl.store.raw.data.RAFContainer.clean(RAFContainer.java:518)
>> - locked <0x000000078665bbb0> (a org.apache.derby.impl.store.raw.data.RAFContainer4)
>
> [...]
>
>> while the second is at
>>
>> "Thread-2" prio=10 tid=0x00007ff04c386000 nid=0x63c0 waiting on
>> condition [0x00007ff0442c6000]
>> java.lang.Thread.State: RUNNABLE
>> at org.apache.derby.iapi.services.context.ContextManager.<init>(ContextManager.java:121)
>
> How odd... That line is
>
> private final HashMap<String,CtxStack> ctxTable = new HashMap<String,CtxStack>();
>
> which shouldn't do any locking, so far as I can see.
Yeah, I found that odd too - but I struggled a bit to find the right
version of jstack - the one in my path didn't work at all - so maybe the
one I used isn't quite right either...
Regards
Dyre
Re: Is shutting down databases and the engine thread safe?
Posted by Knut Anders Hatlen <kn...@oracle.com>.
Dyre Tjeldvoll <Dy...@oracle.com> writes:
> Hi,
>
> I'm wondering if it is safe
>
> to call to
> DriverManager.getConncetion("jdbc:derby:somedb;shutdown=true") and
> DriverManager.getConncetion("jdbc:derby:;shutdown=true")
>
> from two threads simultaneously?
Apparently not... :-/
https://issues.apache.org/jira/browse/DERBY-4447 talks about adding a
block mechanism, where one of the goals is to allow graceful shutdowns
when multiple threads access the database.
> I seem to be in a situation where these two calls deadlock.
>
> The first thread is at
>
> "main" prio=10 tid=0x00007ff04c00a000 nid=0x639e waiting on condition
> [0x00007ff05102d000]
> java.lang.Thread.State: TIMED_WAITING (sleeping)
> at java.lang.Thread.sleep(Native Method)
> at
> org.apache.derby.impl.store.raw.data.RAFContainer.clean(RAFContainer.java:518)
> - locked <0x000000078665bbb0> (a org.apache.derby.impl.store.raw.data.RAFContainer4)
[...]
> while the second is at
>
> "Thread-2" prio=10 tid=0x00007ff04c386000 nid=0x63c0 waiting on
> condition [0x00007ff0442c6000]
> java.lang.Thread.State: RUNNABLE
> at org.apache.derby.iapi.services.context.ContextManager.<init>(ContextManager.java:121)
How odd... That line is
private final HashMap<String,CtxStack> ctxTable = new HashMap<String,CtxStack>();
which shouldn't do any locking, so far as I can see.
--
Knut Anders