-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConfigurationOptions: shuffle in prep for no-clone (#2049)
Cleaning up a bit before moving to no-clone for adjustable configuration. No functionality changes, just moving and ordering lots of cheese to make things easier, same with NRT diffs later.
- Loading branch information
1 parent
cbd6d7e
commit 9fb222e
Showing
20 changed files
with
1,572 additions
and
1,585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace StackExchange.Redis; | ||
|
||
public partial class ConnectionMultiplexer | ||
{ | ||
/// <summary> | ||
/// No longer used. | ||
/// </summary> | ||
[Obsolete("No longer used, will be removed in 3.0.")] | ||
public static TaskFactory Factory { get => Task.Factory; set { } } | ||
|
||
/// <summary> | ||
/// Gets or sets whether asynchronous operations should be invoked in a way that guarantees their original delivery order. | ||
/// </summary> | ||
[Obsolete("Not supported; if you require ordered pub/sub, please see " + nameof(ChannelMessageQueue) + ", will be removed in 3.0", false)] | ||
public bool PreserveAsyncOrder { get => false; set { } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Threading; | ||
|
||
namespace StackExchange.Redis; | ||
|
||
public partial class ConnectionMultiplexer | ||
{ | ||
private static int _collectedWithoutDispose; | ||
internal static int CollectedWithoutDispose => Thread.VolatileRead(ref _collectedWithoutDispose); | ||
|
||
/// <summary> | ||
/// Invoked by the garbage collector. | ||
/// </summary> | ||
~ConnectionMultiplexer() | ||
{ | ||
Interlocked.Increment(ref _collectedWithoutDispose); | ||
} | ||
|
||
bool IInternalConnectionMultiplexer.AllowConnect | ||
{ | ||
get => AllowConnect; | ||
set => AllowConnect = value; | ||
} | ||
|
||
bool IInternalConnectionMultiplexer.IgnoreConnect | ||
{ | ||
get => IgnoreConnect; | ||
set => IgnoreConnect = value; | ||
} | ||
|
||
/// <summary> | ||
/// For debugging: when not enabled, servers cannot connect. | ||
/// </summary> | ||
internal volatile bool AllowConnect = true; | ||
|
||
/// <summary> | ||
/// For debugging: when not enabled, end-connect is silently ignored (to simulate a long-running connect). | ||
/// </summary> | ||
internal volatile bool IgnoreConnect; | ||
} |
120 changes: 120 additions & 0 deletions
120
src/StackExchange.Redis/ConnectionMultiplexer.Events.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Net; | ||
using System.Runtime.CompilerServices; | ||
using StackExchange.Redis.Maintenance; | ||
|
||
namespace StackExchange.Redis; | ||
|
||
public partial class ConnectionMultiplexer | ||
{ | ||
/// <summary> | ||
/// Raised whenever a physical connection fails. | ||
/// </summary> | ||
public event EventHandler<ConnectionFailedEventArgs> ConnectionFailed; | ||
internal void OnConnectionFailed(EndPoint endpoint, ConnectionType connectionType, ConnectionFailureType failureType, Exception exception, bool reconfigure, string physicalName) | ||
{ | ||
if (_isDisposed) return; | ||
var handler = ConnectionFailed; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, failureType, exception, physicalName)); | ||
} | ||
if (reconfigure) | ||
{ | ||
ReconfigureIfNeeded(endpoint, false, "connection failed"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Raised whenever an internal error occurs (this is primarily for debugging). | ||
/// </summary> | ||
public event EventHandler<InternalErrorEventArgs> InternalError; | ||
internal void OnInternalError(Exception exception, EndPoint endpoint = null, ConnectionType connectionType = ConnectionType.None, [CallerMemberName] string origin = null) | ||
{ | ||
try | ||
{ | ||
if (_isDisposed) return; | ||
Trace("Internal error: " + origin + ", " + exception == null ? "unknown" : exception.Message); | ||
var handler = InternalError; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new InternalErrorEventArgs(handler, this, endpoint, connectionType, exception, origin)); | ||
} | ||
} | ||
catch | ||
{ | ||
// Our internal error event failed...whatcha gonna do, exactly? | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Raised whenever a physical connection is established. | ||
/// </summary> | ||
public event EventHandler<ConnectionFailedEventArgs> ConnectionRestored; | ||
internal void OnConnectionRestored(EndPoint endpoint, ConnectionType connectionType, string physicalName) | ||
{ | ||
if (_isDisposed) return; | ||
var handler = ConnectionRestored; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new ConnectionFailedEventArgs(handler, this, endpoint, connectionType, ConnectionFailureType.None, null, physicalName)); | ||
} | ||
ReconfigureIfNeeded(endpoint, false, "connection restored"); | ||
} | ||
|
||
/// <summary> | ||
/// Raised when configuration changes are detected. | ||
/// </summary> | ||
public event EventHandler<EndPointEventArgs> ConfigurationChanged; | ||
internal void OnConfigurationChanged(EndPoint endpoint) => OnEndpointChanged(endpoint, ConfigurationChanged); | ||
|
||
/// <summary> | ||
/// Raised when nodes are explicitly requested to reconfigure via broadcast. | ||
/// This usually means primary/replica changes. | ||
/// </summary> | ||
public event EventHandler<EndPointEventArgs> ConfigurationChangedBroadcast; | ||
internal void OnConfigurationChangedBroadcast(EndPoint endpoint) => OnEndpointChanged(endpoint, ConfigurationChangedBroadcast); | ||
|
||
private void OnEndpointChanged(EndPoint endpoint, EventHandler<EndPointEventArgs> handler) | ||
{ | ||
if (_isDisposed) return; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new EndPointEventArgs(handler, this, endpoint)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Raised when server indicates a maintenance event is going to happen. | ||
/// </summary> | ||
public event EventHandler<ServerMaintenanceEvent> ServerMaintenanceEvent; | ||
internal void OnServerMaintenanceEvent(ServerMaintenanceEvent e) => | ||
ServerMaintenanceEvent?.Invoke(this, e); | ||
|
||
/// <summary> | ||
/// Raised when a hash-slot has been relocated. | ||
/// </summary> | ||
public event EventHandler<HashSlotMovedEventArgs> HashSlotMoved; | ||
internal void OnHashSlotMoved(int hashSlot, EndPoint old, EndPoint @new) | ||
{ | ||
var handler = HashSlotMoved; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new HashSlotMovedEventArgs(handler, this, hashSlot, old, @new)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Raised when a server replied with an error message. | ||
/// </summary> | ||
public event EventHandler<RedisErrorEventArgs> ErrorMessage; | ||
internal void OnErrorMessage(EndPoint endpoint, string message) | ||
{ | ||
if (_isDisposed) return; | ||
var handler = ErrorMessage; | ||
if (handler != null) | ||
{ | ||
CompleteAsWorker(new RedisErrorEventArgs(handler, this, endpoint, message)); | ||
} | ||
} | ||
} |
Oops, something went wrong.