Browse Source

No parallel updates when in transaction. (#915)

* No parallel updates when in transaction.

* Option for clustering.
pull/914/head
Sebastian Stehle 3 years ago
committed by GitHub
parent
commit
2b4c60fe6b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  2. 5
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs
  3. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/ContentOptions.cs
  4. 5
      backend/src/Squidex/appsettings.json

7
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -26,6 +26,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{
private readonly MongoContentCollection collectionComplete;
private readonly MongoContentCollection collectionPublished;
private readonly ContentOptions options;
private readonly IMongoDatabase database;
private readonly IAppProvider appProvider;
@ -42,7 +43,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider,
IOptions<ContentOptions> options)
{
this.appProvider = appProvider;
this.database = database;
this.options = options.Value;
collectionComplete =
new MongoContentCollection("States_Contents_All3", database,
@ -51,8 +54,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
collectionPublished =
new MongoContentCollection("States_Contents_Published3", database,
ReadPreference.Secondary, options.Value.OptimizeForSelfHosting);
this.appProvider = appProvider;
}
public async Task InitializeAsync(
@ -64,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
var clusterVersion = await database.GetMajorVersionAsync(ct);
var clusteredAsReplica = database.Client.Cluster.Description.Type == ClusterType.ReplicaSet;
CanUseTransactions = clusteredAsReplica && clusterVersion >= 4;
CanUseTransactions = clusteredAsReplica && clusterVersion >= 4 && options.UseTransactions;
}
public IAsyncEnumerable<IContentEntity> StreamAll(DomainId appId, HashSet<DomainId>? schemaIds,

5
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs

@ -106,9 +106,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
// Make an update with full transaction support to be more consistent.
await session.WithTransactionAsync(async (session, ct) =>
{
await Task.WhenAll(
UpsertVersionedCompleteAsync(session, job, ct),
UpsertVersionedPublishedAsync(session, job, ct));
await UpsertVersionedCompleteAsync(session, job, ct);
await UpsertVersionedPublishedAsync(session, job, ct);
return true;
}, null, ct);
}

2
backend/src/Squidex.Domain.Apps.Entities/Contents/ContentOptions.cs

@ -13,6 +13,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
public bool OptimizeForSelfHosting { get; set; }
public bool UseTransactions { get; set; }
public int DefaultPageSize { get; set; } = 200;
public int MaxResults { get; set; } = 200;

5
backend/src/Squidex/appsettings.json

@ -234,6 +234,11 @@
// Creates one database per app and one collection per schema. Slows down inserts, but you can create custom indexes.
"optimizeForSelfHosting": false,
// False to not use transactions. Improves performance.
//
// Warning: Can cause consistency issues.
"useTransactions": true,
// The default page size if not specified by a query.
//
// Warning: Can slow down queries if increased.

Loading…
Cancel
Save