Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
4f1db893
Commit
4f1db893
authored
4 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
fix mutex issues
parent
f4adc5c0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
network/gateway/hostPool.go
+30
-18
30 additions, 18 deletions
network/gateway/hostPool.go
with
30 additions
and
18 deletions
network/gateway/hostPool.go
+
30
−
18
View file @
4f1db893
...
...
@@ -139,11 +139,13 @@ func (h *HostPool) UpdateNdf(ndf *ndf.NetworkDefinition) {
// Obtain a random, unique list of Hosts of the given length from the HostPool
func
(
h
*
HostPool
)
getAny
(
length
uint32
,
excluded
[]
*
id
.
ID
)
[]
*
connect
.
Host
{
checked
:=
make
(
map
[
uint32
]
interface
{})
// Keep track of Hosts already selected to avoid duplicates
if
length
>
h
.
poolParams
.
PoolSize
{
length
=
h
.
poolParams
.
PoolSize
}
checked
:=
make
(
map
[
uint32
]
interface
{})
// Keep track of Hosts already selected to avoid duplicates
if
excluded
!=
nil
{
// Add excluded Hosts to already-checked list
for
i
:=
range
excluded
{
gwId
:=
excluded
[
i
]
if
idx
,
ok
:=
h
.
hostMap
[
*
gwId
];
ok
{
...
...
@@ -152,13 +154,19 @@ func (h *HostPool) getAny(length uint32, excluded []*id.ID) []*connect.Host {
}
}
result
:=
make
([]
*
connect
.
Host
,
length
)
result
:=
make
([]
*
connect
.
Host
,
0
,
length
)
rng
:=
h
.
rng
.
GetStream
()
h
.
hostMux
.
RLock
()
for
i
:=
uint32
(
0
);
i
<
length
;
{
// If we've checked the entire HostPool, bail
if
uint32
(
len
(
checked
))
>=
h
.
poolParams
.
PoolSize
{
break
}
// Check the next HostPool index
gwIdx
:=
readRangeUint32
(
0
,
h
.
poolParams
.
PoolSize
,
rng
)
if
_
,
ok
:=
checked
[
gwIdx
];
!
ok
{
result
[
i
]
=
h
.
hostList
[
gwIdx
]
result
=
append
(
result
,
h
.
hostList
[
gwIdx
]
)
checked
[
gwIdx
]
=
nil
i
++
}
...
...
@@ -208,10 +216,21 @@ func (h *HostPool) getPreferred(targets []*id.ID) []*connect.Host {
// Replaces the given hostId in the HostPool if the given hostErr is in errorList
func
(
h
*
HostPool
)
checkReplace
(
hostId
*
id
.
ID
,
hostErr
error
)
error
{
// Check if Host should be replaced
doReplace
:=
false
if
hostErr
!=
nil
{
for
_
,
errString
:=
range
errorsList
{
if
strings
.
Contains
(
hostErr
.
Error
(),
errString
)
{
// Host needs replaced, flag and continue
doReplace
=
true
break
}
}
}
if
doReplace
{
h
.
hostMux
.
Lock
()
defer
h
.
hostMux
.
Unlock
()
// If the Host is still in the pool
if
oldPoolIndex
,
ok
:=
h
.
hostMap
[
*
hostId
];
ok
{
...
...
@@ -219,15 +238,8 @@ func (h *HostPool) checkReplace(hostId *id.ID, hostErr error) error {
h
.
ndfMux
.
RLock
()
err
:=
h
.
forceReplace
(
oldPoolIndex
)
h
.
ndfMux
.
RUnlock
()
h
.
hostMux
.
Unlock
()
return
err
}
// If the Host is NOT still in the pool, return
h
.
hostMux
.
Unlock
()
return
nil
}
}
}
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment