Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
e11171dc
Commit
e11171dc
authored
Mar 21, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-props cleanup
parent
c76b249d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
84 deletions
+77
-84
ConnectionMultiplexer.cs
...change.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
+30
-36
RedisSubscriber.cs
StackExchange.Redis/StackExchange/Redis/RedisSubscriber.cs
+3
-3
ServerEndPoint.cs
StackExchange.Redis/StackExchange/Redis/ServerEndPoint.cs
+44
-45
No files found.
StackExchange.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
View file @
e11171dc
...
...
@@ -45,7 +45,7 @@ public ServerCounters GetCounters()
{
counters
.
Add
(
snapshot
[
i
].
GetCounters
());
}
u
nprocessableCompletionManager
.
GetCounters
(
counters
.
Other
);
U
nprocessableCompletionManager
.
GetCounters
(
counters
.
Other
);
return
counters
;
}
...
...
@@ -123,7 +123,7 @@ internal void OnConnectionFailed(EndPoint endpoint, ConnectionType connectionTyp
var
handler
=
ConnectionFailed
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
ConnectionFailedEventArgs
(
handler
,
this
,
endpoint
,
connectionType
,
failureType
,
exception
)
);
}
...
...
@@ -142,7 +142,7 @@ internal void OnInternalError(Exception exception, EndPoint endpoint = null, Con
var
handler
=
InternalError
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
InternalErrorEventArgs
(
handler
,
this
,
endpoint
,
connectionType
,
exception
,
origin
)
);
}
...
...
@@ -158,7 +158,7 @@ internal void OnConnectionRestored(EndPoint endpoint, ConnectionType connectionT
var
handler
=
ConnectionRestored
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
ConnectionFailedEventArgs
(
handler
,
this
,
endpoint
,
connectionType
,
ConnectionFailureType
.
None
,
null
)
);
}
...
...
@@ -170,7 +170,7 @@ private void OnEndpointChanged(EndPoint endpoint, EventHandler<EndPointEventArgs
if
(
isDisposed
)
return
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
EndPointEventArgs
(
handler
,
this
,
endpoint
)
);
}
...
...
@@ -189,7 +189,7 @@ internal void OnErrorMessage(EndPoint endpoint, string message)
var
handler
=
ErrorMessage
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
RedisErrorEventArgs
(
handler
,
this
,
endpoint
,
message
)
);
}
...
...
@@ -481,7 +481,7 @@ private static void WriteNormalizingLineEndings(string source, StreamWriter writ
/// <summary>
/// Gets the timeout associated with the connections
/// </summary>
public
int
TimeoutMilliseconds
=>
timeoutMilliseconds
;
public
int
TimeoutMilliseconds
{
get
;
}
/// <summary>
/// Gets all endpoints defined on the server
...
...
@@ -494,13 +494,11 @@ public EndPoint[] GetEndPoints(bool configuredOnly = false)
return
ConvertHelper
.
ConvertAll
(
serverSnapshot
,
x
=>
x
.
EndPoint
);
}
private
readonly
int
timeoutMilliseconds
;
private
readonly
ConfigurationOptions
configuration
;
internal
bool
TryResend
(
int
hashSlot
,
Message
message
,
EndPoint
endpoint
,
bool
isMoved
)
{
return
s
erverSelectionStrategy
.
TryResend
(
hashSlot
,
message
,
endpoint
,
isMoved
);
return
S
erverSelectionStrategy
.
TryResend
(
hashSlot
,
message
,
endpoint
,
isMoved
);
}
/// <summary>
...
...
@@ -510,7 +508,7 @@ internal bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool i
public
void
Wait
(
Task
task
)
{
if
(
task
==
null
)
throw
new
ArgumentNullException
(
nameof
(
task
));
if
(!
task
.
Wait
(
t
imeoutMilliseconds
))
throw
new
TimeoutException
();
if
(!
task
.
Wait
(
T
imeoutMilliseconds
))
throw
new
TimeoutException
();
}
/// <summary>
...
...
@@ -521,7 +519,7 @@ public void Wait(Task task)
public
T
Wait
<
T
>(
Task
<
T
>
task
)
{
if
(
task
==
null
)
throw
new
ArgumentNullException
(
nameof
(
task
));
if
(!
task
.
Wait
(
t
imeoutMilliseconds
))
throw
new
TimeoutException
();
if
(!
task
.
Wait
(
T
imeoutMilliseconds
))
throw
new
TimeoutException
();
return
task
.
Result
;
}
...
...
@@ -533,10 +531,10 @@ public void WaitAll(params Task[] tasks)
{
if
(
tasks
==
null
)
throw
new
ArgumentNullException
(
nameof
(
tasks
));
if
(
tasks
.
Length
==
0
)
return
;
if
(!
Task
.
WaitAll
(
tasks
,
t
imeoutMilliseconds
))
throw
new
TimeoutException
();
if
(!
Task
.
WaitAll
(
tasks
,
T
imeoutMilliseconds
))
throw
new
TimeoutException
();
}
private
bool
WaitAllIgnoreErrors
(
Task
[]
tasks
)
=>
WaitAllIgnoreErrors
(
tasks
,
t
imeoutMilliseconds
);
private
bool
WaitAllIgnoreErrors
(
Task
[]
tasks
)
=>
WaitAllIgnoreErrors
(
tasks
,
T
imeoutMilliseconds
);
private
static
bool
WaitAllIgnoreErrors
(
Task
[]
tasks
,
int
timeout
)
{
...
...
@@ -677,7 +675,7 @@ internal void OnHashSlotMoved(int hashSlot, EndPoint old, EndPoint @new)
var
handler
=
HashSlotMoved
;
if
(
handler
!=
null
)
{
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
new
HashSlotMovedEventArgs
(
handler
,
this
,
hashSlot
,
old
,
@new
)
);
}
...
...
@@ -687,7 +685,7 @@ internal void OnHashSlotMoved(int hashSlot, EndPoint old, EndPoint @new)
/// Compute the hash-slot of a specified key
/// </summary>
/// <param name="key">The key to get a hash slot ID for.</param>
public
int
HashSlot
(
RedisKey
key
)
=>
s
erverSelectionStrategy
.
HashSlot
(
key
);
public
int
HashSlot
(
RedisKey
key
)
=>
S
erverSelectionStrategy
.
HashSlot
(
key
);
internal
ServerEndPoint
AnyConnected
(
ServerType
serverType
,
uint
startOffset
,
RedisCommand
command
,
CommandFlags
flags
)
{
...
...
@@ -910,11 +908,11 @@ private ConnectionMultiplexer(ConfigurationOptions configuration)
}
PreserveAsyncOrder
=
configuration
.
PreserveAsyncOrder
;
t
imeoutMilliseconds
=
configuration
.
SyncTimeout
;
T
imeoutMilliseconds
=
configuration
.
SyncTimeout
;
OnCreateReaderWriter
(
configuration
);
u
nprocessableCompletionManager
=
new
CompletionManager
(
this
,
"multiplexer"
);
s
erverSelectionStrategy
=
new
ServerSelectionStrategy
(
this
);
U
nprocessableCompletionManager
=
new
CompletionManager
(
this
,
"multiplexer"
);
S
erverSelectionStrategy
=
new
ServerSelectionStrategy
(
this
);
var
configChannel
=
configuration
.
ConfigurationChannel
;
if
(!
string
.
IsNullOrWhiteSpace
(
configChannel
))
...
...
@@ -975,7 +973,7 @@ internal long LastHeartbeatSecondsAgo
internal
static
long
LastGlobalHeartbeatSecondsAgo
=>
unchecked
(
Environment
.
TickCount
-
VolatileWrapper
.
Read
(
ref
lastGlobalHeartbeatTicks
))
/
1000
;
internal
CompletionManager
UnprocessableCompletionManager
=>
unprocessableCompletionManager
;
internal
CompletionManager
UnprocessableCompletionManager
{
get
;
}
/// <summary>
/// Obtain a pub/sub subscriber connection to the specified server
...
...
@@ -1086,8 +1084,6 @@ internal static void TraceWithoutContext(bool condition, string message, [Caller
if
(
condition
)
OnTraceWithoutContext
(
message
,
category
);
}
private
readonly
CompletionManager
unprocessableCompletionManager
;
/// <summary>
/// The number of operations that have been performed on all connections
/// </summary>
...
...
@@ -1234,7 +1230,7 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
if
(
configuration
.
ResolveDns
&&
configuration
.
HasDnsEndPoints
())
{
var
dns
=
configuration
.
ResolveEndPointsAsync
(
this
,
log
).
ObserveErrors
();
if
((
await
Task
.
WhenAny
(
dns
,
Task
.
Delay
(
t
imeoutMilliseconds
)).
ForAwait
())
!=
dns
)
if
((
await
Task
.
WhenAny
(
dns
,
Task
.
Delay
(
T
imeoutMilliseconds
)).
ForAwait
())
!=
dns
)
{
throw
new
TimeoutException
(
"Timeout resolving endpoints"
);
}
...
...
@@ -1443,15 +1439,15 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
// set the serverSelectionStrategy
if
(
RawConfig
.
Proxy
==
Proxy
.
Twemproxy
)
{
s
erverSelectionStrategy
.
ServerType
=
ServerType
.
Twemproxy
;
S
erverSelectionStrategy
.
ServerType
=
ServerType
.
Twemproxy
;
}
else
if
(
standaloneCount
==
0
&&
sentinelCount
>
0
)
{
s
erverSelectionStrategy
.
ServerType
=
ServerType
.
Sentinel
;
S
erverSelectionStrategy
.
ServerType
=
ServerType
.
Sentinel
;
}
else
{
s
erverSelectionStrategy
.
ServerType
=
ServerType
.
Standalone
;
S
erverSelectionStrategy
.
ServerType
=
ServerType
.
Standalone
;
}
var
preferred
=
await
NominatePreferredMaster
(
log
,
servers
,
useTieBreakers
,
tieBreakers
,
masters
).
ObserveErrors
().
ForAwait
();
foreach
(
var
master
in
masters
)
...
...
@@ -1468,10 +1464,10 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
}
else
{
s
erverSelectionStrategy
.
ServerType
=
ServerType
.
Cluster
;
long
coveredSlots
=
s
erverSelectionStrategy
.
CountCoveredSlots
();
S
erverSelectionStrategy
.
ServerType
=
ServerType
.
Cluster
;
long
coveredSlots
=
S
erverSelectionStrategy
.
CountCoveredSlots
();
LogLocked
(
log
,
"Cluster: {0} of {1} slots covered"
,
coveredSlots
,
s
erverSelectionStrategy
.
TotalSlots
);
coveredSlots
,
S
erverSelectionStrategy
.
TotalSlots
);
}
if
(!
first
)
{
...
...
@@ -1724,15 +1720,13 @@ internal void UpdateClusterRange(ClusterConfiguration configuration)
foreach
(
var
slot
in
node
.
Slots
)
{
var
server
=
GetServerEndPoint
(
node
.
EndPoint
);
if
(
server
!=
null
)
s
erverSelectionStrategy
.
UpdateClusterRange
(
slot
.
From
,
slot
.
To
,
server
);
if
(
server
!=
null
)
S
erverSelectionStrategy
.
UpdateClusterRange
(
slot
.
From
,
slot
.
To
,
server
);
}
}
}
private
Timer
pulse
;
private
readonly
ServerSelectionStrategy
serverSelectionStrategy
;
internal
ServerEndPoint
[]
GetServerSnapshot
()
{
var
tmp
=
serverSnapshot
;
...
...
@@ -1742,12 +1736,12 @@ internal ServerEndPoint[] GetServerSnapshot()
internal
ServerEndPoint
SelectServer
(
Message
message
)
{
if
(
message
==
null
)
return
null
;
return
s
erverSelectionStrategy
.
Select
(
message
);
return
S
erverSelectionStrategy
.
Select
(
message
);
}
internal
ServerEndPoint
SelectServer
(
int
db
,
RedisCommand
command
,
CommandFlags
flags
,
RedisKey
key
)
{
return
s
erverSelectionStrategy
.
Select
(
db
,
command
,
key
,
flags
);
return
S
erverSelectionStrategy
.
Select
(
db
,
command
,
key
,
flags
);
}
private
bool
TryPushMessageToBridge
<
T
>(
Message
message
,
ResultProcessor
<
T
>
processor
,
ResultBox
<
T
>
resultBox
,
ref
ServerEndPoint
server
)
...
...
@@ -1855,7 +1849,7 @@ public bool IsConnecting
internal
ConfigurationOptions
RawConfig
=>
configuration
;
internal
ServerSelectionStrategy
ServerSelectionStrategy
=>
serverSelectionStrategy
;
internal
ServerSelectionStrategy
ServerSelectionStrategy
{
get
;
}
/// <summary>
/// Close all connections and release all resources associated with this object
...
...
@@ -2005,7 +1999,7 @@ internal T ExecuteSyncImpl<T>(Message message, ResultProcessor<T> processor, Ser
throw
ExceptionFactory
.
NoConnectionAvailable
(
IncludeDetailInExceptions
,
IncludePerformanceCountersInExceptions
,
message
.
Command
,
message
,
server
,
GetServerSnapshot
());
}
if
(
Monitor
.
Wait
(
source
,
t
imeoutMilliseconds
))
if
(
Monitor
.
Wait
(
source
,
T
imeoutMilliseconds
))
{
Trace
(
"Timeley response to "
+
message
);
}
...
...
StackExchange.Redis/StackExchange/Redis/RedisSubscriber.cs
View file @
e11171dc
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Net
;
using
System.Threading
;
...
...
@@ -74,7 +74,7 @@ internal void OnMessage(RedisChannel subscription, RedisChannel channel, RedisVa
completable
=
sub
.
ForInvoke
(
channel
,
payload
);
}
}
if
(
completable
!=
null
)
u
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
completable
);
if
(
completable
!=
null
)
U
nprocessableCompletionManager
.
CompleteSyncOrAsync
(
completable
);
}
internal
Task
RemoveAllSubscriptions
(
CommandFlags
flags
,
object
asyncState
)
...
...
@@ -322,4 +322,4 @@ public Task UnsubscribeAsync(RedisChannel channel, Action<RedisChannel, RedisVal
return
multiplexer
.
RemoveSubscription
(
channel
,
handler
,
flags
,
asyncState
);
}
}
}
\ No newline at end of file
}
StackExchange.Redis/StackExchange/Redis/ServerEndPoint.cs
View file @
e11171dc
...
...
@@ -27,10 +27,8 @@ internal sealed partial class ServerEndPoint : IDisposable
internal
volatile
ServerEndPoint
[]
Slaves
=
NoSlaves
;
private
static
readonly
Regex
nameSanitizer
=
new
Regex
(
"[^!-~]"
,
RegexOptions
.
Compiled
);
private
static
readonly
ServerEndPoint
[]
NoSlaves
=
new
ServerEndPoint
[
0
];
private
readonly
EndPoint
endpoint
;
private
readonly
Hashtable
knownScripts
=
new
Hashtable
(
StringComparer
.
Ordinal
);
private
readonly
ConnectionMultiplexer
multiplexer
;
private
int
databases
,
writeEverySeconds
;
private
PhysicalBridge
interactive
,
subscription
;
...
...
@@ -48,8 +46,8 @@ internal void ResetNonConnected()
public
ServerEndPoint
(
ConnectionMultiplexer
multiplexer
,
EndPoint
endpoint
,
TextWriter
log
)
{
this
.
m
ultiplexer
=
multiplexer
;
this
.
endp
oint
=
endpoint
;
M
ultiplexer
=
multiplexer
;
EndP
oint
=
endpoint
;
var
config
=
multiplexer
.
RawConfig
;
version
=
config
.
DefaultVersion
;
slaveReadOnly
=
true
;
...
...
@@ -71,7 +69,7 @@ public ServerEndPoint(ConnectionMultiplexer multiplexer, EndPoint endpoint, Text
public
int
Databases
{
get
{
return
databases
;
}
set
{
SetConfig
(
ref
databases
,
value
);
}
}
public
EndPoint
EndPoint
=>
endpoint
;
public
EndPoint
EndPoint
{
get
;
}
public
bool
HasDatabases
=>
serverType
==
ServerType
.
Standalone
;
...
...
@@ -130,7 +128,8 @@ public long OperationCount
public
Version
Version
{
get
{
return
version
;
}
set
{
SetConfig
(
ref
version
,
value
);
}
}
public
int
WriteEverySeconds
{
get
{
return
writeEverySeconds
;
}
set
{
SetConfig
(
ref
writeEverySeconds
,
value
);
}
}
internal
ConnectionMultiplexer
Multiplexer
=>
multiplexer
;
internal
ConnectionMultiplexer
Multiplexer
{
get
;
}
public
void
ClearUnselectable
(
UnselectableFlags
flags
)
{
...
...
@@ -140,7 +139,7 @@ public void ClearUnselectable(UnselectableFlags flags)
unselectableReasons
&=
~
flags
;
if
(
unselectableReasons
!=
oldFlags
)
{
m
ultiplexer
.
Trace
(
unselectableReasons
==
0
?
"Now usable"
:
(
"Now unusable: "
+
flags
),
ToString
());
M
ultiplexer
.
Trace
(
unselectableReasons
==
0
?
"Now usable"
:
(
"Now unusable: "
+
flags
),
ToString
());
}
}
}
...
...
@@ -196,9 +195,9 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
if
(
configuration
!=
null
)
{
m
ultiplexer
.
Trace
(
"Updating cluster ranges..."
);
m
ultiplexer
.
UpdateClusterRange
(
configuration
);
m
ultiplexer
.
Trace
(
"Resolving genealogy..."
);
M
ultiplexer
.
Trace
(
"Updating cluster ranges..."
);
M
ultiplexer
.
UpdateClusterRange
(
configuration
);
M
ultiplexer
.
Trace
(
"Resolving genealogy..."
);
var
thisNode
=
configuration
.
Nodes
.
FirstOrDefault
(
x
=>
x
.
EndPoint
.
Equals
(
EndPoint
));
if
(
thisNode
!=
null
)
{
...
...
@@ -208,17 +207,17 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
{
if
(
node
.
NodeId
==
thisNode
.
ParentNodeId
)
{
master
=
m
ultiplexer
.
GetServerEndPoint
(
node
.
EndPoint
);
master
=
M
ultiplexer
.
GetServerEndPoint
(
node
.
EndPoint
);
}
else
if
(
node
.
ParentNodeId
==
thisNode
.
NodeId
)
{
(
slaves
??
(
slaves
=
new
List
<
ServerEndPoint
>())).
Add
(
m
ultiplexer
.
GetServerEndPoint
(
node
.
EndPoint
));
(
slaves
??
(
slaves
=
new
List
<
ServerEndPoint
>())).
Add
(
M
ultiplexer
.
GetServerEndPoint
(
node
.
EndPoint
));
}
}
Master
=
master
;
Slaves
=
slaves
?.
ToArray
()
??
NoSlaves
;
}
m
ultiplexer
.
Trace
(
"Cluster configured"
);
M
ultiplexer
.
Trace
(
"Cluster configured"
);
}
}
...
...
@@ -230,7 +229,7 @@ public void SetUnselectable(UnselectableFlags flags)
unselectableReasons
|=
flags
;
if
(
unselectableReasons
!=
oldFlags
)
{
m
ultiplexer
.
Trace
(
unselectableReasons
==
0
?
"Now usable"
:
(
"Now unusable: "
+
flags
),
ToString
());
M
ultiplexer
.
Trace
(
unselectableReasons
==
0
?
"Now usable"
:
(
"Now unusable: "
+
flags
),
ToString
());
}
}
}
...
...
@@ -261,7 +260,7 @@ internal void AutoConfigure(PhysicalConnection connection)
return
;
}
var
commandMap
=
m
ultiplexer
.
CommandMap
;
var
commandMap
=
M
ultiplexer
.
CommandMap
;
const
CommandFlags
flags
=
CommandFlags
.
FireAndForget
|
CommandFlags
.
HighPriority
|
CommandFlags
.
NoRedirect
;
var
features
=
GetFeatures
();
...
...
@@ -269,7 +268,7 @@ internal void AutoConfigure(PhysicalConnection connection)
if
(
commandMap
.
IsAvailable
(
RedisCommand
.
CONFIG
))
{
if
(
m
ultiplexer
.
RawConfig
.
KeepAlive
<=
0
)
if
(
M
ultiplexer
.
RawConfig
.
KeepAlive
<=
0
)
{
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
CONFIG
,
RedisLiterals
.
GET
,
RedisLiterals
.
timeout
);
msg
.
SetInternalCall
();
...
...
@@ -325,7 +324,7 @@ internal void AutoConfigure(PhysicalConnection connection)
internal
Task
Close
()
{
var
tmp
=
interactive
;
if
(
tmp
==
null
||
!
tmp
.
IsConnected
||
!
m
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
QUIT
))
if
(
tmp
==
null
||
!
tmp
.
IsConnected
||
!
M
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
QUIT
))
{
return
CompletedTask
<
bool
>.
Default
(
null
);
}
...
...
@@ -362,7 +361,7 @@ internal string RunId
internal
ServerCounters
GetCounters
()
{
var
counters
=
new
ServerCounters
(
endp
oint
);
var
counters
=
new
ServerCounters
(
EndP
oint
);
interactive
?.
GetCounters
(
counters
.
Interactive
);
subscription
?.
GetCounters
(
counters
.
Subscription
);
return
counters
;
...
...
@@ -416,12 +415,12 @@ internal Message GetTracerMessage(bool assertIdentity)
// we'll do the best with what we have available.
// note that the muxer-ctor asserts that one of ECHO, PING, TIME of GET is available
// see also: TracerProcessor
var
map
=
m
ultiplexer
.
CommandMap
;
var
map
=
M
ultiplexer
.
CommandMap
;
Message
msg
;
const
CommandFlags
flags
=
CommandFlags
.
NoRedirect
|
CommandFlags
.
FireAndForget
;
if
(
assertIdentity
&&
map
.
IsAvailable
(
RedisCommand
.
ECHO
))
{
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
(
RedisValue
)
m
ultiplexer
.
UniqueId
);
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
(
RedisValue
)
M
ultiplexer
.
UniqueId
);
}
else
if
(
map
.
IsAvailable
(
RedisCommand
.
PING
))
{
...
...
@@ -434,12 +433,12 @@ internal Message GetTracerMessage(bool assertIdentity)
else
if
(!
assertIdentity
&&
map
.
IsAvailable
(
RedisCommand
.
ECHO
))
{
// we'll use echo as a PING substitute if it is all we have (in preference to EXISTS)
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
(
RedisValue
)
m
ultiplexer
.
UniqueId
);
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
(
RedisValue
)
M
ultiplexer
.
UniqueId
);
}
else
{
map
.
AssertAvailable
(
RedisCommand
.
EXISTS
);
msg
=
Message
.
Create
(
0
,
flags
,
RedisCommand
.
EXISTS
,
(
RedisValue
)
m
ultiplexer
.
UniqueId
);
msg
=
Message
.
Create
(
0
,
flags
,
RedisCommand
.
EXISTS
,
(
RedisValue
)
M
ultiplexer
.
UniqueId
);
}
msg
.
SetInternalCall
();
return
msg
;
...
...
@@ -472,9 +471,9 @@ internal void OnFullyEstablished(PhysicalConnection connection)
var
bridge
=
connection
.
Bridge
;
if
(
bridge
==
subscription
)
{
m
ultiplexer
.
ResendSubscriptions
(
this
);
M
ultiplexer
.
ResendSubscriptions
(
this
);
}
multiplexer
.
OnConnectionRestored
(
endp
oint
,
bridge
.
ConnectionType
);
Multiplexer
.
OnConnectionRestored
(
EndP
oint
,
bridge
.
ConnectionType
);
}
catch
(
Exception
ex
)
{
...
...
@@ -498,7 +497,7 @@ internal bool CheckInfoReplication()
{
lastInfoReplicationCheckTicks
=
Environment
.
TickCount
;
PhysicalBridge
bridge
;
if
(
version
>=
RedisFeatures
.
v2_8_0
&&
m
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
INFO
)
if
(
version
>=
RedisFeatures
.
v2_8_0
&&
M
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
INFO
)
&&
(
bridge
=
GetBridge
(
ConnectionType
.
Interactive
,
false
))
!=
null
)
{
var
msg
=
Message
.
Create
(-
1
,
CommandFlags
.
FireAndForget
|
CommandFlags
.
HighPriority
|
CommandFlags
.
NoRedirect
,
RedisCommand
.
INFO
,
RedisLiterals
.
replication
);
...
...
@@ -524,7 +523,7 @@ internal void OnHeartbeat()
}
catch
(
Exception
ex
)
{
m
ultiplexer
.
OnInternalError
(
ex
,
EndPoint
);
M
ultiplexer
.
OnInternalError
(
ex
,
EndPoint
);
}
finally
{
...
...
@@ -541,7 +540,7 @@ internal Task<T> QueueDirectAsync<T>(Message message, ResultProcessor<T> process
if
(
bridge
==
null
)
bridge
=
GetBridge
(
message
.
Command
);
if
(!
bridge
.
TryEnqueue
(
message
,
isSlave
))
{
ConnectionMultiplexer
.
ThrowFailed
(
tcs
,
ExceptionFactory
.
NoConnectionAvailable
(
multiplexer
.
IncludeDetailInExceptions
,
multiplexer
.
IncludePerformanceCountersInExceptions
,
message
.
Command
,
message
,
this
,
m
ultiplexer
.
GetServerSnapshot
()));
ConnectionMultiplexer
.
ThrowFailed
(
tcs
,
ExceptionFactory
.
NoConnectionAvailable
(
Multiplexer
.
IncludeDetailInExceptions
,
Multiplexer
.
IncludePerformanceCountersInExceptions
,
message
.
Command
,
message
,
this
,
M
ultiplexer
.
GetServerSnapshot
()));
}
return
tcs
.
Task
;
}
...
...
@@ -551,7 +550,7 @@ internal void QueueDirectFireAndForget<T>(Message message, ResultProcessor<T> pr
if
(
message
!=
null
)
{
message
.
SetSource
(
processor
,
null
);
m
ultiplexer
.
Trace
(
"Enqueue: "
+
message
);
M
ultiplexer
.
Trace
(
"Enqueue: "
+
message
);
(
bridge
??
GetBridge
(
message
.
Command
)).
TryEnqueue
(
message
,
isSlave
);
}
}
...
...
@@ -571,7 +570,7 @@ internal Task<bool> SendTracer(TextWriter log = null)
internal
string
Summary
()
{
var
sb
=
new
StringBuilder
(
Format
.
ToString
(
endp
oint
))
var
sb
=
new
StringBuilder
(
Format
.
ToString
(
EndP
oint
))
.
Append
(
": "
).
Append
(
serverType
).
Append
(
" v"
).
Append
(
version
).
Append
(
", "
).
Append
(
isSlave
?
"slave"
:
"master"
);
if
(
databases
>
0
)
sb
.
Append
(
"; "
).
Append
(
databases
).
Append
(
" databases"
);
...
...
@@ -609,12 +608,12 @@ internal void WriteDirectOrQueueFireAndForget<T>(PhysicalConnection connection,
message
.
SetSource
(
processor
,
null
);
if
(
connection
==
null
)
{
m
ultiplexer
.
Trace
(
"Enqueue: "
+
message
);
M
ultiplexer
.
Trace
(
"Enqueue: "
+
message
);
GetBridge
(
message
.
Command
).
TryEnqueue
(
message
,
isSlave
);
}
else
{
m
ultiplexer
.
Trace
(
"Writing direct: "
+
message
);
M
ultiplexer
.
Trace
(
"Writing direct: "
+
message
);
connection
.
Bridge
.
WriteMessageDirect
(
connection
,
message
);
}
}
...
...
@@ -622,7 +621,7 @@ internal void WriteDirectOrQueueFireAndForget<T>(PhysicalConnection connection,
private
PhysicalBridge
CreateBridge
(
ConnectionType
type
,
TextWriter
log
)
{
m
ultiplexer
.
Trace
(
type
.
ToString
());
M
ultiplexer
.
Trace
(
type
.
ToString
());
var
bridge
=
new
PhysicalBridge
(
this
,
type
);
bridge
.
TryConnect
(
log
);
return
bridge
;
...
...
@@ -630,30 +629,30 @@ private PhysicalBridge CreateBridge(ConnectionType type, TextWriter log)
private
void
Handshake
(
PhysicalConnection
connection
,
TextWriter
log
)
{
m
ultiplexer
.
LogLocked
(
log
,
"Server handshake"
);
M
ultiplexer
.
LogLocked
(
log
,
"Server handshake"
);
if
(
connection
==
null
)
{
m
ultiplexer
.
Trace
(
"No connection!?"
);
M
ultiplexer
.
Trace
(
"No connection!?"
);
return
;
}
Message
msg
;
string
password
=
m
ultiplexer
.
RawConfig
.
Password
;
string
password
=
M
ultiplexer
.
RawConfig
.
Password
;
if
(!
string
.
IsNullOrWhiteSpace
(
password
))
{
m
ultiplexer
.
LogLocked
(
log
,
"Authenticating (password)"
);
M
ultiplexer
.
LogLocked
(
log
,
"Authenticating (password)"
);
msg
=
Message
.
Create
(-
1
,
CommandFlags
.
FireAndForget
,
RedisCommand
.
AUTH
,
(
RedisValue
)
password
);
msg
.
SetInternalCall
();
WriteDirectOrQueueFireAndForget
(
connection
,
msg
,
ResultProcessor
.
DemandOK
);
}
if
(
m
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
CLIENT
))
if
(
M
ultiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
CLIENT
))
{
string
name
=
m
ultiplexer
.
ClientName
;
string
name
=
M
ultiplexer
.
ClientName
;
if
(!
string
.
IsNullOrWhiteSpace
(
name
))
{
name
=
nameSanitizer
.
Replace
(
name
,
""
);
if
(!
string
.
IsNullOrWhiteSpace
(
name
))
{
m
ultiplexer
.
LogLocked
(
log
,
"Setting client name: {0}"
,
name
);
M
ultiplexer
.
LogLocked
(
log
,
"Setting client name: {0}"
,
name
);
msg
=
Message
.
Create
(-
1
,
CommandFlags
.
FireAndForget
,
RedisCommand
.
CLIENT
,
RedisLiterals
.
SETNAME
,
(
RedisValue
)
name
);
msg
.
SetInternalCall
();
WriteDirectOrQueueFireAndForget
(
connection
,
msg
,
ResultProcessor
.
DemandOK
);
...
...
@@ -665,10 +664,10 @@ private void Handshake(PhysicalConnection connection, TextWriter log)
if
(
connType
==
ConnectionType
.
Interactive
)
{
m
ultiplexer
.
LogLocked
(
log
,
"Auto-configure..."
);
M
ultiplexer
.
LogLocked
(
log
,
"Auto-configure..."
);
AutoConfigure
(
connection
);
}
m
ultiplexer
.
LogLocked
(
log
,
"Sending critical tracer: {0}"
,
connection
.
Bridge
);
M
ultiplexer
.
LogLocked
(
log
,
"Sending critical tracer: {0}"
,
connection
.
Bridge
);
var
tracer
=
GetTracerMessage
(
true
);
tracer
=
LoggingMessage
.
Create
(
log
,
tracer
);
WriteDirectOrQueueFireAndForget
(
connection
,
tracer
,
ResultProcessor
.
EstablishConnection
);
...
...
@@ -677,14 +676,14 @@ private void Handshake(PhysicalConnection connection, TextWriter log)
// we will be in subscriber mode: regular commands cannot be sent
if
(
connType
==
ConnectionType
.
Subscription
)
{
var
configChannel
=
m
ultiplexer
.
ConfigurationChangedChannel
;
var
configChannel
=
M
ultiplexer
.
ConfigurationChangedChannel
;
if
(
configChannel
!=
null
)
{
msg
=
Message
.
Create
(-
1
,
CommandFlags
.
FireAndForget
,
RedisCommand
.
SUBSCRIBE
,
(
RedisChannel
)
configChannel
);
WriteDirectOrQueueFireAndForget
(
connection
,
msg
,
ResultProcessor
.
TrackSubscriptions
);
}
}
m
ultiplexer
.
LogLocked
(
log
,
"Flushing outbound buffer"
);
M
ultiplexer
.
LogLocked
(
log
,
"Flushing outbound buffer"
);
connection
.
Flush
();
}
...
...
@@ -692,9 +691,9 @@ private void SetConfig<T>(ref T field, T value, [CallerMemberName] string caller
{
if
(!
EqualityComparer
<
T
>.
Default
.
Equals
(
field
,
value
))
{
m
ultiplexer
.
Trace
(
caller
+
" changed from "
+
field
+
" to "
+
value
,
"Configuration"
);
M
ultiplexer
.
Trace
(
caller
+
" changed from "
+
field
+
" to "
+
value
,
"Configuration"
);
field
=
value
;
multiplexer
.
ReconfigureIfNeeded
(
endp
oint
,
false
,
caller
);
Multiplexer
.
ReconfigureIfNeeded
(
EndP
oint
,
false
,
caller
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment