Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<bool> UpsertRow(string deploymentId, MembershipEntry entry, st
using var session = await Client.StartSessionAsync();
return await session.WithTransactionAsync(async (sessionHandle, ct) =>
{
var hasUpsertedTable = await tableVersionCollection.UpsertAsync(session, tableVersion, deploymentId);
var hasUpsertedTable = await tableVersionCollection.UpsertAsync(sessionHandle, tableVersion, deploymentId);

if (!hasUpsertedTable)
{
Expand Down Expand Up @@ -106,10 +106,10 @@ public async Task<MembershipTableData> ReadAll(string deploymentId)
using var session = await Client.StartSessionAsync();
return await session.WithTransactionAsync(async (sessionHandle, ct) =>
{
var tableVersion = tableVersionCollection.GetTableVersionAsync(deploymentId);
var tableVersion = tableVersionCollection.GetTableVersionAsync(sessionHandle, deploymentId);

var entries =
Collection.Find(x => x.DeploymentId == deploymentId)
Collection.Find(sessionHandle, x => x.DeploymentId == deploymentId)
.ToListAsync(cancellationToken: ct);

await Task.WhenAll(tableVersion, entries);
Expand All @@ -123,12 +123,12 @@ public async Task<MembershipTableData> ReadRow(string deploymentId, SiloAddress
using var session = await Client.StartSessionAsync();
return await session.WithTransactionAsync(async (sessionHandle, ct) =>
{
var tableVersion = tableVersionCollection.GetTableVersionAsync(deploymentId);
var tableVersion = tableVersionCollection.GetTableVersionAsync(sessionHandle, deploymentId);

var id = ReturnId(deploymentId, address);

var entries =
Collection.Find(x => x.Id == id)
Collection.Find(sessionHandle, x => x.Id == id)
.ToListAsync(cancellationToken: ct);

await Task.WhenAll(tableVersion, entries);
Expand All @@ -151,12 +151,19 @@ public Task CleanupDefunctSiloEntries(string deploymentId, DateTimeOffset before
return Collection.DeleteManyAsync(x => x.DeploymentId == deploymentId && x.Status != (int)SiloStatus.Active && x.Timestamp < beforeUtc);
}

public Task DeleteMembershipTableEntries(string deploymentId)
public async Task DeleteMembershipTableEntries(string deploymentId)
{
return Task.WhenAll(
Collection.DeleteManyAsync(x => x.DeploymentId == deploymentId),
tableVersionCollection.DeleteAsync(deploymentId)
);
using var session = await Client.StartSessionAsync();

await session.WithTransactionAsync(async (sessionHandle, ct) =>
{
await Task.WhenAll(
Collection.DeleteManyAsync(sessionHandle, x => x.DeploymentId == deploymentId),
tableVersionCollection.DeleteAsync(sessionHandle, deploymentId)
);

return true;
});
}

private static MembershipTableData ReturnMembershipTableData(IEnumerable<MongoMembershipDocument> membershipList, TableVersion tableVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ protected override string CollectionName()
return $"{collectionPrefix}OrleansMembershipV3_TableVersion";
}

public Task DeleteAsync(string deploymentId)
public Task DeleteAsync(IClientSessionHandle session, string deploymentId)
{
return Collection.DeleteOneAsync(x => x.DeploymentId == deploymentId);
return Collection.DeleteOneAsync(session, x => x.DeploymentId == deploymentId);
}

public async Task<TableVersion> GetTableVersionAsync(string deploymentId)
public async Task<TableVersion> GetTableVersionAsync(IClientSessionHandle session, string deploymentId)
{
var deployment = await Collection.Find(x => x.DeploymentId == deploymentId).FirstOrDefaultAsync();
var deployment = await Collection.Find(session, x => x.DeploymentId == deploymentId).FirstOrDefaultAsync();

if (deployment == null)
{
Expand All @@ -50,7 +50,7 @@ public async Task<bool> UpsertAsync(IClientSessionHandle session, TableVersion t
try
{
await Collection.ReplaceOneAsync(session,
x => x.DeploymentId == deploymentId && x.VersionEtag == tableVersion.VersionEtag,
x => x.DeploymentId == deploymentId && x.VersionEtag == tableVersion.VersionEtag,
update,
UpsertReplace);

Expand Down
8 changes: 4 additions & 4 deletions Orleans.Providers.MongoDB/Orleans.Providers.MongoDB.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Authors>laredoza,sebastianstehle,wassim-k</Authors>
<Company>Orleans.Providers.MongoDB</Company>
<Copyright>MIT</Copyright>
<Description>A MongoDb implementation of the Orleans Providers. This includes custering (IMembershipTable and IGatewayListProvider), reminders (IReminderTable) and storage providers (IGrainStorage).</Description>
<Description>A MongoDb implementation of the Orleans Providers. This includes clustering (IMembershipTable and IGatewayListProvider), reminders (IReminderTable) and storage providers (IGrainStorage).</Description>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -18,12 +18,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Reminders" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="9.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MongoDB.Driver" Version="3.2.1" />
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ await Collection.ReplaceOneAsync(x => x.Id == id,

private static string ReturnId(string serviceId, GrainId grainId, string reminderName)
{
var grainType = grainId.Type.ToString();
var grainKey = grainId.Key.ToString();

if (grainType is null || grainKey is null)
{
throw new ArgumentNullException(nameof(grainId));
}

return $"{serviceId}_{grainId}_{reminderName}";
}
}
Expand Down
19 changes: 1 addition & 18 deletions Orleans.Providers.MongoDB/StorageProviders/MongoGrainStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
Expand All @@ -12,14 +11,13 @@

namespace Orleans.Providers.MongoDB.StorageProviders
{
public class MongoGrainStorage : IGrainStorage, ILifecycleParticipant<ISiloLifecycle>
public class MongoGrainStorage : IGrainStorage
{
private readonly ConcurrentDictionary<string, MongoGrainStorageCollection> collections = new ConcurrentDictionary<string, MongoGrainStorageCollection>();
private readonly MongoDBGrainStorageOptions options;
private readonly IMongoClient mongoClient;
private readonly ILogger<MongoGrainStorage> logger;
private readonly IGrainStateSerializer serializer;
private IMongoDatabase database;

public MongoGrainStorage(
IMongoClientFactory mongoClientFactory,
Expand All @@ -32,21 +30,6 @@ public MongoGrainStorage(
this.serializer = options.GrainStateSerializer;
}

public void Participate(ISiloLifecycle lifecycle)
{
lifecycle.Subscribe<MongoGrainStorage>(ServiceLifecycleStage.ApplicationServices, Init);
}

private Task Init(CancellationToken ct)
{
return DoAndLog(nameof(Init), () =>
{
database = mongoClient.GetDatabase(options.DatabaseName);

return Task.CompletedTask;
});
}

public Task ReadStateAsync<T>(string stateName, GrainId grainId, IGrainState<T> grainState)
{
return DoAndLog(nameof(ReadStateAsync), () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Sdk" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="9.0.1" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="9.0.1" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions Test/Grains/Orleans.Providers.MongoDB.Test.Grains.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.Sdk" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Core" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="9.1.2" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="9.0.1" />
<PackageReference Include="Microsoft.Orleans.Core" Version="9.0.1" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions Test/Host/Orleans.Providers.MongoDB.Test.Host.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -8,7 +8,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
<PackageReference Include="MongoSandbox8" Version="1.0.1" />
<PackageReference Include="MongoSandbox.Core" Version="2.0.0" />
<PackageReference Include="MongoSandbox8.runtime.linux-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="MongoSandbox8.runtime.osx-arm64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="MongoSandbox8.runtime.win-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Test/Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static async Task Main(string[] args)
{
var createShardKey = false;

using var mongoRunner = MongoRunner.Run(new MongoRunnerOptions { KillMongoProcessesWhenCurrentProcessExits = true });
using var mongoRunner = MongoRunner.Run();

Console.WriteLine("MongoDB ConnectionString: {0}", mongoRunner.ConnectionString);

Expand Down
9 changes: 6 additions & 3 deletions UnitTest/Orleans.Providers.MongoDB.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand All @@ -9,8 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MongoSandbox8" Version="1.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MongoSandbox.Core" Version="2.0.0" />
<PackageReference Include="MongoSandbox8.runtime.linux-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
<PackageReference Include="MongoSandbox8.runtime.osx-arm64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<PackageReference Include="MongoSandbox8.runtime.win-x64" Version="2.0.0" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>

Expand Down