Skip to content
Closed
Changes from 1 commit
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
41 changes: 32 additions & 9 deletions src/Wolverine/Runtime/Agents/EventStoreAgents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,43 @@
var usage = await _store.TryCreateUsage(cancellation);
if (usage == null) return list;

var asyncShards = usage.Subscriptions
.Where(x => x.Lifecycle == ProjectionLifecycle.Async)
.SelectMany(x => x.ShardNames)
.ToArray();

// wolverine#3280: under sharded databases + per-tenant event partitioning, multiple tenants are
// co-located in one shard database and each draws its own event sequence, so a single store-global
// agent per (shard, database) cannot track them — fan out one agent per (shard, tenant) instead.
// For any other store (or a database with no tenants yet) keep the one store-global agent.
void addAgentsForShard(DatabaseDescriptor database, DatabaseId id, ShardName shardName)
Comment on lines +103 to +107
{
if (_store.DistributesAgentsPerTenant && database.TenantIds.Count > 0)

Check failure on line 101 in src/Wolverine/Runtime/Agents/EventStoreAgents.cs

View workflow job for this annotation

GitHub Actions / fsharp-codegen-compile-gate

'IEventStore' does not contain a definition for 'DistributesAgentsPerTenant' and no accessible extension method 'DistributesAgentsPerTenant' accepting a first argument of type 'IEventStore' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 101 in src/Wolverine/Runtime/Agents/EventStoreAgents.cs

View workflow job for this annotation

GitHub Actions / fsharp-codegen-compile-gate

'IEventStore' does not contain a definition for 'DistributesAgentsPerTenant' and no accessible extension method 'DistributesAgentsPerTenant' accepting a first argument of type 'IEventStore' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 101 in src/Wolverine/Runtime/Agents/EventStoreAgents.cs

View workflow job for this annotation

GitHub Actions / fsharp-codegen-compile-gate

'IEventStore' does not contain a definition for 'DistributesAgentsPerTenant' and no accessible extension method 'DistributesAgentsPerTenant' accepting a first argument of type 'IEventStore' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 101 in src/Wolverine/Runtime/Agents/EventStoreAgents.cs

View workflow job for this annotation

GitHub Actions / fsharp-codegen-compile-gate

'IEventStore' does not contain a definition for 'DistributesAgentsPerTenant' and no accessible extension method 'DistributesAgentsPerTenant' accepting a first argument of type 'IEventStore' could be found (are you missing a using directive or an assembly reference?)
{
foreach (var tenantId in database.TenantIds.Distinct())
{
var tenantShard = shardName.ForTenant(tenantId);
_shardNames = _shardNames.AddOrUpdate(tenantShard.RelativeUrl, tenantShard);
list.Add(EventSubscriptionAgentFamily.UriFor(_store.Identity, id, tenantShard));
}
}
Comment on lines +109 to +122
else
{
_shardNames = _shardNames.AddOrUpdate(shardName.RelativeUrl, shardName);
list.Add(EventSubscriptionAgentFamily.UriFor(_store.Identity, id, shardName));
}
}

// Using this to keep from double dipping
var databaseIds = new List<DatabaseId>();
foreach (var database in usage.Database.Databases)
{
var id = new DatabaseId(database.ServerName, database.DatabaseName);
databaseIds.Add(id);
foreach (var shardName in usage.Subscriptions.Where(x => x.Lifecycle == ProjectionLifecycle.Async).SelectMany(x => x.ShardNames))

foreach (var shardName in asyncShards)
{
_shardNames = _shardNames.AddOrUpdate(shardName.RelativeUrl, shardName);
var uri = EventSubscriptionAgentFamily.UriFor(_store.Identity, id, shardName);
list.Add(uri);
addAgentsForShard(database, id, shardName);
}
}

Expand All @@ -108,11 +133,9 @@
var id = new DatabaseId(database.ServerName, database.DatabaseName);
if (!databaseIds.Contains(id))
{
foreach (var shardName in usage.Subscriptions.Where(x => x.Lifecycle == ProjectionLifecycle.Async).SelectMany(x => x.ShardNames))
foreach (var shardName in asyncShards)
{
_shardNames = _shardNames.AddOrUpdate(shardName.RelativeUrl, shardName);
var uri = EventSubscriptionAgentFamily.UriFor(_store.Identity, id, shardName);
list.Add(uri);
addAgentsForShard(database, id, shardName);
}
}
}
Expand Down
Loading