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
7e06b342
Commit
7e06b342
authored
Mar 11, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: ServerEndPoint
parent
05554dd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
47 deletions
+19
-47
ServerEndPoint.cs
StackExchange.Redis/StackExchange/Redis/ServerEndPoint.cs
+19
-47
No files found.
StackExchange.Redis/StackExchange/Redis/ServerEndPoint.cs
View file @
7e06b342
...
...
@@ -19,7 +19,6 @@ internal enum UnselectableFlags
RedundantMaster
=
1
,
DidNotRespond
=
2
,
ServerType
=
4
}
internal
sealed
partial
class
ServerEndPoint
:
IDisposable
...
...
@@ -30,30 +29,23 @@ internal sealed partial class ServerEndPoint : IDisposable
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
;
bool
isDisposed
;
ServerType
serverType
;
private
bool
isDisposed
;
private
ServerType
serverType
;
private
bool
slaveReadOnly
,
isSlave
;
private
volatile
UnselectableFlags
unselectableReasons
;
private
Version
version
;
internal
void
ResetNonConnected
()
{
interactive
?.
ResetNonConnected
();
subscription
?.
ResetNonConnected
();
}
public
ServerEndPoint
(
ConnectionMultiplexer
multiplexer
,
EndPoint
endpoint
,
TextWriter
log
)
{
this
.
multiplexer
=
multiplexer
;
...
...
@@ -83,14 +75,7 @@ public ServerEndPoint(ConnectionMultiplexer multiplexer, EndPoint endpoint, Text
public
bool
HasDatabases
=>
serverType
==
ServerType
.
Standalone
;
public
bool
IsConnected
{
get
{
var
tmp
=
interactive
;
return
tmp
!=
null
&&
tmp
.
IsConnected
;
}
}
public
bool
IsConnected
=>
interactive
?.
IsConnected
==
true
;
internal
Exception
LastException
{
...
...
@@ -100,12 +85,9 @@ internal Exception LastException
var
tmp2
=
subscription
;
//check if subscription endpoint has a better lastexception
if
(
tmp2
!=
null
&&
tmp2
.
LastException
!=
null
)
if
(
tmp2
?.
LastException
!=
null
&&
tmp2
.
LastException
.
Data
.
Contains
(
"Redis-FailureType"
)
&&
!
tmp2
.
LastException
.
Data
[
"Redis-FailureType"
].
ToString
().
Equals
(
nameof
(
ConnectionFailureType
.
UnableToConnect
))
)
{
if
(
tmp2
.
LastException
.
Data
.
Contains
(
"Redis-FailureType"
)
&&
!
tmp2
.
LastException
.
Data
[
"Redis-FailureType"
].
ToString
().
Equals
(
ConnectionFailureType
.
UnableToConnect
.
ToString
()))
{
return
tmp2
.
LastException
;
}
return
tmp2
.
LastException
;
}
return
tmp1
?.
LastException
;
}
...
...
@@ -185,6 +167,7 @@ public PhysicalBridge GetBridge(ConnectionType type, bool create = true, TextWri
}
return
null
;
}
public
PhysicalBridge
GetBridge
(
RedisCommand
command
,
bool
create
=
true
)
{
if
(
isDisposed
)
return
null
;
...
...
@@ -207,7 +190,6 @@ public RedisFeatures GetFeatures()
public
void
SetClusterConfiguration
(
ClusterConfiguration
configuration
)
{
ClusterConfiguration
=
configuration
;
if
(
configuration
!=
null
)
...
...
@@ -251,16 +233,10 @@ public void SetUnselectable(UnselectableFlags flags)
}
}
}
public
override
string
ToString
()
{
return
Format
.
ToString
(
EndPoint
);
}
public
bool
TryEnqueue
(
Message
message
)
{
var
bridge
=
GetBridge
(
message
.
Command
);
return
bridge
!=
null
&&
bridge
.
TryEnqueue
(
message
,
isSlave
);
}
public
override
string
ToString
()
=>
Format
.
ToString
(
EndPoint
);
public
bool
TryEnqueue
(
Message
message
)
=>
GetBridge
(
message
.
Command
)?.
TryEnqueue
(
message
,
isSlave
)
==
true
;
internal
void
Activate
(
ConnectionType
type
,
TextWriter
log
)
{
...
...
@@ -341,23 +317,21 @@ internal void AutoConfigure(PhysicalConnection connection)
}
}
int
_nextReplicaOffset
;
private
int
_nextReplicaOffset
;
internal
uint
NextReplicaOffset
()
// used to round-robin between multiple replicas
=>
(
uint
)
System
.
Threading
.
Interlocked
.
Increment
(
ref
_nextReplicaOffset
);
internal
Task
Close
()
{
var
tmp
=
interactive
;
Task
result
;
if
(
tmp
==
null
||
!
tmp
.
IsConnected
||
!
multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
QUIT
))
{
re
sult
=
CompletedTask
<
bool
>.
Default
(
null
);
re
turn
CompletedTask
<
bool
>.
Default
(
null
);
}
else
{
re
sult
=
QueueDirectAsync
(
Message
.
Create
(-
1
,
CommandFlags
.
None
,
RedisCommand
.
QUIT
),
ResultProcessor
.
DemandOK
,
bridge
:
interactive
);
re
turn
QueueDirectAsync
(
Message
.
Create
(-
1
,
CommandFlags
.
None
,
RedisCommand
.
QUIT
),
ResultProcessor
.
DemandOK
,
bridge
:
interactive
);
}
return
result
;
}
internal
void
FlushScriptCache
()
...
...
@@ -473,7 +447,7 @@ internal Message GetTracerMessage(bool assertIdentity)
internal
bool
IsSelectable
(
RedisCommand
command
)
{
var
bridge
=
unselectableReasons
==
0
?
GetBridge
(
command
,
false
)
:
null
;
return
bridge
!=
null
&&
bridge
.
IsConnected
;
return
bridge
?.
IsConnected
==
true
;
}
internal
void
OnEstablishing
(
PhysicalConnection
connection
,
TextWriter
log
)
...
...
@@ -506,7 +480,7 @@ internal void OnFullyEstablished(PhysicalConnection connection)
connection
.
RecordConnectionFailed
(
ConnectionFailureType
.
InternalFailure
,
ex
);
}
}
internal
int
LastInfoReplicationCheckSecondsAgo
{
get
{
return
unchecked
(
Environment
.
TickCount
-
VolatileWrapper
.
Read
(
ref
lastInfoReplicationCheckTicks
))
/
1000
;
}
...
...
@@ -519,7 +493,6 @@ public EndPoint MasterEndPoint
set
{
SetConfig
(
ref
masterEndPoint
,
value
);
}
}
internal
bool
CheckInfoReplication
()
{
lastInfoReplicationCheckTicks
=
Environment
.
TickCount
;
...
...
@@ -534,6 +507,7 @@ internal bool CheckInfoReplication()
}
return
false
;
}
private
int
lastInfoReplicationCheckTicks
;
private
int
_heartBeatActive
;
...
...
@@ -544,8 +518,6 @@ internal void OnHeartbeat()
{
try
{
interactive
?.
OnHeartbeat
(
false
);
subscription
?.
OnHeartbeat
(
false
);
}
...
...
@@ -600,7 +572,6 @@ internal string Summary()
{
var
sb
=
new
StringBuilder
(
Format
.
ToString
(
endpoint
))
.
Append
(
": "
).
Append
(
serverType
).
Append
(
" v"
).
Append
(
version
).
Append
(
", "
).
Append
(
isSlave
?
"slave"
:
"master"
);
if
(
databases
>
0
)
sb
.
Append
(
"; "
).
Append
(
databases
).
Append
(
" databases"
);
if
(
writeEverySeconds
>
0
)
...
...
@@ -628,6 +599,7 @@ internal string Summary()
}
return
sb
.
ToString
();
}
internal
void
WriteDirectOrQueueFireAndForget
<
T
>(
PhysicalConnection
connection
,
Message
message
,
ResultProcessor
<
T
>
processor
)
{
if
(
message
!=
null
)
...
...
@@ -653,7 +625,8 @@ private PhysicalBridge CreateBridge(ConnectionType type, TextWriter log)
bridge
.
TryConnect
(
log
);
return
bridge
;
}
void
Handshake
(
PhysicalConnection
connection
,
TextWriter
log
)
private
void
Handshake
(
PhysicalConnection
connection
,
TextWriter
log
)
{
multiplexer
.
LogLocked
(
log
,
"Server handshake"
);
if
(
connection
==
null
)
...
...
@@ -698,7 +671,6 @@ void Handshake(PhysicalConnection connection, TextWriter log)
tracer
=
LoggingMessage
.
Create
(
log
,
tracer
);
WriteDirectOrQueueFireAndForget
(
connection
,
tracer
,
ResultProcessor
.
EstablishConnection
);
// note: this **must** be the last thing on the subscription handshake, because after this
// we will be in subscriber mode: regular commands cannot be sent
if
(
connType
==
ConnectionType
.
Subscription
)
...
...
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