Skip to content

Commit cccad02

Browse files
Ticket #307 :
Remove Distributed lock Enable MARS
1 parent be2708b commit cccad02

14 files changed

Lines changed: 46 additions & 149 deletions

File tree

SimpleIdServer.Scim.Host.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.Persist
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.MongoDb.Startup", "src\Scim\SimpleIdServer.Scim.MongoDb.Startup\SimpleIdServer.Scim.MongoDb.Startup.csproj", "{FB7F6266-9813-4D71-9CB1-4C1872442795}"
2929
EndProject
30-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.SqlServer", "src\Scim\SimpleIdServer.Scim.SqlServer\SimpleIdServer.Scim.SqlServer.csproj", "{025D5A4C-BEA5-4132-817D-BA1C57072625}"
31-
EndProject
3230
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.Swashbuckle", "src\Scim\SimpleIdServer.Scim.Swashbuckle\SimpleIdServer.Scim.Swashbuckle.csproj", "{A8244272-C4D7-42F3-8316-A118D34399B9}"
3331
EndProject
3432
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleIdServer.Scim.Provisioning", "src\Scim\SimpleIdServer.Scim.Provisioning\SimpleIdServer.Scim.Provisioning.csproj", "{8F077A30-41F5-43B2-9D1F-631D6FA5D0E3}"
@@ -101,10 +99,6 @@ Global
10199
{FB7F6266-9813-4D71-9CB1-4C1872442795}.Debug|Any CPU.Build.0 = Debug|Any CPU
102100
{FB7F6266-9813-4D71-9CB1-4C1872442795}.Release|Any CPU.ActiveCfg = Release|Any CPU
103101
{FB7F6266-9813-4D71-9CB1-4C1872442795}.Release|Any CPU.Build.0 = Release|Any CPU
104-
{025D5A4C-BEA5-4132-817D-BA1C57072625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
105-
{025D5A4C-BEA5-4132-817D-BA1C57072625}.Debug|Any CPU.Build.0 = Debug|Any CPU
106-
{025D5A4C-BEA5-4132-817D-BA1C57072625}.Release|Any CPU.ActiveCfg = Release|Any CPU
107-
{025D5A4C-BEA5-4132-817D-BA1C57072625}.Release|Any CPU.Build.0 = Release|Any CPU
108102
{A8244272-C4D7-42F3-8316-A118D34399B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
109103
{A8244272-C4D7-42F3-8316-A118D34399B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
110104
{A8244272-C4D7-42F3-8316-A118D34399B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -167,7 +161,6 @@ Global
167161
{5AE1ACD1-5129-4D01-B8FB-496395048EAF} = {32DF2B02-EE73-4928-AA1F-9E74F1573B24}
168162
{02A2B0B2-3328-4340-8E20-06256544935E} = {E47E7F9F-C5CA-4459-AF46-F320F155B69E}
169163
{FB7F6266-9813-4D71-9CB1-4C1872442795} = {32DF2B02-EE73-4928-AA1F-9E74F1573B24}
170-
{025D5A4C-BEA5-4132-817D-BA1C57072625} = {E47E7F9F-C5CA-4459-AF46-F320F155B69E}
171164
{A8244272-C4D7-42F3-8316-A118D34399B9} = {E47E7F9F-C5CA-4459-AF46-F320F155B69E}
172165
{8F077A30-41F5-43B2-9D1F-631D6FA5D0E3} = {011E8E6E-5B36-4E0C-A4AE-FF7B11579380}
173166
{32DF2B02-EE73-4928-AA1F-9E74F1573B24} = {011E8E6E-5B36-4E0C-A4AE-FF7B11579380}

default.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ task pack -depends release, compile {
8383
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim.Persistence.EF\SimpleIdServer.Scim.Persistence.EF.csproj -c $config --no-build $versionSuffix --output $result_dir }
8484
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim\SimpleIdServer.Scim.csproj -c $config --no-build $versionSuffix --output $result_dir }
8585
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim.Persistence.MongoDB\SimpleIdServer.Scim.Persistence.MongoDB.csproj -c $config --no-build $versionSuffix --output $result_dir }
86-
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim.SqlServer\SimpleIdServer.Scim.SqlServer.csproj -c $config --no-build $versionSuffix --output $result_dir }
8786
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim.Swashbuckle\SimpleIdServer.Scim.Swashbuckle.csproj -c $config --no-build $versionSuffix --output $result_dir }
8887
exec { dotnet pack $source_dir\Scim\SimpleIdServer.Scim.SwashbuckleV6\SimpleIdServer.Scim.SwashbuckleV6.csproj -c $config --no-build $versionSuffix --output $result_dir }
8988
exec { dotnet pack $source_dir\Scim\dotnet6\SimpleIdServer.Scim.Persistence.EFNet6\SimpleIdServer.Scim.Persistence.EFNet6.csproj -c $config --no-build $versionSuffix --output $result_dir }

