Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
eos
QuarkDB
Commits
036c0fc2
Commit
036c0fc2
authored
Jun 22, 2018
by
Georgios Bitzes
Browse files
Refactor logic for maybeAdvanceClock
parent
d97fb0be
Pipeline
#423336
passed with stages
in 41 minutes and 58 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/StateMachine.cc
View file @
036c0fc2
...
...
@@ -1056,6 +1056,25 @@ void StateMachine::advanceClock(ClockValue newValue, LogIndex index) {
stagingArea
.
commit
(
index
);
}
ClockValue
StateMachine
::
maybeAdvanceClock
(
StagingArea
&
stagingArea
,
ClockValue
clockUpdate
)
{
// Get current clock time.
ClockValue
currentClock
;
getClock
(
stagingArea
,
currentClock
);
// Two cases:
// - currentClock is behind clockUpdate - should be by far the most common.
// Simply update currentClock to clockUpdate.
// - currentClock is ahead.. we were hit by a rare race condition. Advance
// clockUpdate to currentClock instead.
if
(
currentClock
<
clockUpdate
)
{
advanceClock
(
stagingArea
,
clockUpdate
);
return
clockUpdate
;
}
else
{
return
currentClock
;
}
}
void
StateMachine
::
getClock
(
StagingArea
&
stagingArea
,
ClockValue
&
value
)
{
std
::
string
prevValue
;
THROW_ON_ERROR
(
stagingArea
.
get
(
KeyConstants
::
kStateMachine_Clock
,
prevValue
));
...
...
@@ -1075,21 +1094,8 @@ void StateMachine::getClock(ClockValue &value) {
rocksdb
::
Status
StateMachine
::
lease_acquire
(
StagingArea
&
stagingArea
,
const
std
::
string
&
key
,
const
std
::
string
&
value
,
ClockValue
clockUpdate
,
uint64_t
duration
,
bool
&
acquired
)
{
qdb_assert
(
!
value
.
empty
());
// First, some timekeeping. Get current clock time.
ClockValue
currentClock
;
getClock
(
stagingArea
,
currentClock
);
// Two cases:
// - currentClock is behind clockUpdate - should be by far the most common.
// Simply update currentClock to clockUpdate.
// - currentClock is ahead.. we were hit by a rare race condition. Advance
// clockUpdate to currentClock instead.
if
(
currentClock
<
clockUpdate
)
{
advanceClock
(
stagingArea
,
clockUpdate
);
}
else
{
clockUpdate
=
currentClock
;
}
// First, some timekeeping, update clock time if necessary.
clockUpdate
=
maybeAdvanceClock
(
stagingArea
,
clockUpdate
);
// Quick check that no-one else holds the lease right now.
// Could it be that the lease has actually expired? Not at this point.
...
...
src/StateMachine.hh
View file @
036c0fc2
...
...
@@ -197,6 +197,7 @@ public:
RequestCounter
&
getRequestCounter
()
{
return
requestCounter
;
}
private:
ClockValue
maybeAdvanceClock
(
StagingArea
&
stagingArea
,
ClockValue
newValue
);
friend
class
StagingArea
;
class
Snapshot
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment