Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] "Auto commit"
[CDO] "Auto commit" [message #425435] Wed, 26 November 2008 10:01 Go to next message
David Bonneau is currently offline David BonneauFriend
Messages: 28
Registered: July 2009
Junior Member
Hi

I'm working on an application that manages very large model. For this,
I use CDO 1.0.x.

I have one transaction (only one client), and I have to commit often
this transaction, if I don't want to use too memory (to prevent
OutOfMemoryException). I would like this commit is automatic. I don't
want to have to add everywhere in my code : myTransaction.commit.

I try to add a listener (a CDOTransactionHandler) to my transaction.
I'm able to known if an object is added or modified in the transaction.
Every X add or modification I try to commit the transaction. But if I
commit in the addedObject method, I have the following exception :

java.lang.IllegalStateException: Failing event COMMIT in state PREPARED
for MyObject@oid679
(data= org.eclipse.emf.internal.cdo.protocol.CommitTransactionResul t @614695)
at
org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:152)
at
org.eclipse.emf.internal.cdo.CDOStateMachine.commit(CDOState Machine.java:275)
at
org.eclipse.emf.internal.cdo.CDOTransactionImpl.postCommit(C DOTransactionImpl.java:492)
at
org.eclipse.emf.internal.cdo.CDOTransactionImpl.commit(CDOTr ansactionImpl.java:250)

I understand why I have this exception : the object will be added in the
transaction, the state of the transaction changes, and I try to commit !

I would like to know, if it's possible to add a listener after (and not
before) the object is added in a transaction. Is there another solution ?

David
Re: [CDO] "Auto commit" [message #425439 is a reply to message #425435] Wed, 26 November 2008 10:34 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
David,

This is an interesting idea, please file an enhancement request!

Cheers
/Eike

----
http://thegordian.blogspot.com



David Bonneau schrieb:
> Hi
>
> I'm working on an application that manages very large model. For
> this, I use CDO 1.0.x.
>
> I have one transaction (only one client), and I have to commit often
> this transaction, if I don't want to use too memory (to prevent
> OutOfMemoryException). I would like this commit is automatic. I don't
> want to have to add everywhere in my code : myTransaction.commit.
>
> I try to add a listener (a CDOTransactionHandler) to my transaction.
> I'm able to known if an object is added or modified in the
> transaction. Every X add or modification I try to commit the
> transaction. But if I commit in the addedObject method, I have the
> following exception :
>
> java.lang.IllegalStateException: Failing event COMMIT in state
> PREPARED for MyObject@oid679
> (data= org.eclipse.emf.internal.cdo.protocol.CommitTransactionResul t @614695)
>
> at
> org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:152)
>
> at
> org.eclipse.emf.internal.cdo.CDOStateMachine.commit(CDOState Machine.java:275)
>
> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.postCommit(C DOTransactionImpl.java:492)
>
> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.commit(CDOTr ansactionImpl.java:250)
>
>
> I understand why I have this exception : the object will be added in
> the transaction, the state of the transaction changes, and I try to
> commit !
>
> I would like to know, if it's possible to add a listener after (and
> not before) the object is added in a transaction. Is there another
> solution ?
>
> David


Re: [CDO] "Auto commit" [message #425440 is a reply to message #425435] Wed, 26 November 2008 10:39 Go to previous messageGo to next message
Victor Roldan Betancort is currently offline Victor Roldan BetancortFriend
Messages: 524
Registered: July 2009
Senior Member
David,

I imagine you could add an adapter to your objects to track changes and
perform a commit, or you could add also an adapter to the resource that
contains your objects and listen to Resource.RESOURCE__IS_MODIFIED
events. Unfortunately, we still need to complete bug #252242 (to have an
adapter capable of tracking changes of loaded objects the same way
ResourceImpl$ModificationTrackingAdapter does).

HTH,
Víctor.

