From 8d74efb6358d594e12b800a1d70cf97d7a8415cd Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 21 Sep 2021 12:28:49 +0200 Subject: [PATCH] Handle maindom was acquired doing install, so we do not have our lock Id in the database.. --- .../Runtime/SqlMainDomLock.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs index 5e4597903a..5be1d13a7b 100644 --- a/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs +++ b/src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs @@ -40,7 +40,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime private bool _errorDuringAcquiring; private readonly object _locker = new object(); private bool _hasTable = false; - + private bool _acquireWhenTablesNotAvailable = false; public SqlMainDomLock( ILogger logger, ILoggerFactory loggerFactory, @@ -99,7 +99,8 @@ namespace Umbraco.Cms.Infrastructure.Runtime _hasTable = db.HasTable(Cms.Core.Constants.DatabaseSchema.Tables.KeyValue); if (!_hasTable) { - // the Db does not contain the required table, we must be in an install state we have no choice but to assume we can acquire + _logger.LogDebug("The DB does not contain the required table, we must be in an install state we have no choice but to assume we can acquire"); + _acquireWhenTablesNotAvailable = true; return true; } @@ -225,6 +226,13 @@ namespace Umbraco.Cms.Infrastructure.Runtime } } + // In case we acquired the main dom doing install, there was no database. We therefore has to insert our lockId now, but only handle this once. + if (_acquireWhenTablesNotAvailable) + { + _acquireWhenTablesNotAvailable = false; + InsertLockRecord(_lockId, db); + } + db.BeginTransaction(IsolationLevel.ReadCommitted); // get a read lock _sqlServerSyntax.ReadLock(db, Cms.Core.Constants.Locks.MainDom); @@ -434,7 +442,10 @@ namespace Umbraco.Cms.Infrastructure.Runtime private bool IsMainDomValue(string val, IUmbracoDatabase db) { return db.ExecuteScalar("SELECT COUNT(*) FROM umbracoKeyValue WHERE [key] = @key AND [value] = @val", - new { key = MainDomKey, val = val }) == 1; + new { key = MainDomKey, val = val }) == 1; + + + } /// @@ -447,6 +458,7 @@ namespace Umbraco.Cms.Infrastructure.Runtime #region IDisposable Support private bool _disposedValue = false; // To detect redundant calls + protected virtual void Dispose(bool disposing) { if (!_disposedValue)