src/Scim/SimpleIdServer.Scim.Benchmark/ScimBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace SimpleIdServer.Scim.Benchmark
1717
[RPlotExporter]
1818
public class ScimBenchmark
1919
{
20-
private const string baseUrl = "http://localhost:60002";
20+
private const string baseUrl = "http://localhost:5002";
2121
private string _groupId;
2222

23-
// [Benchmark]
23+
[Benchmark]
2424
public async Task AddUserToGroup()
2525
{
2626
using (var httpClient = new HttpClient())

src/Scim/SimpleIdServer.Scim.SqlServer.Startup/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void Main(string[] args)
1212
var host = Host.CreateDefaultBuilder(args)
1313
.ConfigureWebHostDefaults((cfg) =>
1414
{
15-
cfg.UseUrls("http://*:60002");
15+
cfg.UseUrls("http://*:5002");
1616
cfg.UseStartup<Startup>();
1717
})
1818
.Build();

src/Scim/SimpleIdServer.Scim.SqlServer.Startup/SimpleIdServer.Scim.SqlServer.Startup.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<ItemGroup>
1717
<ProjectReference Include="..\..\OAuth\SimpleIdServer.Jwt\SimpleIdServer.Jwt.csproj" />
1818
<ProjectReference Include="..\SimpleIdServer.Scim.Persistence.EF\SimpleIdServer.Scim.Persistence.EF.csproj" />
19-
<ProjectReference Include="..\SimpleIdServer.Scim.SqlServer\SimpleIdServer.Scim.SqlServer.csproj" />
2019
<ProjectReference Include="..\SimpleIdServer.Scim\SimpleIdServer.Scim.csproj" />
2120
</ItemGroup>
2221
<ItemGroup>

src/Scim/SimpleIdServer.Scim.SqlServer.Startup/Startup.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public void ConfigureServices(IServiceCollection services)
7878
});
7979
services.AddScimStoreEF(options =>
8080
{
81-
options.UseSqlServer(Configuration.GetConnectionString("db"), o => o.MigrationsAssembly(migrationsAssembly));
82-
});
83-
services.AddDistributedLockSQLServer(opts =>
84-
{
85-
opts.ConnectionString = Configuration.GetConnectionString("db");
81+
options.UseSqlServer(Configuration.GetConnectionString("db"), o =>
82+
{
83+
o.MigrationsAssembly(migrationsAssembly);
84+
o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
85+
});
8686
});
8787
}
8888

