New Posts New Posts RSS Feed: Refreshing Cache Oddness
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Refreshing Cache Oddness

 Post Reply Post Reply
Author
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Topic: Refreshing Cache Oddness
    Posted: 21-Oct-2010 at 3:01pm

We're currently using Version 6.0.4

 

We're have an intermittent, unusual problem while performing a refresh of data.  In short, the client is requesting that the server perform a possibly 'long' operation.  The server does it's processing asyncronously, adding/modifying around 90 Units to our table, with the possibility of hundreds of UnitCycles and SourcingDecisions.  The server finishes, saves, and the async call is complete.  The client now has to query for all the newly added entities.

 

Our Original Code (executed when the server operation is complete):

 

IEntityQuery<Unit> query = _entityManager.Units

                .Where(i => i.COA.UniqueID == coaID)

                .Include("SourcingDecisions")

                .Include("SourcingDecisions.UnitCycle")

                .Include("UnitCycles")

                .Include("UnitCycles. Unit")

                .With(QueryStrategy.DataSourceOnly);

 

_entityManager.ExecuteQueryAsync<Unit>(query, (args) =>

{

                Refetched_Entities(args.Results);

 

}, null);

 

The problem we're having is that occassionally we get an Exception in the callback args from the query indicating that "An entity with this key: Unit: 8412cc8a-0c6d-4c83-9c59-01c9049be817 already exists in this EntityManager".  What's odd to us about the error message is we're not Adding a new Unit to the entity manager with a duplicate key, we're simply querying for data... who cares if the Unit with that key is already in cache; if it is it's the same Unit, we just want a fresh copy of it.

 

Even more oddness.  To attempt to get around the problem we added the following code before the query.

 

EntityState removeState =

               EntityState.Added | EntityState.Deleted | EntityState.Detached | EntityState.Modified | EntityState.Unchanged;

 

_entityManager.RemoveEntities(typeof(SourcingDecision), removeState);

_entityManager.RemoveEntities(typeof(UnitCycle), removeState);

_entityManager.RemoveEntities(typeof(Unit), removeState);

 

So at this point, the cache should be completely cleared of all Units and yet, we still will receive the same Exception.

 

Any help would be appreciated.

 

The Exception:

 

