mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 23:42:33 +01:00
Updated transaction locks to be defered.
This commit is contained in:
parent
06d8d1e2bb
commit
af3c0de4d5
@ -894,10 +894,10 @@ namespace Marr.Data
|
|||||||
ClosingConnection = null;
|
ClosingConnection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeginTransaction()
|
public void BeginTransaction(IsolationLevel isolationLevel)
|
||||||
{
|
{
|
||||||
OpenConnection();
|
OpenConnection();
|
||||||
DbTransaction trans = Command.Connection.BeginTransaction();
|
DbTransaction trans = Command.Connection.BeginTransaction(isolationLevel);
|
||||||
Command.Transaction = trans;
|
Command.Transaction = trans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ namespace Marr.Data
|
|||||||
|
|
||||||
#region - Connections / Transactions -
|
#region - Connections / Transactions -
|
||||||
|
|
||||||
void BeginTransaction();
|
void BeginTransaction(IsolationLevel isolationLevel);
|
||||||
void RollBack();
|
void RollBack();
|
||||||
void Commit();
|
void Commit();
|
||||||
event EventHandler OpeningConnection;
|
event EventHandler OpeningConnection;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Data;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
namespace Marr.Data
|
namespace Marr.Data
|
||||||
@ -54,12 +55,12 @@ namespace Marr.Data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeginTransaction()
|
public void BeginTransaction(IsolationLevel isolationLevel)
|
||||||
{
|
{
|
||||||
// Only allow one transaction to begin
|
// Only allow one transaction to begin
|
||||||
if (_transactionCount < 1)
|
if (_transactionCount < 1)
|
||||||
{
|
{
|
||||||
DB.BeginTransaction();
|
DB.BeginTransaction(isolationLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
_transactionCount++;
|
_transactionCount++;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@ -108,7 +109,7 @@ namespace NzbDrone.Core.Backup
|
|||||||
|
|
||||||
using (var unitOfWork = new UnitOfWork(() => _maindDb.GetDataMapper()))
|
using (var unitOfWork = new UnitOfWork(() => _maindDb.GetDataMapper()))
|
||||||
{
|
{
|
||||||
unitOfWork.BeginTransaction();
|
unitOfWork.BeginTransaction(IsolationLevel.Serializable);
|
||||||
|
|
||||||
var databaseFile = _appFolderInfo.GetNzbDroneDatabase();
|
var databaseFile = _appFolderInfo.GetNzbDroneDatabase();
|
||||||
var tempDatabaseFile = Path.Combine(_backupTempFolder, Path.GetFileName(databaseFile));
|
var tempDatabaseFile = Path.Combine(_backupTempFolder, Path.GetFileName(databaseFile));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using Marr.Data;
|
using Marr.Data;
|
||||||
@ -145,7 +146,7 @@ namespace NzbDrone.Core.Datastore
|
|||||||
{
|
{
|
||||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||||
{
|
{
|
||||||
unitOfWork.BeginTransaction();
|
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
|
||||||
|
|
||||||
foreach (var model in models)
|
foreach (var model in models)
|
||||||
{
|
{
|
||||||
@ -160,7 +161,7 @@ namespace NzbDrone.Core.Datastore
|
|||||||
{
|
{
|
||||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||||
{
|
{
|
||||||
unitOfWork.BeginTransaction();
|
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
|
||||||
|
|
||||||
foreach (var model in models)
|
foreach (var model in models)
|
||||||
{
|
{
|
||||||
@ -203,7 +204,7 @@ namespace NzbDrone.Core.Datastore
|
|||||||
{
|
{
|
||||||
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
||||||
{
|
{
|
||||||
unitOfWork.BeginTransaction();
|
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
|
||||||
|
|
||||||
foreach (var id in ids)
|
foreach (var id in ids)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
using FluentMigrator.Runner;
|
using FluentMigrator.Runner;
|
||||||
using FluentMigrator.Runner.Initialization;
|
using FluentMigrator.Runner.Initialization;
|
||||||
using FluentMigrator.Runner.Processors.SQLite;
|
using FluentMigrator.Runner.Processors.SQLite;
|
||||||
@ -21,6 +22,8 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||||||
|
|
||||||
public void MigrateToLatest(string connectionString, MigrationType migrationType)
|
public void MigrateToLatest(string connectionString, MigrationType migrationType)
|
||||||
{
|
{
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
_announcer.Heading("Migrating " + connectionString);
|
_announcer.Heading("Migrating " + connectionString);
|
||||||
|
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
@ -39,6 +42,10 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||||||
var processor = factory.Create(connectionString, _announcer, options);
|
var processor = factory.Create(connectionString, _announcer, options);
|
||||||
var runner = new MigrationRunner(assembly, migrationContext, processor);
|
var runner = new MigrationRunner(assembly, migrationContext, processor);
|
||||||
runner.MigrateUp(true);
|
runner.MigrateUp(true);
|
||||||
|
|
||||||
|
sw.Stop();
|
||||||
|
|
||||||
|
_announcer.ElapsedTime(sw.Elapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
using System.Data.Common;
|
||||||
|
using System.Data.SQLite;
|
||||||
|
using FluentMigrator.Runner.Processors;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration.Framework
|
||||||
|
{
|
||||||
|
public class MigrationDbFactory : DbFactoryBase
|
||||||
|
{
|
||||||
|
protected override DbProviderFactory CreateFactory()
|
||||||
|
{
|
||||||
|
return SQLiteFactory.Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||||||
|
|
||||||
public void ElapsedTime(TimeSpan timeSpan)
|
public void ElapsedTime(TimeSpan timeSpan)
|
||||||
{
|
{
|
||||||
|
_logger.Debug("Took: {0}", timeSpan);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Error(string message)
|
public void Error(string message)
|
||||||
|
@ -10,7 +10,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
|
|||||||
{
|
{
|
||||||
public override IMigrationProcessor Create(String connectionString, IAnnouncer announcer, IMigrationProcessorOptions options)
|
public override IMigrationProcessor Create(String connectionString, IAnnouncer announcer, IMigrationProcessorOptions options)
|
||||||
{
|
{
|
||||||
var factory = new SqliteDbFactory();
|
var factory = new MigrationDbFactory();
|
||||||
var connection = factory.CreateConnection(connectionString);
|
var connection = factory.CreateConnection(connectionString);
|
||||||
var generator = new SqliteGenerator() { compatabilityMode = CompatabilityMode.STRICT };
|
var generator = new SqliteGenerator() { compatabilityMode = CompatabilityMode.STRICT };
|
||||||
return new NzbDroneSqliteProcessor(connection, generator, announcer, options, factory);
|
return new NzbDroneSqliteProcessor(connection, generator, announcer, options, factory);
|
||||||
|
@ -22,7 +22,8 @@ namespace NzbDrone.Core.Instrumentation
|
|||||||
|
|
||||||
public DatabaseTarget(IConnectionStringFactory connectionStringFactory)
|
public DatabaseTarget(IConnectionStringFactory connectionStringFactory)
|
||||||
{
|
{
|
||||||
_connection = new SQLiteConnection(connectionStringFactory.LogDbConnectionString).OpenAndReturn();
|
_connection = new SQLiteConnection(connectionStringFactory.LogDbConnectionString);
|
||||||
|
_connection.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Register()
|
public void Register()
|
||||||
|
@ -230,6 +230,7 @@
|
|||||||
<Compile Include="Datastore\Migration\067_add_added_to_series.cs" />
|
<Compile Include="Datastore\Migration\067_add_added_to_series.cs" />
|
||||||
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
|
||||||
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
|
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
|
||||||
|
<Compile Include="Datastore\Migration\Framework\MigrationDbFactory.cs" />
|
||||||
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
|
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />
|
||||||
<Compile Include="Datastore\Migration\Framework\MigrationLogger.cs" />
|
<Compile Include="Datastore\Migration\Framework\MigrationLogger.cs" />
|
||||||
<Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" />
|
<Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user