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
98 changes: 0 additions & 98 deletions src/Npgsql/ConnectorSource.cs

This file was deleted.

14 changes: 7 additions & 7 deletions src/Npgsql/Internal/NpgsqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ internal void FlagAsWritableForMultiplexing()

/// <summary>
/// The connector source (e.g. pool) from where this connector came, and to which it will be returned.
/// Note that in multi-host scenarios, this references the host-specific <see cref="ConnectorPool"/> rather than the
/// <see cref="MultiHostConnectorPool"/>,
/// Note that in multi-host scenarios, this references the host-specific <see cref="PoolingDataSource"/> rather than the
/// <see cref="MultiHostDataSource"/>,
/// </summary>
readonly ConnectorSource _connectorSource;
readonly NpgsqlDataSource _connectorSource;

internal string UserFacingConnectionString => _connectorSource.UserFacingConnectionString;
internal string UserFacingConnectionString => _connectorSource.ConnectionString;

/// <summary>
/// Contains the UTC timestamp when this connector was opened, used to implement
Expand Down Expand Up @@ -312,7 +312,7 @@ internal bool PostgresCancellationPerformed

#region Constructors

internal NpgsqlConnector(ConnectorSource connectorSource, NpgsqlConnection conn)
internal NpgsqlConnector(NpgsqlDataSource connectorSource, NpgsqlConnection conn)
: this(connectorSource)
{
ProvideClientCertificatesCallback = conn.ProvideClientCertificatesCallback;
Expand All @@ -333,7 +333,7 @@ internal NpgsqlConnector(ConnectorSource connectorSource, NpgsqlConnection conn)
ProvidePasswordCallback = connector.ProvidePasswordCallback;
}