David Bonneau escribió:
> Hi
>
> I'm working on an application that manages very large model. For this,
> I use CDO 1.0.x.
>
> I have one transaction (only one client), and I have to commit often
> this transaction, if I don't want to use too memory (to prevent
> OutOfMemoryException). I would like this commit is automatic. I don't
> want to have to add everywhere in my code : myTransaction.commit.
>
> I try to add a listener (a CDOTransactionHandler) to my transaction.
> I'm able to known if an object is added or modified in the transaction.
> Every X add or modification I try to commit the transaction. But if I
> commit in the addedObject method, I have the following exception :
>
> java.lang.IllegalStateException: Failing event COMMIT in state PREPARED
> for MyObject@oid679
> (data= org.eclipse.emf.internal.cdo.protocol.CommitTransactionResul t @614695)
> at
> org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:152)
>
> at
> org.eclipse.emf.internal.cdo.CDOStateMachine.commit(CDOState Machine.java:275)
>
> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.postCommit(C DOTransactionImpl.java:492)
>
> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.commit(CDOTr ansactionImpl.java:250)
>
>
> I understand why I have this exception : the object will be added in the
> transaction, the state of the transaction changes, and I try to commit !
>
> I would like to know, if it's possible to add a listener after (and not
> before) the object is added in a transaction. Is there another solution ?
>
> David
Re: [CDO] "Auto commit" [message #425529 is a reply to message #425435] Mon, 01 December 2008 00:14 Go to previous messageGo to next message
Tom Crockett is currently offline Tom CrockettFriend
Messages: 54
Registered: July 2009
Member
Hey David,

It looks as though by attempting to commit directly from the
addingObject() method you're catching the CDOStateMachine in the
intermediate PREPARED state that exists between TRANSIENT and NEW; the
only valid states for an object to be committed are NEW and DIRTY. This is
probably happening because the CDOTransactionHandler gets to hear about
added objects before ordinary adapters, one of which I believe is
responsible for making the (almost immediate) transition from PREPARED to
NEW.

I have a similar need for auto-commit in my own project, except that we
are using EMF Transactions, and we commit upon hearing of any (EMF)
transaction finishing. I can tell you from experience that one thing you
will definitely want to implement is some form of coalescing events, so
that 20 changes to various EObjects does not result in 20 separate commits
for each of the deltas. That would be Very Bad :) I would recommend
something like the following:

synchronized void scheduleCommit() {
if (!alreadyCommitting) {
alreadyCommitting = true;
new Thread("commit thread") {
public void run() {
try {
Thread.sleep(500);
transaction.commit();
} catch (InterruptedException) {
...
} finally {
alreadyCommitting = false;
}
}
}.start();
}
}

Doing something like this would also more or less take care of the
exception you're seeing, because the actual commit would take place at a
later date, when the state machine had had plenty of time to transition
from PREPARED to NEW. I'm not sure if there's a chance that the resulting
commit would take place in that very brief PREPARED state, but it seems
very unlikely at the least, and perhaps Eike has put in place some
synchronization to prevent that.

Hope that helps,

Tom

David Bonneau wrote:

> Hi

> I'm working on an application that manages very large model. For this,
> I use CDO 1.0.x.

> I have one transaction (only one client), and I have to commit often
> this transaction, if I don't want to use too memory (to prevent
> OutOfMemoryException). I would like this commit is automatic. I don't
> want to have to add everywhere in my code : myTransaction.commit.

> I try to add a listener (a CDOTransactionHandler) to my transaction.
> I'm able to known if an object is added or modified in the transaction.
> Every X add or modification I try to commit the transaction. But if I
> commit in the addedObject method, I have the following exception :

> java.lang.IllegalStateException: Failing event COMMIT in state PREPARED
> for MyObject@oid679
> (data= org.eclipse.emf.internal.cdo.protocol.CommitTransactionResul t @614695)
> at
>
org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:152)
> at
> org.eclipse.emf.internal.cdo.CDOStateMachine.commit(CDOState Machine.java:275)
> at
>
org.eclipse.emf.internal.cdo.CDOTransactionImpl.postCommit(C DOTransactionImpl.java:492)
> at
>
org.eclipse.emf.internal.cdo.CDOTransactionImpl.commit(CDOTr ansactionImpl.java:250)

