mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:43:05 +08:00
Don't start transactions for migration
It looks like transactions are used internally during migration.
This commit is contained in:
parent
a3287b8cf2
commit
80806be047
@ -41,17 +41,18 @@ namespace osu.Game.Database
|
||||
/// Request a context for write usage. Can be consumed in a nested fashion (and will return the same underlying context).
|
||||
/// This method may block if a write is already active on a different thread.
|
||||
/// </summary>
|
||||
/// <param name="withTransaction">Whether to start a transaction for this write.</param>
|
||||
/// <returns>A usage containing a usable context.</returns>
|
||||
public DatabaseWriteUsage GetForWrite()
|
||||
public DatabaseWriteUsage GetForWrite(bool withTransaction = true)
|
||||
{
|
||||
Monitor.Enter(writeLock);
|
||||
|
||||
if (currentWriteTransaction == null)
|
||||
if (currentWriteTransaction == null && withTransaction)
|
||||
currentWriteTransaction = threadContexts.Value.Database.BeginTransaction();
|
||||
|
||||
Interlocked.Increment(ref currentWriteUsages);
|
||||
|
||||
return new DatabaseWriteUsage(threadContexts.Value, usageCompleted) { IsTransactionLeader = currentWriteUsages == 1 };
|
||||
return new DatabaseWriteUsage(threadContexts.Value, usageCompleted) { IsTransactionLeader = currentWriteTransaction != null && currentWriteUsages == 1 };
|
||||
}
|
||||
|
||||
private void usageCompleted(DatabaseWriteUsage usage)
|
||||
@ -66,9 +67,9 @@ namespace osu.Game.Database
|
||||
if (usages > 0) return;
|
||||
|
||||
if (currentWriteDidError)
|
||||
currentWriteTransaction.Rollback();
|
||||
currentWriteTransaction?.Rollback();
|
||||
else
|
||||
currentWriteTransaction.Commit();
|
||||
currentWriteTransaction?.Commit();
|
||||
|
||||
currentWriteTransaction = null;
|
||||
currentWriteDidWrite = false;
|
||||
|
@ -14,7 +14,8 @@ namespace osu.Game.Database
|
||||
/// Request a context for write usage. Can be consumed in a nested fashion (and will return the same underlying context).
|
||||
/// This method may block if a write is already active on a different thread.
|
||||
/// </summary>
|
||||
/// <param name="withTransaction">Whether to start a transaction for this write.</param>
|
||||
/// <returns>A usage containing a usable context.</returns>
|
||||
DatabaseWriteUsage GetForWrite();
|
||||
DatabaseWriteUsage GetForWrite(bool withTransaction = true);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ namespace osu.Game.Database
|
||||
|
||||
public OsuDbContext Get() => context;
|
||||
|
||||
public DatabaseWriteUsage GetForWrite() => new DatabaseWriteUsage(context, null);
|
||||
public DatabaseWriteUsage GetForWrite(bool withTransaction = true) => new DatabaseWriteUsage(context, null);
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ namespace osu.Game
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var db = contextFactory.GetForWrite())
|
||||
using (var db = contextFactory.GetForWrite(false))
|
||||
db.Context.Migrate();
|
||||
}
|
||||
catch (MigrationFailedException e)
|
||||
@ -220,7 +220,7 @@ namespace osu.Game
|
||||
contextFactory.ResetDatabase();
|
||||
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
|
||||
|
||||
using (var db = contextFactory.GetForWrite())
|
||||
using (var db = contextFactory.GetForWrite(false))
|
||||
db.Context.Migrate();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user