src/Scim/SimpleIdServer.Scim.SqlServer.Startup/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ConnectionStrings": {
3-
"db": "Data Source=THABART;Initial Catalog=SCIM;Integrated Security=True"
3+
"db": "Data Source=THABART;Initial Catalog=SCIM;Integrated Security=True; MultipleActiveResultSets=True"
44
},
55
"Logging": {
66
"LogLevel": {

src/Scim/SimpleIdServer.Scim/Commands/Handlers/PatchRepresentationCommandHandler.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
using SimpleIdServer.Scim.DTOs;
88
using SimpleIdServer.Scim.Exceptions;
99
using SimpleIdServer.Scim.Helpers;
10-
using SimpleIdServer.Scim.Infrastructure.Lock;
1110
using SimpleIdServer.Scim.Persistence;
1211
using SimpleIdServer.Scim.Resources;
1312
using System;
1413
using System.Collections.Generic;
1514
using System.Linq;
16-
using System.Threading;
1715
using System.Threading.Tasks;
1816

1917
namespace SimpleIdServer.Scim.Commands.Handlers
@@ -23,42 +21,30 @@ public class PatchRepresentationCommandHandler : BaseCommandHandler, IPatchRepre
2321
private readonly ISCIMAttributeMappingQueryRepository _scimAttributeMappingQueryRepository;
2422
private readonly ISCIMRepresentationQueryRepository _scimRepresentationQueryRepository;
2523
private readonly ISCIMRepresentationCommandRepository _scimRepresentationCommandRepository;
26-
private readonly IDistributedLock _distributedLock;
2724
private readonly IRepresentationReferenceSync _representationReferenceSync;
2825
private readonly SCIMHostOptions _options;
2926

3027
public PatchRepresentationCommandHandler(
3128
ISCIMAttributeMappingQueryRepository scimAttributeMappingQueryRepository,
3229
ISCIMRepresentationQueryRepository scimRepresentationQueryRepository,
3330
ISCIMRepresentationCommandRepository scimRepresentationCommandRepository,
34-
IDistributedLock distributedLock,
3531
IRepresentationReferenceSync representationReferenceSync,
3632
IOptions<SCIMHostOptions> options,
3733
IBusControl busControl) : base(busControl)
3834
{
3935
_scimAttributeMappingQueryRepository = scimAttributeMappingQueryRepository;
4036
_scimRepresentationQueryRepository = scimRepresentationQueryRepository;
4137
_scimRepresentationCommandRepository = scimRepresentationCommandRepository;
42-
_distributedLock = distributedLock;
4338
_representationReferenceSync = representationReferenceSync;
4439
_options = options.Value;
4540
}
4641

4742
public async Task<PatchRepresentationResult> Handle(PatchRepresentationCommand patchRepresentationCommand)
4843
{
4944
CheckParameter(patchRepresentationCommand.PatchRepresentation);
50-
var lockName = $"representation-{patchRepresentationCommand.Id}";
51-
await _distributedLock.WaitLock(lockName, CancellationToken.None);
52-
try
53-
{
54-
var existingRepresentation = await _scimRepresentationQueryRepository.FindSCIMRepresentationById(patchRepresentationCommand.Id);
55-
if (existingRepresentation == null) throw new SCIMNotFoundException(string.Format(Global.ResourceNotFound, patchRepresentationCommand.Id));
56-
return await UpdateRepresentation(existingRepresentation, patchRepresentationCommand);
57-
}
58-
finally
59-
{
60-
await _distributedLock.ReleaseLock(lockName, CancellationToken.None);
61-
}
45+
var existingRepresentation = await _scimRepresentationQueryRepository.FindSCIMRepresentationById(patchRepresentationCommand.Id);
46+
if (existingRepresentation == null) throw new SCIMNotFoundException(string.Format(Global.ResourceNotFound, patchRepresentationCommand.Id));
47+
return await UpdateRepresentation(existingRepresentation, patchRepresentationCommand);
6248
}
6349

6450
private async Task<PatchRepresentationResult> UpdateRepresentation(SCIMRepresentation existingRepresentation, PatchRepresentationCommand patchRepresentationCommand)

src/Scim/SimpleIdServer.Scim/Commands/Handlers/ReplaceRepresentationCommandHandler.cs

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
using SimpleIdServer.Scim.Exceptions;
77
using SimpleIdServer.Scim.Extensions;
88
using SimpleIdServer.Scim.Helpers;
9-
using SimpleIdServer.Scim.Infrastructure.Lock;
109
using SimpleIdServer.Scim.Persistence;
1110
using SimpleIdServer.Scim.Resources;
1211
using System;
1312
using System.Collections.Generic;
1413
using System.Linq;
15-
using System.Threading;
1614
using System.Threading.Tasks;
1715

1816
namespace SimpleIdServer.Scim.Commands.Handlers
@@ -24,23 +22,20 @@ public class ReplaceRepresentationCommandHandler : BaseCommandHandler, IReplaceR
2422
private readonly ISCIMRepresentationHelper _scimRepresentationHelper;
2523
private readonly ISCIMRepresentationCommandRepository _scimRepresentationCommandRepository;
2624
private readonly IRepresentationReferenceSync _representationReferenceSync;
27-
private readonly IDistributedLock _distributedLock;
2825

2926
public ReplaceRepresentationCommandHandler(
3027
ISCIMAttributeMappingQueryRepository scimAttributeMappingQueryRepository,
3128
ISCIMSchemaQueryRepository scimSchemaQueryRepository,
3229
ISCIMRepresentationHelper scimRepresentationHelper,
3330
ISCIMRepresentationCommandRepository scimRepresentationCommandRepository,
3431
IRepresentationReferenceSync representationReferenceSync,
35-
IDistributedLock distributedLock,
3632
IBusControl busControl) : base(busControl)
3733
{
3834
_scimAttributeMappingQueryRepository = scimAttributeMappingQueryRepository;
3935
_scimSchemaQueryRepository = scimSchemaQueryRepository;
4036
_scimRepresentationHelper = scimRepresentationHelper;
4137
_scimRepresentationCommandRepository = scimRepresentationCommandRepository;
4238
_representationReferenceSync = representationReferenceSync;
43-
_distributedLock = distributedLock;
4439
}
4540

4641
public async Task<SCIMRepresentation> Handle(ReplaceRepresentationCommand replaceRepresentationCommand)
@@ -61,49 +56,40 @@ public async Task<SCIMRepresentation> Handle(ReplaceRepresentationCommand replac
6156
}
6257

6358
var schemas = await _scimSchemaQueryRepository.FindSCIMSchemaByIdentifiers(requestedSchemas);
64-
var lockName = $"representation-{replaceRepresentationCommand.Id}";
65-
await _distributedLock.WaitLock(lockName, CancellationToken.None);
66-
try
59+
var existingRepresentation = await _scimRepresentationCommandRepository.Get(replaceRepresentationCommand.Id);
60+
if (existingRepresentation == null)
6761
{
68-
var existingRepresentation = await _scimRepresentationCommandRepository.Get(replaceRepresentationCommand.Id);
69-
if (existingRepresentation == null)
70-
{
71-
throw new SCIMNotFoundException(string.Format(Global.ResourceNotFound, replaceRepresentationCommand.Id));
72-
}
62+
throw new SCIMNotFoundException(string.Format(Global.ResourceNotFound, replaceRepresentationCommand.Id));
63+
}
7364

74-
var oldRepresentation = (SCIMRepresentation)existingRepresentation.Clone();
75-
var mainSchema = schemas.First(s => s.Id == schema.Id);
76-
var extensionSchemas = schemas.Where(s => s.Id != schema.Id).ToList();
77-
var updatedRepresentation = _scimRepresentationHelper.ExtractSCIMRepresentationFromJSON(
78-
replaceRepresentationCommand.Representation.Attributes,
79-
replaceRepresentationCommand.Representation.ExternalId,
80-
mainSchema,
81-
extensionSchemas);
82-
var updateResult = await UpdateExistingRepresentation(replaceRepresentationCommand.ResourceType, existingRepresentation, updatedRepresentation);
83-
existingRepresentation.SetDisplayName(updatedRepresentation.DisplayName);
84-
existingRepresentation.SetExternalId(updatedRepresentation.ExternalId);
85-
existingRepresentation.SetUpdated(DateTime.UtcNow);
86-
var isReferenceProperty = await _representationReferenceSync.IsReferenceProperty(replaceRepresentationCommand.Representation.Attributes.GetKeys());
87-
var references = await _representationReferenceSync.Sync(updateResult.AttributeMappingLst, replaceRepresentationCommand.ResourceType, oldRepresentation, existingRepresentation, replaceRepresentationCommand.Location, !isReferenceProperty);
88-
using (var transaction = await _scimRepresentationCommandRepository.StartTransaction())
65+
var oldRepresentation = (SCIMRepresentation)existingRepresentation.Clone();
66+
var mainSchema = schemas.First(s => s.Id == schema.Id);
67+
var extensionSchemas = schemas.Where(s => s.Id != schema.Id).ToList();
68+
var updatedRepresentation = _scimRepresentationHelper.ExtractSCIMRepresentationFromJSON(
69+
replaceRepresentationCommand.Representation.Attributes,
70+
replaceRepresentationCommand.Representation.ExternalId,
71+
mainSchema,
72+
extensionSchemas);
73+
var updateResult = await UpdateExistingRepresentation(replaceRepresentationCommand.ResourceType, existingRepresentation, updatedRepresentation);
74+
existingRepresentation.SetDisplayName(updatedRepresentation.DisplayName);
75+
existingRepresentation.SetExternalId(updatedRepresentation.ExternalId);
76+
existingRepresentation.SetUpdated(DateTime.UtcNow);
77+
var isReferenceProperty = await _representationReferenceSync.IsReferenceProperty(replaceRepresentationCommand.Representation.Attributes.GetKeys());
78+
var references = await _representationReferenceSync.Sync(updateResult.AttributeMappingLst, replaceRepresentationCommand.ResourceType, oldRepresentation, existingRepresentation, replaceRepresentationCommand.Location, !isReferenceProperty);
79+
using (var transaction = await _scimRepresentationCommandRepository.StartTransaction())
80+
{
81+
await _scimRepresentationCommandRepository.Update(existingRepresentation);
82+
foreach (var reference in references.Representations)
8983
{
90-
await _scimRepresentationCommandRepository.Update(existingRepresentation);
91-
foreach (var reference in references.Representations)
92-
{
93-
await _scimRepresentationCommandRepository.Update(reference);
94-
}
95-
96-
await transaction.Commit();
84+
await _scimRepresentationCommandRepository.Update(reference);
9785
}
9886

99-
await Notify(references);
100-
existingRepresentation.ApplyEmptyArray();
101-
return existingRepresentation;
102-
}
103-
finally
104-
{
105-
await _distributedLock.ReleaseLock(lockName, CancellationToken.None);
87+
await transaction.Commit();
10688
}
89+
90+
await Notify(references);
91+
existingRepresentation.ApplyEmptyArray();
92+
return existingRepresentation;
10793
}
10894

10995
private async Task<UpdateRepresentationResult> UpdateExistingRepresentation(string resourceType, SCIMRepresentation existingRepresentation, SCIMRepresentation updatedRepresentation)

src/Scim/SimpleIdServer.Scim/Infrastructure/Lock/IDistributedLock.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)