Skip to main content

DataverseConnectionPool

  • Namespace: PPDS.Dataverse.Pooling
  • Assembly: PPDS.Dataverse
  • Kind: Class
  • Implements: IDataverseConnectionPool, IAsyncDisposable, IDisposable

Summary​

High-performance connection pool for Dataverse with multi-connection support.

Members​

Constructors​

DataverseConnectionPool(IEnumerable<IConnectionSource> sources, IThrottleTracker throttleTracker, ConnectionPoolOptions poolOptions, ILogger<DataverseConnectionPool> logger)​

DataverseConnectionPool(IEnumerable<IConnectionSource> sources, IThrottleTracker throttleTracker, ConnectionPoolOptions poolOptions, ILogger<DataverseConnectionPool> logger)

Initializes a new connection pool from connection sources.

  • Param sources: One or more connection sources providing seed clients. Each source's seed will be cloned to create pool members.

  • Param throttleTracker: Throttle tracking service.

  • Param poolOptions: Pool configuration options.

  • Param logger: Logger instance.

DataverseConnectionPool(IOptions<DataverseOptions> options, IThrottleTracker throttleTracker, ILogger<DataverseConnectionPool> logger)​

DataverseConnectionPool(IOptions<DataverseOptions> options, IThrottleTracker throttleTracker, ILogger<DataverseConnectionPool> logger)

Initializes a new connection pool from DataverseOptions configuration. This constructor maintains backward compatibility with existing DI registration.

Methods​

Dispose​

void Dispose()

(inherited from System.IDisposable.Dispose)

DisposeAsync​

ValueTask DisposeAsync()

(inherited from System.IAsyncDisposable.DisposeAsync)

EnsureInitializedAsync​

Task EnsureInitializedAsync(CancellationToken cancellationToken)

Ensures the pool is initialized by warming all seed connections. Triggers authentication and DOP discovery. Idempotent - subsequent calls are no-ops.

  • Param cancellationToken: Cancellation token.

  • Returns: A task that completes when initialization is done.

ExecuteAsync​

Task<OrganizationResponse> ExecuteAsync(OrganizationRequest request, CancellationToken cancellationToken)

Executes a request with automatic retry on service protection errors. This is a convenience method that handles connection management and throttle retry internally. The caller doesn't need to handle service protection exceptions - they are handled transparently.

  • Param request: The organization request to execute.

  • Param cancellationToken: Cancellation token.

  • Returns: The organization response.

GetActiveConnectionCount​

int GetActiveConnectionCount(string sourceName)

Gets the current number of active (checked-out) connections for a source.

  • Param sourceName: The name of the connection source.

  • Returns: The number of currently active connections.

GetClient​

IPooledClient GetClient(DataverseClientOptions options)

Gets a client from the pool synchronously.

  • Param options: Optional per-request options (CallerId, etc.)

  • Returns: A pooled client that returns to pool on dispose.

GetClientAsync​

Task<IPooledClient> GetClientAsync(DataverseClientOptions options, string excludeConnectionName, CancellationToken cancellationToken)

Gets a client from the pool asynchronously.

  • Param options: Optional per-request options (CallerId, etc.)

  • Param excludeConnectionName: Optional connection name to exclude from selection (useful for retry after throttle).

  • Param cancellationToken: Cancellation token.

  • Returns: A pooled client that returns to pool on dispose.

GetLiveSourceDop​

int GetLiveSourceDop(string sourceName)

Gets the live DOP (degrees of parallelism) for a specific connection source.

  • Param sourceName: The name of the connection source.

  • Returns: The current recommended parallelism for this source (1-52).

GetTotalRecommendedParallelism​

int GetTotalRecommendedParallelism()

Gets the total recommended parallelism across all connection sources. This is the sum of live RecommendedDegreesOfParallelism for each source.

  • Returns: The total recommended parallelism across all sources.

InvalidateSeed​

void InvalidateSeed(string connectionName)

Invalidates the seed client for a connection, forcing fresh authentication on next use.

  • Param connectionName: The name of the connection source to invalidate.

RecordAuthFailure​

void RecordAuthFailure()

Records an authentication failure for statistics.

RecordConnectionFailure​

void RecordConnectionFailure()

Records a connection failure for statistics.

TryGetClientWithCapacityAsync​

Task<IPooledClient> TryGetClientWithCapacityAsync(CancellationToken cancellationToken)

Tries to get a client from a source that has available DOP capacity. Returns null if all sources are at capacity or throttled.

  • Param cancellationToken: Cancellation token.

  • Returns: A pooled client if capacity is available, null otherwise.

Properties​

BatchCoordinator​

BatchParallelismCoordinator BatchCoordinator { get; }

Gets the batch parallelism coordinator for coordinating concurrent bulk operations.

InitializationResults​

IReadOnlyList<SeedInitializationResult> InitializationResults { get; }

Gets the results of seed initialization for each connection source.

IsEnabled​

bool IsEnabled { get; }

Gets a value indicating whether the pool is enabled.

SourceCount​

int SourceCount { get; }

Gets the number of connection sources configured in the pool. This represents the number of Application Users/app registrations available.

Statistics​

PoolStatistics Statistics { get; }

Gets pool statistics and health information.