Skip to content

Commit

Permalink
RavenDB-20968 deference shard & orchestrator executors
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 committed Jul 31, 2023
1 parent d251053 commit 263d7a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ protected AbstractExecutor([NotNull] ServerStore store)
ServerStore.Server.ServerCertificateChanged += OnCertificateChange;
}

public void ForgetAbout()
{
// the event handler holds a strong reference to this object, so it will not be collected by the gc
ServerStore.Server.ServerCertificateChanged -= OnCertificateChange;
}

public abstract RequestExecutor GetRequestExecutorAt(int position);

protected abstract Memory<int> GetAllPositions();
Expand Down
4 changes: 4 additions & 0 deletions src/Raven.Server/Documents/Sharding/ShardedDatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void OnDatabaseRecordChange(DatabaseRecord record, long index)

if (DictionaryExtensions.KeysEqual(record.Sharding.Shards, _record.Sharding.Shards) == false)
{
ShardExecutor.ForgetAbout();
ShardExecutor = new ShardExecutor(ServerStore, record, record.DatabaseName);
}
else
Expand All @@ -139,6 +140,7 @@ private void OnDatabaseRecordChange(DatabaseRecord record, long index)

if (CheckForTopologyChangesAndRaiseNotification(record.Sharding.Orchestrator.Topology, _record.Sharding.Orchestrator.Topology))
{
AllOrchestratorNodesExecutor.ForgetAbout();
AllOrchestratorNodesExecutor = new AllOrchestratorNodesExecutor(ServerStore, record);
}

Expand Down Expand Up @@ -171,8 +173,10 @@ private void OnUrlChange(DatabaseRecord record, long index)
// we explicitly do not dispose the old executors here to avoid possible memory invalidation and since this is expected to be rare.
// So we rely on the GC to dispose them via the finalizer

ShardExecutor.ForgetAbout();
ShardExecutor = new ShardExecutor(ServerStore, _record, _record.DatabaseName);

AllOrchestratorNodesExecutor.ForgetAbout();
AllOrchestratorNodesExecutor = new AllOrchestratorNodesExecutor(ServerStore, _record);
}

Expand Down

0 comments on commit 263d7a4

Please sign in to comment.