Fixing accidental api signature breaking change

This commit is contained in:
Shannon
2020-01-23 16:23:27 +11:00
parent 1dfdfba236
commit 201927580c
2 changed files with 11 additions and 6 deletions

View File

@@ -251,10 +251,10 @@ where tbl.[name]=@0 and col.[name]=@1;", tableName, columnName)
public override void WriteLock(IDatabase db, params int[] lockIds)
{
WriteLock(db, 1800, lockIds);
WriteLock(db, TimeSpan.FromMilliseconds(1800), lockIds);
}
public void WriteLock(IDatabase db, int millisecondsTimeout, params int[] lockIds)
public void WriteLock(IDatabase db, TimeSpan timeout, params int[] lockIds)
{
// soon as we get Database, a transaction is started
@@ -265,7 +265,7 @@ where tbl.[name]=@0 and col.[name]=@1;", tableName, columnName)
// *not* using a unique 'WHERE IN' query here because the *order* of lockIds is important to avoid deadlocks
foreach (var lockId in lockIds)
{
db.Execute($"SET LOCK_TIMEOUT {millisecondsTimeout};");
db.Execute($"SET LOCK_TIMEOUT {timeout.TotalMilliseconds};");
var i = db.Execute(@"UPDATE umbracoLock WITH (REPEATABLEREAD) SET value = (CASE WHEN (value=1) THEN -1 ELSE 1 END) WHERE id=@id", new { id = lockId });
if (i == 0) // ensure we are actually locking!
throw new ArgumentException($"LockObject with id={lockId} does not exist.");

View File

@@ -39,6 +39,11 @@ namespace Umbraco.Core.Runtime
public async Task<bool> AcquireLockAsync(int millisecondsTimeout)
{
if (!(_dbFactory.SqlContext.SqlSyntax is SqlServerSyntaxProvider sqlServerSyntaxProvider))
throw new NotSupportedException("SqlMainDomLock is only supported for Sql Server");
_sqlServerSyntax = sqlServerSyntaxProvider;
_logger.Debug<SqlMainDomLock>("Acquiring lock...");
var db = GetDatabase();
@@ -52,7 +57,7 @@ namespace Umbraco.Core.Runtime
try
{
// wait to get a write lock
_sqlServerSyntax.WriteLock(db, millisecondsTimeout, Constants.Locks.MainDom);
_sqlServerSyntax.WriteLock(db, TimeSpan.FromMilliseconds(millisecondsTimeout), Constants.Locks.MainDom);
}
catch (Exception ex)
{
@@ -136,7 +141,7 @@ namespace Umbraco.Core.Runtime
db.BeginTransaction(IsolationLevel.ReadCommitted);
// get a read lock
_sqlServerSyntax.ReadLock(db, Constants.Locks.MainDom);
_dbFactory.SqlContext.SqlSyntax.ReadLock(db, Constants.Locks.MainDom);
// TODO: We could in theory just check if the main dom row doesn't exist, that could indicate that
// we are still the maindom. An empty value might be better because then we won't have any orphan rows
@@ -209,7 +214,7 @@ namespace Umbraco.Core.Runtime
db.BeginTransaction(IsolationLevel.ReadCommitted);
// get a read lock
_sqlServerSyntax.ReadLock(db, Constants.Locks.MainDom);
_dbFactory.SqlContext.SqlSyntax.ReadLock(db, Constants.Locks.MainDom);
// the row
var mainDomRows = db.Fetch<KeyValueDto>("SELECT * FROM umbracoKeyValue WHERE [key] = @key", new { key = MainDomKey });