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
c53b619c
Commit
c53b619c
authored
Dec 10, 2015
by
Marc Gravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:StackExchange/StackExchange.Redis into jeremymeng-netcore
parents
e9f3d204
98dbfd4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
2 deletions
+47
-2
ClusterConfiguration.cs
...xchange.Redis/StackExchange/Redis/ClusterConfiguration.cs
+47
-2
No files found.
StackExchange.Redis/StackExchange/Redis/ClusterConfiguration.cs
View file @
c53b619c
...
...
@@ -172,6 +172,7 @@ public sealed class ClusterConfiguration
private
readonly
ServerSelectionStrategy
serverSelectionStrategy
;
internal
ClusterConfiguration
(
ServerSelectionStrategy
serverSelectionStrategy
,
string
nodes
,
EndPoint
origin
)
{
// Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls
this
.
serverSelectionStrategy
=
serverSelectionStrategy
;
this
.
origin
=
origin
;
using
(
var
reader
=
new
StringReader
(
nodes
))
...
...
@@ -180,9 +181,36 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
while
((
line
=
reader
.
ReadLine
())
!=
null
)
{
if
(
string
.
IsNullOrWhiteSpace
(
line
))
continue
;
var
node
=
new
ClusterNode
(
this
,
line
,
origin
);
nodeLookup
.
Add
(
node
.
EndPoint
,
node
);
// Be resilient to ":0 {master,slave},fail,noaddr" nodes
if
(
node
.
IsNoAddr
)
continue
;
if
(
nodeLookup
.
ContainsKey
(
node
.
EndPoint
))
{
// Deal with conflicting node entries for the same endpoint
// This can happen in dynamic environments when a node goes down and a new one is created
// to replace it.
if
(!
node
.
IsConnected
)
{
// The node we're trying to add is probably about to become stale. Ignore it.
continue
;
}
else
if
(!
nodeLookup
[
node
.
EndPoint
].
IsConnected
)
{
// The node we registered previously is probably stale. Replace it with a known good node.
nodeLookup
[
node
.
EndPoint
]
=
node
;
}
else
{
// We have conflicting connected nodes. There's nothing much we can do other than
// wait for the cluster state to converge and refresh on the next pass.
// The same is true if we have multiple disconnected nodes.
}
}
else
{
nodeLookup
.
Add
(
node
.
EndPoint
,
node
);
}
}
}
}
...
...
@@ -262,6 +290,10 @@ public sealed class ClusterNode : IEquatable<ClusterNode>, IComparable<ClusterN
private
readonly
bool
isSlave
;
private
readonly
bool
isNoAddr
;
private
readonly
bool
isConnected
;
private
readonly
string
nodeId
,
parentNodeId
,
raw
;
private
readonly
IList
<
SlotRange
>
slots
;
...
...
@@ -275,6 +307,7 @@ public sealed class ClusterNode : IEquatable<ClusterNode>, IComparable<ClusterN
internal
ClusterNode
()
{
}
internal
ClusterNode
(
ClusterConfiguration
configuration
,
string
raw
,
EndPoint
origin
)
{
// http://redis.io/commands/cluster-nodes
this
.
configuration
=
configuration
;
this
.
raw
=
raw
;
var
parts
=
raw
.
Split
(
StringSplits
.
Space
);
...
...
@@ -285,6 +318,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
nodeId
=
parts
[
0
];
isSlave
=
flags
.
Contains
(
"slave"
);
isNoAddr
=
flags
.
Contains
(
"noaddr"
);
parentNodeId
=
string
.
IsNullOrWhiteSpace
(
parts
[
3
])
?
null
:
parts
[
3
];
List
<
SlotRange
>
slots
=
null
;
...
...
@@ -299,6 +333,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
}
}
this
.
slots
=
slots
==
null
?
NoSlots
:
slots
.
AsReadOnly
();
this
.
isConnected
=
parts
[
7
]
==
"connected"
;
// Can be "connected" or "disconnected"
}
/// <summary>
/// Gets all child nodes of the current node
...
...
@@ -333,6 +368,16 @@ public IList<ClusterNode> Children
/// </summary>
public
bool
IsSlave
{
get
{
return
isSlave
;
}
}
/// <summary>
/// Gets whether this node is flagged as noaddr
/// </summary>
public
bool
IsNoAddr
{
get
{
return
isNoAddr
;
}
}
/// <summary>
/// Gets the node's connection status
/// </summary>
public
bool
IsConnected
{
get
{
return
isConnected
;
}
}
/// <summary>
/// Gets the unique node-id of the current node
/// </summary>
...
...
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