System.Reflection.TargetInvocationException was unhandled by user code
  Message=An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.
  StackTrace:
       at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
       at IdeaBlade.EntityModel.EntityQueriedEventArgs`1.get_Results()
       at IdeaBlade.EntityModel.EntityQueryOperation`1.get_Results()
       at AST.Web.SourcingCOA.SL.COAUnitDataManager.<RefetchData>b__0(EntityQueryOperation`1 args)
       at IdeaBlade.EntityModel.EntityQueryOperation`1.IdeaBlade.EntityModel.IHasAsyncEventArgs.OnCompleted()
       at IdeaBlade.EntityModel.AsyncProcessor`1.<>c__DisplayClass2.<.ctor>b__0(TArgs args)
       at IdeaBlade.EntityModel.AsyncProcessor`1.Signal()
       at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)
  InnerException: System.InvalidOperationException
       Message=An entity with this key: Unit: 8412cc8a-0c6d-4c83-9c59-01c9049be817 already exists in this EntityManager
       StackTrace:
            at IdeaBlade.EntityModel.EntityGroup.AddToKeyMap(EntityWrapper wrapper)
            at IdeaBlade.EntityModel.EntityGroup.AddEntityCore(EntityWrapper wrapper)
            at IdeaBlade.EntityModel.EntityGroup.AddNewEntity(EntityWrapper wrapper)
            at IdeaBlade.EntityModel.EntityManager.AddEntityWrapper(EntityWrapper wrapper)
            at IdeaBlade.EntityModel.EntityReferenceBase.AttachIfPossible(EntityWrapper newValueWrapper)
            at IdeaBlade.EntityModel.RelatedEntityList`1.AddOrInsert(Int32 index, T item, Boolean updateInverse)
            at IdeaBlade.EntityModel.RelatedEntityList`1.Add(T item, Boolean updateInverse)
            at IdeaBlade.EntityModel.ListEntityReference`1.AddEntity(Object entity, Boolean updateInverse)
            at IdeaBlade.EntityModel.ListEntityReference`1.FixupReferences()
            at IdeaBlade.EntityModel.EntityWrapper.<FixupReferences>b__13(EntityReferenceBase eref)
            at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
            at IdeaBlade.EntityModel.EntityWrapper.FixupReferences()
            at IdeaBlade.EntityModel.EntityWrapper.TrackChanged(EntityChangedEventArgs e)
            at IdeaBlade.EntityModel.EntityGroup.OnEntityChanged(EntityChangedEventArgs e)
            at IdeaBlade.EntityModel.EntityGroup.AddQueriedEntity(EntityWrapper wrapper)
            at IdeaBlade.EntityModel.EntityGroup.LoadEntity(EntityWrapper sourceWrapper, MergeStrategy mergeStrategy, Boolean& rowUpdated)
            at IdeaBlade.EntityModel.EntityMerger.MergeEntityCore(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup)
            at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.FindOrMergeTarget(EntityWrapper sourceWrapper, NavigationEntityProperty navProp, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.MergeScalarNavProp(EntityReferenceManager sourceRefManager, NavigationEntityProperty navProp, EntityReferenceBase targetSref, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.MergeNavProperties(InProcessInfo inProcessInfo, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.MergeEntityNavProperties(InProcessInfo inProcessInfo, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.MergeEntity(EntityWrapper sourceWrapper, EntityGroup targetEntityGroup, NavigationContext context)
            at IdeaBlade.EntityModel.EntityMerger.<>c__DisplayClass1.<MergeEntities>b__0(EntityWrapper sourceWrapper)
            at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x)
            at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
            at IdeaBlade.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action)
            at IdeaBlade.EntityModel.DataBlockFns.MakeResultList(Type type, IEnumerable items, Boolean isOrdered)
            at IdeaBlade.EntityModel.EntityQueryResult.UpdateDataSet(EntitiesDataBlock block, NavigationContext context)
            at IdeaBlade.EntityModel.EntitiesDataBlock.Resolve(EntityQueryResult helper)
            at IdeaBlade.EntityModel.EntityQueryResult..ctor(DataQueryResult dataQueryResult, EntityManager entityManager, MergeStrategy mergeStrategy, Guid queryId, QueryInfo queryInfo)
            at IdeaBlade.EntityModel.EntityQueryResultCollection..ctor(DataQueryResultCollection dqResults, EntityManager entityManager, MergeStrategy mergeStrategy)
            at IdeaBlade.EntityModel.EntityManager.MergeAndReturnDataSourceOnly(IEntityFinder finder, DataQueryResultCollection dqResults)
            at IdeaBlade.EntityModel.EntityManager.ProcessFetchedData(DataQueryResultCollection dqResults, IEntityFinder finder)
            at IdeaBlade.EntityModel.EntityManager.AsyncFetchCompleted(AsyncEventArgs args)
            at IdeaBlade.EntityModel.EntityManager.<ExecuteQueryAsyncCore>b__57[T](EntityQueryOperation`1 op)
            at IdeaBlade.EntityModel.AsyncProcessor`1.<Execute>b__5(Object x)
       InnerException:

 

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 22-Oct-2010 at 7:22pm
My first thought was that the nature of the relationships might be confusing DevForce as it merges the results back into cache, but using simplified versions of your entities I haven't been able to prove this.  The error you see is occurring as the newly queried entities are merged into cache:  during fixup of the references for one of the lists (SourcingDecisions or UnitCycles) the merge thinks it's found a "new" entity and wants to add it to cache. 
 
This is likely a bug in the fixup logic, although since I'm unable to reproduce it right now I can't offer you any advice or a workaround.  If you can send some test data for these three entities that would be a big help.  Also, when you do the refresh, do you know if there have been a lot of changes, deletions or additions in the data?  
 
Email IdeaBladeSupportTrack with subject line "[#9103]" if you send anything to support.
Back to Top
btitular View Drop Down
Newbie
Newbie
Avatar

Joined: 08-Oct-2009
Location: CA
Posts: 20
Post Options Post Options   Quote btitular Quote  Post ReplyReply Direct Link To This Post Posted: 23-Oct-2010 at 12:11pm
I'm getting the same "already exists in this EntityManager" error. I'm on 6.0.5.0. I can't consistently reproduce the error, but it does occur. In my case, it occurs when I'm executing a
 
_mgr.SaveChangesAsync(auditUpdateList, null, null, null)
 
We're selectively saving this entity and it consists of only one item.
 
The entity has no relationships. The table that it is linked to has an identity key. The entity gets saved to the database, but I get the exception thrown about an existing key. As you mentioned above, it looks like something's failing in the fixup logic.
 
I'm going to try to write a small test project to see if I can get the error to occur so I can send that to you.
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 23-Oct-2010 at 12:20pm

btitular, thanks!

Back to Top
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2010 at 10:15am
I finally freed up enough time to put together a sample application that would replicate the problem consistently.  Since my original post upgraded to version 6.0.6.1.  I sent the sample to IdeaBladeSupportTrack@ideablade.com with [#9103] as the subject line.
 
It seems to be directly related to performing queries combined with calls to RemoveEntities.  In the sample app, no modifications of any kind are happening to the data.  It's literally, query, RemoveEntities, query, exception, and it seems to be query dependent (in other words, not all queries will result in the issue).
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2010 at 7:02pm
Hi Ken,
 
We got your email on Friday.  I'll take a look at the sample on Monday and let you know what I find.
Back to Top
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Posted: 18-Nov-2010 at 10:09am
Thanks Kim.  Any updates or ideas how to work around this yet? 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 18-Nov-2010 at 10:38am
I don't have a workaround for you, but there is an EAP build of 6.0.7 available which contains the fix for the problem.  I sent you the download URL last week in reply to support case #9103, but if you haven't downloaded it yet I'll need to send you the new URL, since we've had another EAP build posted since then.
Back to Top
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Posted: 18-Nov-2010 at 10:40am
Awesome, I'll take a look at it.  Thanks again.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down