Skip to content

Commit

Permalink
Trying to improve errors handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mimetis committed Nov 28, 2022
1 parent 785bfd9 commit 3748fd4
Show file tree
Hide file tree
Showing 36 changed files with 2,917 additions and 1,953 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ApplyChangesConflictOccuredArgs : ProgressArgs
public async Task<SyncConflict> GetSyncConflictAsync()
{
var (_, localRow) = await orchestrator.InternalGetConflictRowAsync(scopeInfo, Context, schemaChangesTable, conflictRow, this.Connection, this.Transaction).ConfigureAwait(false);
this.conflict = orchestrator.InternalGetConflict(conflictRow, localRow);
this.conflict = orchestrator.InternalGetConflict(Context, conflictRow, localRow);
return conflict;
}

Expand Down
1 change: 0 additions & 1 deletion Projects/Dotmim.Sync.Core/Args/TableChangesApplyArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public static partial class InterceptorsExtensions
/// {
/// Console.WriteLine($"Changes for table
/// {args.SchemaTable.GetFullName()}. Rows:{syncTable.Rows.Count}");

/// foreach (var row in syncTable.Rows)
/// Console.WriteLine(row);
/// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ internal virtual async Task InternalApplyCleanErrorsAsync(ScopeInfo scopeInfo, S
{
if (lastSyncErrorsBatchInfo == null)
return;
try
{
context.SyncStage = SyncStage.ChangesApplying;

context.SyncStage = SyncStage.ChangesApplying;

var schemaTables = message.Schema.Tables.SortByDependencies(tab => tab.GetRelations().Select(r => r.GetParentTable()));
var schemaTables = message.Schema.Tables.SortByDependencies(tab => tab.GetRelations().Select(r => r.GetParentTable()));

this.Logger.LogInformation($@"[InternalApplyCleanErrorsAsync]. Directory name {{directoryName}}. BatchParts count {{BatchPartsInfoCount}}", lastSyncErrorsBatchInfo.DirectoryName, lastSyncErrorsBatchInfo.BatchPartsInfo.Count);
this.Logger.LogInformation($@"[InternalApplyCleanErrorsAsync]. Directory name {{directoryName}}. BatchParts count {{BatchPartsInfoCount}}", lastSyncErrorsBatchInfo.DirectoryName, lastSyncErrorsBatchInfo.BatchPartsInfo.Count);

try
{
foreach (var schemaTable in schemaTables)
{
var tableChangesApplied = message.ChangesApplied?.TableChangesApplied?.FirstOrDefault(tca =>
Expand All @@ -50,7 +49,6 @@ internal virtual async Task InternalApplyCleanErrorsAsync(ScopeInfo scopeInfo, S
sn.Equals(otherSn, sc);
});


// tmp sync table with only writable columns
var changesSet = schemaTable.Schema.Clone(false);
var schemaChangesTable = CreateChangesTable(schemaTable, changesSet);
Expand Down Expand Up @@ -159,7 +157,6 @@ internal virtual async Task<Exception>
if (!string.IsNullOrEmpty(message.BatchDirectory) && !Directory.Exists(message.BatchDirectory))
Directory.CreateDirectory(message.BatchDirectory);


// Disable check constraints
// Because Sqlite does not support "PRAGMA foreign_keys=OFF" Inside a transaction
// Report this disabling constraints brefore opening a transaction
Expand Down Expand Up @@ -357,7 +354,6 @@ internal virtual async Task<Exception> InternalApplyTableChangesAsync(ScopeInfo

try
{

foreach (var batchPartInfo in bpiTables)
{
var batchChangesApplyingArgs = new BatchChangesApplyingArgs(context, message.Changes, batchPartInfo, schemaTable, applyType, command, connection, transaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -29,7 +31,8 @@ public partial class LocalOrchestrator : BaseOrchestrator
internal virtual async Task<(SyncContext context, ClientSyncChanges clientSyncChange, ScopeInfoClient CScopeInfoClient)>
InternalApplyChangesAsync(ScopeInfo cScopeInfo, ScopeInfoClient cScopeInfoClient, SyncContext context, ServerSyncChanges serverSyncChanges,
ClientSyncChanges clientSyncChanges, ConflictResolutionPolicy policy, bool snapshotApplied,
DbConnection connection = default, DbTransaction transaction = default, CancellationToken cancellationToken = default, IProgress<ProgressArgs> progress = null)
DbConnection connection = default, DbTransaction transaction = default,
CancellationToken cancellationToken = default, IProgress<ProgressArgs> progress = null)
{
// Connection & Transaction runner
DbConnectionRunner runner = null;
Expand Down Expand Up @@ -103,15 +106,13 @@ public partial class LocalOrchestrator : BaseOrchestrator
if (failureException != null)
throw failureException;


if (serverBatchInfo != null && serverBatchInfo.HasData())
{
// Call apply changes on provider
applyChanges.Changes = serverBatchInfo;
failureException = await this.InternalApplyChangesAsync(cScopeInfo, context, applyChanges, connection, transaction, cancellationToken, progress).ConfigureAwait(false);
}


if (failureException != null)
throw failureException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ public partial class RemoteOrchestrator : BaseOrchestrator
await runner.CommitAsync().ConfigureAwait(false);

}
catch (Exception)
catch (Exception ex)
{
if (runner != null)
{
await runner.RollbackAsync().ConfigureAwait(false);
await runner.DisposeAsync().ConfigureAwait(false);
}
throw;
throw GetSyncError(context, ex);
}

try
Expand Down Expand Up @@ -263,11 +263,12 @@ public partial class RemoteOrchestrator : BaseOrchestrator

return (context, serverSyncChanges, this.Options.ConflictResolutionPolicy);
}
catch (Exception)
catch (Exception ex)
{
if (runner != null)
await runner.RollbackAsync().ConfigureAwait(false);
throw;

throw GetSyncError(context, ex);
}
finally
{
Expand Down
Loading

0 comments on commit 3748fd4

Please sign in to comment.