Skip to content

Commit

Permalink
improve: remove useless code and upgrade dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
catcherwong committed Apr 9, 2022
1 parent aef4a2e commit ff01961
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
20 changes: 1 addition & 19 deletions src/DtmCommon/Barrier/BranchBarrier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ public async Task Call(DbConnection db, Func<DbTransaction, Task> busiCall)
// check the connection state
if (db.State != System.Data.ConnectionState.Open) await db.OpenAsync();

// All should using async method, but netstandard2.0 do not support.
#if NETSTANDARD2_0
var tx = db.BeginTransaction();
#else
var tx = await db.BeginTransactionAsync();
#endif

try
{
Expand All @@ -72,39 +67,26 @@ public async Task Call(DbConnection db, Func<DbTransaction, Task> busiCall)
if (isNullCompensation || isDuplicateOrPend)
{
Logger?.LogInformation("Will not exec busiCall, isNullCompensation={isNullCompensation}, isDuplicateOrPend={isDuplicateOrPend}", isNullCompensation, isDuplicateOrPend);
#if NETSTANDARD2_0
tx.Commit();
#else
await tx.CommitAsync();
#endif

return;
}

try
{
await busiCall.Invoke(tx);
}
catch
catch
{
throw;
}

#if NETSTANDARD2_0
tx.Commit();
#else
await tx.CommitAsync();
#endif
}
catch (Exception ex)
{
Logger?.LogError(ex, "Call error, gid={gid}, trans_type={trans_type}", this.Gid, this.TransType);

#if NETSTANDARD2_0
tx.Rollback();
#else
await tx.RollbackAsync();
#endif

throw;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DtmCommon/DtmCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RepositoryUrl>https://github.com/catcherwong/dtmgrpc-csharp</RepositoryUrl>
<Description>a c# client for distributed transaction framework dtm. 分布式事务管理器dtm的c#客户端</Description>
<PackageTags>dtm,csharp,distributed transaction,tcc,saga,msg</PackageTags>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>catcherwong</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand Down
4 changes: 2 additions & 2 deletions src/DtmSERedisBarrier/DtmSERedisBarrier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<RepositoryUrl>https://github.com/catcherwong/dtmgrpc-csharp</RepositoryUrl>
<Description>a c# client for distributed transaction framework dtm. 分布式事务管理器dtm的c#客户端</Description>
<PackageTags>dtm,csharp,distributed transaction,tcc,saga,msg</PackageTags>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>catcherwong</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.2.88" />
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Dtmgrpc/Dtmgrpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RepositoryUrl>https://github.com/catcherwong/dtmgrpc-csharp</RepositoryUrl>
<Description>a c# client for distributed transaction framework dtm. 分布式事务管理器dtm的c#客户端</Description>
<PackageTags>dtm,csharp,distributed transaction,tcc,saga,msg</PackageTags>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>catcherwong</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -22,9 +22,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.19.4" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.42.0" />
<PackageReference Include="Grpc.Tools" Version="2.43.0">
<PackageReference Include="Google.Protobuf" Version="3.20.0" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.44.0" />
<PackageReference Include="Grpc.Tools" Version="2.45.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/Dtmgrpc/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ private static IServiceCollection AddDtmGrpcCore(IServiceCollection services)
services.TryAddSingleton<Driver.IDtmDriver, Driver.DefaultDtmDriver>();

// trans releate
services.AddSingleton<IDtmTransFactory, DtmTransFactory>();
services.AddSingleton<IDtmgRPCClient, DtmgRPCClient>();
services.AddSingleton<TccGlobalTransaction>();
services.TryAddSingleton<IDtmTransFactory, DtmTransFactory>();
services.TryAddSingleton<IDtmgRPCClient, DtmgRPCClient>();
services.TryAddSingleton<TccGlobalTransaction>();

DtmCommon.ServiceCollectionExtensions.AddDtmCommon(services);

// barrier factory
services.AddSingleton<IBranchBarrierFactory, DefaultBranchBarrierFactory>();
services.TryAddSingleton<IBranchBarrierFactory, DefaultBranchBarrierFactory>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -27,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.19.4" />
<PackageReference Include="Grpc.Tools" Version="2.43.0">
<PackageReference Include="Google.Protobuf" Version="3.20.0" />
<PackageReference Include="Grpc.Tools" Version="2.45.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit ff01961

Please sign in to comment.