I am having an OutOfMemoryException while upgrading a date field of several hundreds of thousands of entities in one transaction.

Code sample :

events = Query.All<Event>().Where(a => a.When != null);
foreach (var entity in events)
  entity.When = entity.When.Value.ToUniversalTime();

Context :

Dataobjects.Net, the code is in an opened transaction which does many other upgrades but none will go out of memory.

Question :

Is this a bug or is there a better pattern to do this ? Can i use nested transaction for it ? Shall I call Session.Current.SaveChanges() every 100000 updated entities ?

Stacktrace :

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.Generic.Dictionary`2.Resize(Int32 newSize, Boolean forceNewHashCodes)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Xtensive.Caching.WeakCache`2.Add(TItem item, Boolean replaceIfExists)
   at Xtensive.Caching.LruCache`2.Clear()
   at Xtensive.Orm.Session.Dispose()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.PerformUpgrade(Domain domain, UpgradeStage stage)
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.BuildMultistageDomain()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.Run()
   at Xtensive.Orm.Upgrade.UpgradingDomainBuilder.Build(DomainConfiguration configuration)
   at Xtensive.Orm.Domain.Build(DomainConfiguration configuration)



asked Aug 04 '15 at 10:27

Benoit%20Nesme's gravatar image

Benoit Nesme

edited Aug 04 '15 at 10:28

Hello Benoit Nesme

I suppose you upgrade a date field in OnStage. Am I right?

(Aug 05 '15 at 05:01) Alexey Kulakov Alexey%20Kulakov's gravatar image

Hi Alexey, I am in the override of UpgradeHandler.OnUpgrade() Which indeed is called from OnStage()

(Aug 05 '15 at 06:18) Benoit Nesme Benoit%20Nesme's gravatar image

I found my way through what I consider as a bug, splitting the big upgrade operation in two (under two different system sessions).

Can the call of weakcache.Add(item) be the issue of this outofmemory ?

(Aug 06 '15 at 09:27) Benoit Nesme Benoit%20Nesme's gravatar image

One Answer:

Hello Benoit Nesme

Domain building (especially in Perform and PerformSafely mode) is quite resource-intensive process.

If you need only to update date fields you may try to move this operations to UpgradeHandler.OnComplete(Domain domain) when all the building operations are finished.

I found some problems on disposing of session cache. We'll fix them in one of next versions, but, unfortunately, not in 4.6 branch.

answered Aug 07 '15 at 03:20

Alexey%20Kulakov's gravatar image

Alexey Kulakov

Thanks Alexey, I'll give a look at UpgradeHandler.OnComplete

(Aug 07 '15 at 03:26) Benoit Nesme Benoit%20Nesme's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Aug 04 '15 at 10:27

Seen: 5,399 times

Last updated: Aug 07 '15 at 03:26

powered by OSQA