Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
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
exchain
nebula
Commits
7b933391
Commit
7b933391
authored
Sep 14, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
release lock on errors, validate if local is behind remote before acquiring the lock
parent
b15fe51a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
6 deletions
+33
-6
consensus_tracker.go
proxyd/consensus_tracker.go
+33
-6
No files found.
proxyd/consensus_tracker.go
View file @
7b933391
...
...
@@ -52,6 +52,18 @@ func NewInMemoryConsensusTracker() ConsensusTracker {
}
}
func
(
ct
*
InMemoryConsensusTracker
)
Valid
()
bool
{
return
ct
.
GetLatestBlockNumber
()
>
0
&&
ct
.
GetSafeBlockNumber
()
>
0
&&
ct
.
GetFinalizedBlockNumber
()
>
0
}
func
(
ct
*
InMemoryConsensusTracker
)
Behind
(
other
*
InMemoryConsensusTracker
)
bool
{
return
ct
.
GetLatestBlockNumber
()
<
other
.
GetLatestBlockNumber
()
||
ct
.
GetSafeBlockNumber
()
<
other
.
GetSafeBlockNumber
()
||
ct
.
GetFinalizedBlockNumber
()
<
other
.
GetFinalizedBlockNumber
()
}
func
(
ct
*
InMemoryConsensusTracker
)
GetLatestBlockNumber
()
hexutil
.
Uint64
{
defer
ct
.
mutex
.
Unlock
()
ct
.
mutex
.
Lock
()
...
...
@@ -179,8 +191,15 @@ func (ct *RedisConsensusTracker) stateHeartbeat() {
val
,
err
:=
ct
.
client
.
Get
(
ct
.
ctx
,
key
)
.
Result
()
if
err
!=
nil
&&
err
!=
redis
.
Nil
{
log
.
Error
(
"failed to read the mutex"
,
"err"
,
err
)
log
.
Error
(
"failed to read the lock"
,
"err"
,
err
)
if
ct
.
leader
{
ok
,
err
:=
ct
.
redlock
.
Unlock
()
if
err
!=
nil
||
!
ok
{
log
.
Error
(
"failed to release the lock after error"
,
"err"
,
err
)
return
}
ct
.
leader
=
false
}
return
}
if
val
!=
""
{
...
...
@@ -189,6 +208,11 @@ func (ct *RedisConsensusTracker) stateHeartbeat() {
ok
,
err
:=
ct
.
redlock
.
Extend
()
if
err
!=
nil
||
!
ok
{
log
.
Error
(
"failed to extend lock"
,
"err"
,
err
,
"mutex"
,
ct
.
redlock
.
Name
(),
"val"
,
ct
.
redlock
.
Value
())
ok
,
err
:=
ct
.
redlock
.
Unlock
()
if
err
!=
nil
||
!
ok
{
log
.
Error
(
"failed to release the lock after error"
,
"err"
,
err
)
return
}
ct
.
leader
=
false
return
}
...
...
@@ -224,12 +248,15 @@ func (ct *RedisConsensusTracker) stateHeartbeat() {
log
.
Debug
(
"updated state from remote"
,
"state"
,
val
,
"leader"
,
leaderName
)
}
}
else
{
if
ct
.
local
.
GetLatestBlockNumber
()
==
0
||
ct
.
local
.
GetSafeBlockNumber
()
==
0
||
ct
.
local
.
GetFinalizedBlockNumber
()
==
0
{
log
.
Warn
(
"lock not found, but local state is missing, skipping"
)
if
!
ct
.
local
.
Valid
()
{
log
.
Warn
(
"local state is not valid or behind remote, skipping"
)
return
}
if
ct
.
remote
.
Valid
()
&&
ct
.
local
.
Behind
(
ct
.
remote
)
{
log
.
Warn
(
"local state is behind remote, skipping"
)
return
}
log
.
Info
(
"lock not found, creating a new one"
)
mutex
:=
rs
.
NewMutex
(
key
,
...
...
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