Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 338692 - [DB][Derby] Interrupting connection thread brings embedded DB in broken state
Summary: [DB][Derby] Interrupting connection thread brings embedded DB in broken state
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 4.0   Edit
Hardware: Macintosh Mac OS X
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Caspar D. CLA
QA Contact: Eike Stepper CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-02 10:53 EST by Egidijus Vaisnora CLA
Modified: 2011-06-23 03:38 EDT (History)
3 users (show)

See Also:
stepper: review+


Attachments
StackTrace (4.13 KB, text/plain)
2011-03-02 10:58 EST, Egidijus Vaisnora CLA
no flags Details
Patch v1 (524 bytes, patch)
2011-03-03 03:21 EST, Egidijus Vaisnora CLA
no flags Details | Diff
Patch v2 (2.58 KB, patch)
2011-03-24 04:02 EDT, Caspar D. CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Egidijus Vaisnora CLA 2011-03-02 10:53:24 EST
Attached stack trace from the server. After this stack trace, comes other exceptions like DB lock timeouts or SQlIntegrityConstraintViolationException.
Comment 1 Egidijus Vaisnora CLA 2011-03-02 10:58:26 EST
Created attachment 190173 [details]
StackTrace
Comment 2 Egidijus Vaisnora CLA 2011-03-02 11:05:36 EST
It looks like interruption more likely is caused by the "org.eclipse.emf.cdo.internal.server.QueryManager.QueryContext.cancel". It by it self calls "future.cancel(true)", which should trigger this exception. Fix could be to call "future.cancel(false)", without interrupting running thread - letting to finish DB call thread
Comment 3 Eike Stepper CLA 2011-03-02 11:31:51 EST
Derby is such a trouble maker!
Comment 4 Stefan Winkler CLA 2011-03-02 17:22:48 EST
Well, no, actually. Derby (although being slooow) does most of the things really right, which should be expected from most DMBS, but that are optimized away. (e.g., transactional table/schema manipulation).
Therefore, things that cause exceptions in Derby are potentially able to cause hard-to-debug inconsistencies in other DBMS which don't complain as much. So, up to some point, we should be grateful that Derby helps us detect some of these things ;-)
Comment 5 Eike Stepper CLA 2011-03-03 01:16:33 EST
I see ;-)
Comment 6 Eike Stepper CLA 2011-03-03 01:17:01 EST
I hope you're grateful that I assigned this bug to you :P
Comment 7 Egidijus Vaisnora CLA 2011-03-03 03:21:54 EST
Created attachment 190245 [details]
Patch v1

Patch proposal. It is hart to see, if it is enough, but taking all facts together I think it should be right way. Let the future do not interrupt running task, what do you think?
Comment 8 Egidijus Vaisnora CLA 2011-03-03 03:29:00 EST
Message from Derby forum, which could give background for this fix: http://mail-archives.apache.org/mod_mbox/db-derby-user/201103.mbox/%3Cx6bp1ule8f.fsf@oracle.com%3E
Comment 9 Egidijus Vaisnora CLA 2011-03-08 02:29:41 EST
Stefan, does the attached patch look reasonable to solve issue?
Comment 10 Stefan Winkler CLA 2011-03-08 03:42:31 EST
(In reply to comment #9)
> Stefan, does the attached patch look reasonable to solve issue?

At first glance: yes.

At the same time, I also see the issue that if you do a long-running query with a QueryContext and you call cancel then the long-running query will continue to run nonetheless. So, we are buying a better behavior with Derby (and potentially other DBMS who cannot cope with thread interruptions) for the sacrifice of not being able to interrupt long-running queries on the DB at all.

Question: Could we introduce an optional flag (something like "boolean alsoCancelInStore") into the QueryContext's cancel API, which provides a hint to the store implementor that it should also interrupt DB queries. Then it's up to the application developer to decide which of the options above is desired.
Comment 11 Egidijus Vaisnora CLA 2011-03-09 11:07:40 EST
> Question: Could we introduce an optional flag (something like "boolean
> alsoCancelInStore") into the QueryContext's cancel API, which provides a hint to
> the store implementor that it should also interrupt DB queries. Then it's up to
> the application developer to decide which of the options above is desired.

IMO, if we would have possibility to configure, then it is even better.
Comment 12 Caspar D. CLA 2011-03-24 04:02:51 EDT
Created attachment 191809 [details]
Patch v2

As per earlier discussion, behavior is now configurable.
Comment 13 Eike Stepper CLA 2011-04-04 03:00:04 EDT
Please add a section to http://wiki.eclipse.org/CDO/Server_Configuration_Reference#Element_repository
Comment 14 Caspar D. CLA 2011-04-04 05:00:01 EDT
Committed revision 7579.
Comment 15 Caspar D. CLA 2011-04-04 05:39:29 EDT
Wiki updated.
Comment 16 Eike Stepper CLA 2011-06-23 03:38:55 EDT
Available in R20110608-1407