> I understand why I have this exception : the object will be added in the
> transaction, the state of the transaction changes, and I try to commit !

> I would like to know, if it's possible to add a listener after (and not
> before) the object is added in a transaction. Is there another solution ?

> David
Since no one as answered the original question about the exception, I'll
take a crack at it.
Re: [CDO] "Auto commit" [message #425535 is a reply to message #425529] Mon, 01 December 2008 10:38 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Tom, David and Vik,

I think you should not be required to add commit operations only for
"technical" reasons, i.e. to avoid OutOfMemoryExceptions. This is not
only inconvenient but also blurs the logical view of a possible commit
history but also dramatically increases the size in auditing back-ends.
I filed the following bugs:

257050: Better client-side scalability of transactions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=257050

257048: Better server-side scalability of transactions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=257048

More comments below...



Tom Crockett schrieb:
> Hey David,
>
> It looks as though by attempting to commit directly from the
> addingObject() method you're catching the CDOStateMachine in the
> intermediate PREPARED state that exists between TRANSIENT and NEW; the
> only valid states for an object to be committed are NEW and DIRTY.
> This is probably happening because the CDOTransactionHandler gets to
> hear about added objects before ordinary adapters, one of which I
> believe is responsible for making the (almost immediate) transition
> from PREPARED to NEW.
Correct. This is because a concrete CDOTransactionHandler should be able
to *prevent* subsequent commit operations rather than bringing it forward.

>
> I have a similar need for auto-commit in my own project, except that
> we are using EMF Transactions, and we commit upon hearing of any (EMF)
> transaction finishing. I can tell you from experience that one thing
> you will definitely want to implement is some form of coalescing
> events, so that 20 changes to various EObjects does not result in 20
> separate commits for each of the deltas. That would be Very Bad :) I
> would recommend something like the following:
>
> synchronized void scheduleCommit() {
> if (!alreadyCommitting) {
> alreadyCommitting = true;
> new Thread("commit thread") {
> public void run() {
> try {
> Thread.sleep(500);
> transaction.commit();
> } catch (InterruptedException) {
> ...
> } finally {
> alreadyCommitting = false;
> }
> }
> }.start();
> }
> }
>
> Doing something like this would also more or less take care of the
> exception you're seeing, because the actual commit would take place at
> a later date, when the state machine had had plenty of time to
> transition from PREPARED to NEW. I'm not sure if there's a chance that
> the resulting commit would take place in that very brief PREPARED
> state, but it seems very unlikely at the least, and perhaps Eike has
> put in place some synchronization to prevent that.
Do you think that we need such coalescing even when we have transparent
support for transactions of arbitrary sizes? If so, please file a
bugzilla so that we don't forget about it.

Cheers
/Eike

----
http://thegordian.blogspot.com


>
> Hope that helps,
>
> Tom
>
> David Bonneau wrote:
>
>> Hi
>
>> I'm working on an application that manages very large model. For
>> this, I use CDO 1.0.x.
>
>> I have one transaction (only one client), and I have to commit
>> often this transaction, if I don't want to use too memory (to prevent
>> OutOfMemoryException). I would like this commit is automatic. I don't
>> want to have to add everywhere in my code : myTransaction.commit.
>
>> I try to add a listener (a CDOTransactionHandler) to my
>> transaction. I'm able to known if an object is added or modified in
>> the transaction. Every X add or modification I try to commit the
>> transaction. But if I commit in the addedObject method, I have the
>> following exception :
>
>> java.lang.IllegalStateException: Failing event COMMIT in state
>> PREPARED for MyObject@oid679
>> (data= org.eclipse.emf.internal.cdo.protocol.CommitTransactionResul t @614695)
>>
>> at
> org.eclipse.net4j.util.fsm.FiniteStateMachine.process(Finite StateMachine.java:152)
>
>> at
>> org.eclipse.emf.internal.cdo.CDOStateMachine.commit(CDOState Machine.java:275)
>>
>> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.postCommit(C DOTransactionImpl.java:492)
>
>> at
> org.eclipse.emf.internal.cdo.CDOTransactionImpl.commit(CDOTr ansactionImpl.java:250)
>
>
>> I understand why I have this exception : the object will be added in
>> the transaction, the state of the transaction changes, and I try to
>> commit !
>
>> I would like to know, if it's possible to add a listener after (and
>> not before) the object is added in a transaction. Is there another
>> solution ?
>
>> David
> Since no one as answered the original question about the exception,
> I'll take a crack at it.
>