NpgsqlConnector(ConnectorSource connectorSource)
NpgsqlConnector(NpgsqlDataSource connectorSource)
{
Debug.Assert(connectorSource.OwnsConnectors);
_connectorSource = connectorSource;
Expand Down Expand Up @@ -596,7 +596,7 @@ internal async ValueTask LoadDatabaseInfo(bool forceReload, NpgsqlTimeout timeou
// multiplexing there's no connector yet). However, in the very first multiplexing connection (bootstrap phase) we create
// a connector-specific mapper, which will later become shared pool-wide one.
TypeMapper =
Settings.Multiplexing && ((MultiplexingConnectorPool)_connectorSource).MultiplexingTypeMapper is { } multiplexingTypeMapper
Settings.Multiplexing && ((MultiplexingDataSource)_connectorSource).MultiplexingTypeMapper is { } multiplexingTypeMapper
? multiplexingTypeMapper
: new ConnectorTypeMapper(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

namespace Npgsql;

sealed class MultiHostConnectorPool : ConnectorSource
sealed class MultiHostDataSource : NpgsqlDataSource
{
internal override bool OwnsConnectors => false;

readonly ConnectorSource[] _pools;
readonly NpgsqlDataSource[] _pools;

internal ConnectorSource[] Pools => _pools;
internal NpgsqlDataSource[] Pools => _pools;

volatile int _roundRobinIndex = -1;

public MultiHostConnectorPool(NpgsqlConnectionStringBuilder settings, string connString) : base(settings, connString)
public MultiHostDataSource(NpgsqlConnectionStringBuilder settings, string connString) : base(settings, connString)
{
var hosts = settings.Host!.Split(',');
_pools = new ConnectorSource[hosts.Length];
_pools = new NpgsqlDataSource[hosts.Length];
for (var i = 0; i < hosts.Length; i++)
{
var poolSettings = settings.Clone();
Expand All @@ -39,8 +39,8 @@ public MultiHostConnectorPool(NpgsqlConnectionStringBuilder settings, string con
poolSettings.Host = host.ToString();

_pools[i] = settings.Pooling
? new ConnectorPool(poolSettings, poolSettings.ConnectionString, this)
: new UnpooledConnectorSource(poolSettings, poolSettings.ConnectionString);
? new PoolingDataSource(poolSettings, poolSettings.ConnectionString, this)
: new UnpooledDataSource(poolSettings, poolSettings.ConnectionString);
}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ static bool IsFallbackOrPreferred(ClusterState state, TargetSessionAttributes pr
_ => false
};

static ClusterState GetClusterState(ConnectorSource pool, bool ignoreExpiration = false)
static ClusterState GetClusterState(NpgsqlDataSource pool, bool ignoreExpiration = false)
=> GetClusterState(pool.Settings.Host!, pool.Settings.Port, ignoreExpiration);

static ClusterState GetClusterState(string host, int port, bool ignoreExpiration)
Expand Down Expand Up @@ -191,6 +191,8 @@ static ClusterState GetClusterState(string host, int port, bool ignoreExpiration

internal override async ValueTask<NpgsqlConnector> Get(NpgsqlConnection conn, NpgsqlTimeout timeout, bool async, CancellationToken cancellationToken)
{
CheckDisposed();

var exceptions = new List<Exception>();

var poolIndex = conn.Settings.LoadBalanceHosts ? GetRoundRobinIndex() : 0;
Expand Down Expand Up @@ -249,13 +251,13 @@ int GetRoundRobinIndex()
}

internal override void Return(NpgsqlConnector connector)
=> throw new NpgsqlException("Npgsql bug: a connector was returned to " + nameof(MultiHostConnectorPool));
=> throw new NpgsqlException("Npgsql bug: a connector was returned to " + nameof(MultiHostDataSource));

internal override bool TryGetIdleConnector([NotNullWhen(true)] out NpgsqlConnector? connector)
=> throw new NpgsqlException("Npgsql bug: trying to get an idle connector from " + nameof(MultiHostConnectorPool));
=> throw new NpgsqlException("Npgsql bug: trying to get an idle connector from " + nameof(MultiHostDataSource));

internal override ValueTask<NpgsqlConnector?> OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, bool async, CancellationToken cancellationToken)
=> throw new NpgsqlException("Npgsql bug: trying to open a new connector from " + nameof(MultiHostConnectorPool));
=> throw new NpgsqlException("Npgsql bug: trying to open a new connector from " + nameof(MultiHostDataSource));

internal override void Clear()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace Npgsql;

sealed class MultiHostConnectorPoolWrapper : ConnectorSource
sealed class MultiHostDataSourceWrapper : NpgsqlDataSource
{
internal override bool OwnsConnectors => false;

readonly MultiHostConnectorPool _wrappedSource;
readonly MultiHostDataSource _wrappedSource;

public MultiHostConnectorPoolWrapper(NpgsqlConnectionStringBuilder settings, string connString, MultiHostConnectorPool source) : base(settings, connString)
public MultiHostDataSourceWrapper(NpgsqlConnectionStringBuilder settings, string connString, MultiHostDataSource source) : base(settings, connString)
=> _wrappedSource = source;

internal override (int Total, int Idle, int Busy) Statistics => _wrappedSource.Statistics;
Expand All @@ -22,9 +22,9 @@ public MultiHostConnectorPoolWrapper(NpgsqlConnectionStringBuilder settings, str
internal override ValueTask<NpgsqlConnector> Get(NpgsqlConnection conn, NpgsqlTimeout timeout, bool async, CancellationToken cancellationToken)
=> _wrappedSource.Get(conn, timeout, async, cancellationToken);
internal override bool TryGetIdleConnector([NotNullWhen(true)] out NpgsqlConnector? connector)
=> throw new NpgsqlException("Npgsql bug: trying to get an idle connector from " + nameof(MultiHostConnectorPoolWrapper));
=> throw new NpgsqlException("Npgsql bug: trying to get an idle connector from " + nameof(MultiHostDataSourceWrapper));
internal override ValueTask<NpgsqlConnector?> OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, bool async, CancellationToken cancellationToken)
=> throw new NpgsqlException("Npgsql bug: trying to open a new connector from " + nameof(MultiHostConnectorPoolWrapper));
=> throw new NpgsqlException("Npgsql bug: trying to open a new connector from " + nameof(MultiHostDataSourceWrapper));
internal override void Return(NpgsqlConnector connector)
=> _wrappedSource.Return(connector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Npgsql;

sealed class MultiplexingConnectorPool : ConnectorPool
sealed class MultiplexingDataSource : PoolingDataSource
{
static readonly ILogger ConnectionLogger = NpgsqlLoggingConfiguration.ConnectionLogger;
static readonly ILogger CommandLogger = NpgsqlLoggingConfiguration.CommandLogger;
Expand Down Expand Up @@ -47,8 +47,8 @@ public bool IsBootstrapped
// TODO: Make this configurable
const int MultiplexingCommandChannelBound = 4096;

internal MultiplexingConnectorPool(
NpgsqlConnectionStringBuilder settings, string connString, MultiHostConnectorPool? parentPool = null)
internal MultiplexingDataSource(
NpgsqlConnectionStringBuilder settings, string connString, MultiHostDataSource? parentPool = null)
: base(settings, connString, parentPool)
{
Debug.Assert(Settings.Multiplexing);
Expand Down Expand Up @@ -399,10 +399,14 @@ static void CompleteWrite(NpgsqlConnector connector, ref MultiplexingStats stats
// ReSharper disable once FunctionNeverReturns
}

public override void Dispose()
protected override void Dispose(bool disposing)
{
_bootstrapSemaphore.Dispose();
base.Dispose();
base.Dispose(disposing);

if (disposing)
{
_bootstrapSemaphore.Dispose();
}
}

struct MultiplexingStats
Expand Down
Loading