• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EOSharedEditingContext question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOSharedEditingContext question


  • Subject: Re: EOSharedEditingContext question
  • From: Chuck Hill <email@hidden>
  • Date: Thu, 3 Feb 2005 10:39:01 -0800

I'm not a shared EC expert and not really comfortable playing at one. For the most part I have avoided using them due to the high number of bugs, historically speaking. OK, that said...

On Feb 3, 2005, at 10:02 AM, Dov Rosenberg wrote:

We use shared editing contexts to save the overhead on read only data and to
use it like a cache. When we use the shared context we always do a lock()
even for a read type operation. In cases where we are going to modify data
that has been retrieved into the shared context, we create a new editing
context and make the changes and save. We lock both the shared and the
regular context when we do.


IIRC, when editing a EO in shared ec the pattern is supposed to be:
- create ec
- lock ec
- set ec's shared ec to null
- fetch (faulting is OK?) the object into the EC
- edit the object and save the EC
- unlock the EC

There is not need to lock the shared EC, it will pick up the changes itself.


Based on your reply I think we need to make some changes. Does the following
make any sense?


1. Instead of creating a new regular EOEditingContext, perhaps we should
make them a nested editing context with the shared editing context as the
parent. That way we make sure to get the correct state of things before we
make the changes and save to the db. Can a shared editing context have
nested editing contexts? If so, hopefully the changes will get recorded
properly by the shared context and be more efficient than what we are doing


I don't think that would be good. If the EC is nested, to save any changes to objects in it, you would also have to save the shared EC. I'd follow Ben's advice: think of it as a data store not an editing context regardless of what the super class is.


2. If we remove the lock(), unlock() from the sharededitingcontext usage
will that start sending out the missing lock messages again? I kind of
remember we had to add the lock() calls to get rid of those.


If it does, that is a bug in the shared EC.


The big qualifier for us is our app is not a typical WO app from the
perspective that our JSP tag library uses EOF but not WO components. We
really don't have WOSessions (except for the JSP Session/WOSession
integration). Our app runs as a servlet outside of the scope of the .woa
application. For the most part this works very well and we have been this
way for the past 3 years with great success.


I would not expect this to be an issue. The shared EC locks _itself_ using, IIRC, com.webobjects.foundation.NSMultiReaderLock. This is in contrast to the defaultEditingContext() of WOSession which is locked and unlocked externally by WOSession. I am not aware of any functional dependancies on anything in the WO side of things.


HTH Chuck


On 2/3/05 12:35 PM, "Chuck Hill" <email@hidden> wrote:

Hi Dov, I don't know if this is what you are looking for, but this was
posted a (long) while ago by Ben Trumbull:

------------
Although an EOSharedEditingContext sounds and appears like an editing
context, it's probably a more useful view to consider it a very special
EOObjectStore. I prefer to call it a "read mostly object store".


Several differences.

First, correctly locking and unlocking an EC at the application level
is your responsibility, regardless of whether or not you believe an
operation is "an edit".  For example, firing a fault causes side
effects upon various caches.  EOSharedEditingContexts manage their own
locking.

Second, EOSharedEditingContexts are "read mostly".  Mutating EOs in
them is complicated and inefficient.

Third, regular ECs "have" one shared EC, a lot like they have a parent
object store. This means that several regular ECs all using the same
shared EC also use the same objects that are within the shared EC. EOs
within a shared EC are unique instances, unlike all other EOs which
have individual instances in each regular EC, even though they have the
same primary key (GID).


Basically, this is a memory-performance compromise.  Using a shared EC
means not only do your EOs reuse the cached row level snapshots in
EOAccess, but they are also represented by the same Java objects. The
down side is that shared ECs do more locking, and changing EOs within
them is inconvenient.

In summary, EOSharedEditingContext is really more about implementation
inheritance than interface inheritance.
---------------------------------

I suspect your problem had to do with you locking the shared EC
yourself and the locks staying in place too long.  Consider this
hypothetical situation:

Thead 1: locks EC, shared EC, performs operations which results in an
attempt to lock object store coordinator

Thread 2: performs some operation, locks object store coordinator,
execution of operation requires operation on shared EC, shared EC
attempts to lock itself

At this point you have a deadly embrace. Thread one has the shared ec
locked and is waiting to lock the OSC. Thread 2 has the OSC locked and
is waiting to lock the shared EC.


Chuck


On Feb 2, 2005, at 3:42 PM, Dov Rosenberg wrote:

We recently fixed a bug in our application that was causing it to lock
when multiple users submitted a form request via http. After
scratching our heads for a long while we went to look in the “Bible”
(Chuck Hill’s Practical WebObjects – great book). We came across a
little blurb about not locking SharedEditingContexts. When we removed
the lock it seems to have cleared up our deadlock problem. But we are
stumped as to why this caused us a headache.


Our app uses both a sharededitingcontext and regular editing contexts
created doing new EOEditingContext(). We lock and unlock both the
shared and regular editing contexts everywhere. It seems that our
problem only manifested itself when we were writing to the database
(not reading). It was also not consistently reproducible.


 Any thoughts or comments would be appreciated.

 Thanks in advance



 --
 Dov Rosenberg
 Conviveon Corporation
http://www.conviveon.com

     _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
village.net

This email sent to email@hidden




--
Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: EOSharedEditingContext question
      • From: "Jonathan Fleming" <email@hidden>
References: 
 >Re: EOSharedEditingContext question (From: Dov Rosenberg <email@hidden>)

  • Prev by Date: Re: Raw Rows versus EOs
  • Next by Date: Re: Xcode 1.5 Cont'd
  • Previous by thread: Re: EOSharedEditingContext question
  • Next by thread: Re: EOSharedEditingContext question
  • Index(es):
    • Date
    • Thread