Re: [CDO] "Auto commit" [message #425574 is a reply to message #425535] Mon, 01 December 2008 20:11 Go to previous messageGo to next message
Tom Crockett is currently offline Tom CrockettFriend
Messages: 54
Registered: July 2009
Member
Eike Stepper wrote:

> Do you think that we need such coalescing even when we have transparent
> support for transactions of arbitrary sizes? If so, please file a
> bugzilla so that we don't forget about it.

I see coalescing as being necessary primarily in an auto-commit scheme
where you need to schedule a commit every time someone dirties the
transaction, either by adding new objects or dirtying old objects. You
don't want to actually DO a commit, synchronously, every time you hear of
a dirtied transaction--you just want to schedule one for a little bit
later, so that if n changes happen in quick succession, you won't trigger
n synchronous commits one after the other. If you plan to add API support
for auto-committing, I think it would be good to add an asynchronous
commit scheduling mechanism like this.

Tom
Re: [CDO] "Auto commit" [message #425579 is a reply to message #425574] Mon, 01 December 2008 22:46 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Tom,

This should be comparingly easy to achieve. Can you please file an
enhancement request?

Cheers
/Eike

----
http://thegordian.blogspot.com



Tom Crockett schrieb:
> Eike Stepper wrote:
>
>> Do you think that we need such coalescing even when we have
>> transparent support for transactions of arbitrary sizes? If so,
>> please file a bugzilla so that we don't forget about it.
>
> I see coalescing as being necessary primarily in an auto-commit scheme
> where you need to schedule a commit every time someone dirties the
> transaction, either by adding new objects or dirtying old objects. You
> don't want to actually DO a commit, synchronously, every time you hear
> of a dirtied transaction--you just want to schedule one for a little
> bit later, so that if n changes happen in quick succession, you won't
> trigger n synchronous commits one after the other. If you plan to add
> API support for auto-committing, I think it would be good to add an
> asynchronous commit scheduling mechanism like this.
>
> Tom
>


Re: [CDO] "Auto commit" [message #425595 is a reply to message #425579] Tue, 02 December 2008 21:57 Go to previous message
Tom Crockett is currently offline Tom CrockettFriend
Messages: 54
Registered: July 2009
Member
Done: https://bugs.eclipse.org/bugs/show_bug.cgi?id=257274

Eike Stepper wrote:

> Tom,

> This should be comparingly easy to achieve. Can you please file an
> enhancement request?

> Cheers
> /Eike

> ----
> http://thegordian.blogspot.com



> Tom Crockett schrieb:
>> Eike Stepper wrote:
>>
>>> Do you think that we need such coalescing even when we have
>>> transparent support for transactions of arbitrary sizes? If so,
>>> please file a bugzilla so that we don't forget about it.
>>
>> I see coalescing as being necessary primarily in an auto-commit scheme
>> where you need to schedule a commit every time someone dirties the
>> transaction, either by adding new objects or dirtying old objects. You
>> don't want to actually DO a commit, synchronously, every time you hear
>> of a dirtied transaction--you just want to schedule one for a little
>> bit later, so that if n changes happen in quick succession, you won't
>> trigger n synchronous commits one after the other. If you plan to add
>> API support for auto-committing, I think it would be good to add an
>> asynchronous commit scheduling mechanism like this.
>>
>> Tom
>>
Previous Topic:Containment
Next Topic:Retrieve ItemProvider based on the EClass
Goto Forum:
  


Current Time: Thu Apr 25 13:09:14 GMT 2024

Powered by FUDForum. Page generated in 0.04250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top