1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00

Merge pull request #147 from Sonarr/sqlite-lock

Updated transaction locks to be defered.
This commit is contained in:
Keivan Beigi 2014-11-24 16:22:12 -08:00
commit e226bf19e1
11 changed files with 39 additions and 12 deletions

View File

@ -894,10 +894,10 @@ private void UnbindEvents()
ClosingConnection = null;
}
public void BeginTransaction()
public void BeginTransaction(IsolationLevel isolationLevel)
{
OpenConnection();
DbTransaction trans = Command.Connection.BeginTransaction();
DbTransaction trans = Command.Connection.BeginTransaction(isolationLevel);
Command.Transaction = trans;
}

View File

@ -90,7 +90,7 @@ public interface IDataMapper : IDisposable
#region - Connections / Transactions -
void BeginTransaction();
void BeginTransaction(IsolationLevel isolationLevel);
void RollBack();
void Commit();
event EventHandler OpeningConnection;

View File

@ -1,4 +1,5 @@
using System;
using System.Data;
using System.Runtime.Serialization;
namespace Marr.Data
@ -54,12 +55,12 @@ public UnitOfWorkSharedContext SharedContext
}
}
public void BeginTransaction()
public void BeginTransaction(IsolationLevel isolationLevel)
{
// Only allow one transaction to begin
if (_transactionCount < 1)
{
DB.BeginTransaction();
DB.BeginTransaction(isolationLevel);
}
_transactionCount++;

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
@ -108,7 +109,7 @@ private void BackupDatabase()
using (var unitOfWork = new UnitOfWork(() => _maindDb.GetDataMapper()))
{
unitOfWork.BeginTransaction();
unitOfWork.BeginTransaction(IsolationLevel.Serializable);
var databaseFile = _appFolderInfo.GetNzbDroneDatabase();
var tempDatabaseFile = Path.Combine(_backupTempFolder, Path.GetFileName(databaseFile));

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using Marr.Data;
@ -145,7 +146,7 @@ public void InsertMany(IList<TModel> models)
{
using (var unitOfWork = new UnitOfWork(() => DataMapper))
{
unitOfWork.BeginTransaction();
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
foreach (var model in models)
{
@ -160,7 +161,7 @@ public void UpdateMany(IList<TModel> models)
{
using (var unitOfWork = new UnitOfWork(() => DataMapper))
{
unitOfWork.BeginTransaction();
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
foreach (var model in models)
{
@ -203,7 +204,7 @@ public void DeleteMany(IEnumerable<int> ids)
{
using (var unitOfWork = new UnitOfWork(() => DataMapper))
{
unitOfWork.BeginTransaction();
unitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
foreach (var id in ids)
{

View File

@ -1,4 +1,5 @@
using System.Reflection;
using System.Diagnostics;
using System.Reflection;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Initialization;
using FluentMigrator.Runner.Processors.SQLite;
@ -21,6 +22,8 @@ public MigrationController(IAnnouncer announcer)
public void MigrateToLatest(string connectionString, MigrationType migrationType)
{
var sw = Stopwatch.StartNew();
_announcer.Heading("Migrating " + connectionString);
var assembly = Assembly.GetExecutingAssembly();
@ -39,6 +42,10 @@ public void MigrateToLatest(string connectionString, MigrationType migrationType
var processor = factory.Create(connectionString, _announcer, options);
var runner = new MigrationRunner(assembly, migrationContext, processor);
runner.MigrateUp(true);
sw.Stop();
_announcer.ElapsedTime(sw.Elapsed);
}
}
}

View File

@ -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;
}
}
}

View File

@ -37,6 +37,7 @@ public void Sql(string sql)
public void ElapsedTime(TimeSpan timeSpan)
{
_logger.Debug("Took: {0}", timeSpan);
}
public void Error(string message)

View File

@ -10,7 +10,7 @@ public class NzbDroneSqliteProcessorFactory : SqliteProcessorFactory
{
public override IMigrationProcessor Create(String connectionString, IAnnouncer announcer, IMigrationProcessorOptions options)
{
var factory = new SqliteDbFactory();
var factory = new MigrationDbFactory();
var connection = factory.CreateConnection(connectionString);
var generator = new SqliteGenerator() { compatabilityMode = CompatabilityMode.STRICT };
return new NzbDroneSqliteProcessor(connection, generator, announcer, options, factory);

View File

@ -22,7 +22,8 @@ public class DatabaseTarget : TargetWithLayout, IHandle<ApplicationShutdownReque
public DatabaseTarget(IConnectionStringFactory connectionStringFactory)
{
_connection = new SQLiteConnection(connectionStringFactory.LogDbConnectionString).OpenAndReturn();
_connection = new SQLiteConnection(connectionStringFactory.LogDbConnectionString);
_connection.Open();
}
public void Register()

View File

@ -230,6 +230,7 @@
<Compile Include="Datastore\Migration\067_add_added_to_series.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.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\MigrationLogger.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationOptions.cs" />