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
87d4dc84
Commit
87d4dc84
authored
Dec 01, 2015
by
hrishi18pathak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make auto discoverability of nodes synchronous, actually fix issue 300
parent
6b317395
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
103 deletions
+141
-103
ConnectionMultiplexer.cs
...change.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
+132
-103
EndPointCollection.cs
...kExchange.Redis/StackExchange/Redis/EndPointCollection.cs
+9
-0
No files found.
StackExchange.Redis/StackExchange/Redis/ConnectionMultiplexer.cs
View file @
87d4dc84
...
@@ -1203,11 +1203,31 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
...
@@ -1203,11 +1203,31 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
}
}
const
CommandFlags
flags
=
CommandFlags
.
NoRedirect
|
CommandFlags
.
HighPriority
;
const
CommandFlags
flags
=
CommandFlags
.
NoRedirect
|
CommandFlags
.
HighPriority
;
var
available
=
new
Task
<
bool
>[
endpoints
.
Count
];
List
<
ServerEndPoint
>
masters
=
new
List
<
ServerEndPoint
>(
endpoints
.
Count
);
var
servers
=
new
ServerEndPoint
[
available
.
Length
];
bool
useTieBreakers
=
!
string
.
IsNullOrWhiteSpace
(
configuration
.
TieBreaker
);
bool
useTieBreakers
=
!
string
.
IsNullOrWhiteSpace
(
configuration
.
TieBreaker
);
var
tieBreakers
=
useTieBreakers
?
new
Task
<
string
>[
endpoints
.
Count
]
:
null
;
ServerEndPoint
[]
servers
=
null
;
Task
<
string
>[]
tieBreakers
=
null
;
bool
encounteredConnectedServer
=
false
;
Stopwatch
watch
=
null
;
int
iterCount
=
first
?
2
:
1
;
// this is fix for https://github.com/StackExchange/StackExchange.Redis/issues/300
// auto discoverability of cluster nodes is made synchronous.
// we try to connect to endpoints specified inside the user provided configuration
// and when we encounter one such endpoint to which we are able to successfully connect,
// we get the list of cluster nodes from this endpoint and try to proactively connect
// to these nodes instead of relying on auto configure
for
(
int
iter
=
0
;
iter
<
iterCount
;
++
iter
)
{
if
(
endpoints
==
null
)
break
;
var
available
=
new
Task
<
bool
>[
endpoints
.
Count
];
tieBreakers
=
useTieBreakers
?
new
Task
<
string
>[
endpoints
.
Count
]
:
null
;
servers
=
new
ServerEndPoint
[
available
.
Length
];
RedisKey
tieBreakerKey
=
useTieBreakers
?
(
RedisKey
)
configuration
.
TieBreaker
:
default
(
RedisKey
);
RedisKey
tieBreakerKey
=
useTieBreakers
?
(
RedisKey
)
configuration
.
TieBreaker
:
default
(
RedisKey
);
for
(
int
i
=
0
;
i
<
available
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
available
.
Length
;
i
++)
{
{
Trace
(
"Testing: "
+
Format
.
ToString
(
endpoints
[
i
]));
Trace
(
"Testing: "
+
Format
.
ToString
(
endpoints
[
i
]));
...
@@ -1232,11 +1252,13 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
...
@@ -1232,11 +1252,13 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
}
}
}
}
LogLocked
(
log
,
"Allowing endpoints {0} to respond..."
,
TimeSpan
.
FromMilliseconds
(
configuration
.
ConnectTimeout
));
watch
=
watch
??
Stopwatch
.
StartNew
();
Trace
(
"Allowing endpoints "
+
TimeSpan
.
FromMilliseconds
(
configuration
.
ConnectTimeout
)
+
" to respond..."
);
var
remaining
=
configuration
.
ConnectTimeout
-
checked
((
int
)
watch
.
ElapsedMilliseconds
);
await
WaitAllIgnoreErrorsAsync
(
available
,
configuration
.
ConnectTimeout
,
log
).
ForAwait
();
LogLocked
(
log
,
"Allowing endpoints {0} to respond..."
,
TimeSpan
.
FromMilliseconds
(
remaining
));
List
<
ServerEndPoint
>
masters
=
new
List
<
ServerEndPoint
>(
available
.
Length
);
Trace
(
"Allowing endpoints "
+
TimeSpan
.
FromMilliseconds
(
remaining
)
+
" to respond..."
);
await
WaitAllIgnoreErrorsAsync
(
available
,
remaining
,
log
).
ForAwait
();
EndPointCollection
updatedEndpointCollection
=
null
;
for
(
int
i
=
0
;
i
<
available
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
available
.
Length
;
i
++)
{
{
var
task
=
available
[
i
];
var
task
=
available
[
i
];
...
@@ -1263,7 +1285,14 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
...
@@ -1263,7 +1285,14 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
{
{
servers
[
i
].
ClearUnselectable
(
UnselectableFlags
.
DidNotRespond
);
servers
[
i
].
ClearUnselectable
(
UnselectableFlags
.
DidNotRespond
);
LogLocked
(
log
,
"{0} returned with success"
,
Format
.
ToString
(
endpoints
[
i
]));
LogLocked
(
log
,
"{0} returned with success"
,
Format
.
ToString
(
endpoints
[
i
]));
UpdateClusterConfigIfNeeded
(
server
,
log
);
if
(!
encounteredConnectedServer
)
{
// we have encountered a connected server for the first time.
// so we will get list of other nodes from this server using "CLUSTER NODES" command
// and try to connect to these other nodes in the next iteration
encounteredConnectedServer
=
true
;
updatedEndpointCollection
=
GetEndpointsFromClusterNodes
(
server
,
log
);
}
// count the server types
// count the server types
switch
(
server
.
ServerType
)
switch
(
server
.
ServerType
)
{
{
...
@@ -1314,6 +1343,16 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
...
@@ -1314,6 +1343,16 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
}
}
}
}
if
(
encounteredConnectedServer
)
{
endpoints
=
updatedEndpointCollection
;
}
else
{
break
;
// will be retried by the outer do while loop
}
}
if
(
clusterCount
==
0
)
if
(
clusterCount
==
0
)
{
{
// set the serverSelectionStrategy
// set the serverSelectionStrategy
...
@@ -1419,33 +1458,23 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
...
@@ -1419,33 +1458,23 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, Text
}
}
}
}
private
void
UpdateClusterConfigIfNeeded
(
ServerEndPoint
server
,
TextWriter
log
)
private
EndPointCollection
GetEndpointsFromClusterNodes
(
ServerEndPoint
server
,
TextWriter
log
)
{
{
var
message
=
Message
.
Create
(-
1
,
CommandFlags
.
None
,
RedisCommand
.
CLUSTER
,
RedisLiterals
.
NODES
);
var
message
=
Message
.
Create
(-
1
,
CommandFlags
.
None
,
RedisCommand
.
CLUSTER
,
RedisLiterals
.
NODES
);
ClusterConfiguration
clusterConfig
=
null
;
ClusterConfiguration
clusterConfig
=
null
;
try
try
{
{
clusterConfig
=
this
.
ExecuteSyncImpl
(
message
,
ResultProcessor
.
ClusterNodes
,
server
);
clusterConfig
=
this
.
ExecuteSyncImpl
(
message
,
ResultProcessor
.
ClusterNodes
,
server
);
return
new
EndPointCollection
(
clusterConfig
.
Nodes
.
Select
(
node
=>
node
.
EndPoint
).
ToList
());
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
if
(
ex
.
Message
.
Contains
(
"ERR This instance has cluster support disabled"
))
{
LogLocked
(
log
,
"Cluster support disabled. Continuing without updating cluster config..."
);
return
;
}
LogLocked
(
log
,
"Encountered error while updating cluster config: "
+
ex
.
Message
);
LogLocked
(
log
,
"Encountered error while updating cluster config: "
+
ex
.
Message
);
}
return
null
;
if
(
clusterConfig
!=
null
)
{
this
.
UpdateClusterRange
(
clusterConfig
);
LogLocked
(
log
,
"Updated cluster config"
);
}
}
}
}
private
void
ResetAllNonConnected
()
private
void
ResetAllNonConnected
()
{
{
var
snapshot
=
serverSnapshot
;
var
snapshot
=
serverSnapshot
;
...
...
StackExchange.Redis/StackExchange/Redis/EndPointCollection.cs
View file @
87d4dc84
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Collections.ObjectModel
;
using
System.Net
;
using
System.Net
;
...
@@ -9,6 +10,14 @@ namespace StackExchange.Redis
...
@@ -9,6 +10,14 @@ namespace StackExchange.Redis
/// </summary>
/// </summary>
public
sealed
class
EndPointCollection
:
Collection
<
EndPoint
>
public
sealed
class
EndPointCollection
:
Collection
<
EndPoint
>
{
{
public
EndPointCollection
()
:
base
()
{
}
public
EndPointCollection
(
IList
<
EndPoint
>
endpoints
)
:
base
(
endpoints
)
{
}
/// <summary>
/// <summary>
/// Format an endpoint
/// Format an endpoint
/// </summary>
/// </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