Cleans up old notes

This commit is contained in:
Shannon
2020-01-06 21:39:26 +11:00
parent c2ac5e8531
commit 95337d5a70
5 changed files with 73 additions and 89 deletions

View File

@@ -157,40 +157,44 @@ namespace Umbraco.Web.PublishedCache.NuCache
private void Release(WriteLockInfo lockInfo, bool commit = true)
{
if (commit == false)
try
{
lock(_rlocko)
if (commit == false)
{
// see SnapDictionary
try { }
finally
lock (_rlocko)
{
_nextGen = false;
_liveGen -= 1;
// see SnapDictionary
try { }
finally
{
_nextGen = false;
_liveGen -= 1;
}
}
}
Rollback(_contentNodes);
RollbackRoot();
Rollback(_contentTypesById);
Rollback(_contentTypesByAlias);
}
else if (_localDb != null && _wchanges != null)
{
foreach (var change in _wchanges)
Rollback(_contentNodes);
RollbackRoot();
Rollback(_contentTypesById);
Rollback(_contentTypesByAlias);
}
else if (_localDb != null && _wchanges != null)
{
if (change.Value.IsNull)
_localDb.TryRemove(change.Key, out ContentNodeKit unused);
else
_localDb[change.Key] = change.Value;
foreach (var change in _wchanges)
{
if (change.Value.IsNull)
_localDb.TryRemove(change.Key, out ContentNodeKit unused);
else
_localDb[change.Key] = change.Value;
}
_wchanges = null;
_localDb.Commit();
}
_wchanges = null;
_localDb.Commit();
}
// TODO: Shouldn't this be in a finally block?
if (lockInfo.Taken)
Monitor.Exit(_wlocko);
finally
{
if (lockInfo.Taken)
Monitor.Exit(_wlocko);
}
}
private void RollbackRoot()
@@ -256,10 +260,6 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
finally
{
_logger.Info<ContentStore>("Releasing ContentStore...");
// TODO: I don't understand this, we would have already closed the BPlusTree store above??
// I guess it's 'safe' and will just decrement the write lock counter?
Release(lockInfo);
}
}

View File

@@ -39,15 +39,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public void Resync()
{
// This is annoying since this can cause deadlocks. Since this will be cleared if something happens in the same
// thread after that calls Elements, it will re-lock the _storesLock but that might already be locked again
// and since we're most likely in a ContentStore write lock, the other thread is probably wanting that one too.
// no lock - published snapshots are single-thread
// TODO: Instead of clearing, we could hold this value in another var in case the above call to GetElements() Or potentially
// a new TryGetElements() fails (since we might be shutting down). In that case we can use the old value.
_elements?.Dispose();
_elements = null;
}

View File

@@ -670,15 +670,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
publishedChanged = publishedChanged2;
}
// TODO: These resync's are a problem, they cause deadlocks because when this is called, it's generally called within a writelock
// and then we clear out the snapshot and then if there's some event handler that needs the content cache, it tries to re-get it
// which first tries locking on the _storesLock which may have already been acquired and in this case we deadlock because
// we're still holding the write lock.
// We resync at the end of a ScopedWriteLock
// BUT if we don't resync here then the current snapshot is out of date for any event handlers that wish to use the most up to date
// data...
// so we need to figure out how to deal with the _storesLock
if (draftChanged || publishedChanged)
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync();
}