Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tarantool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
core
tarantool
Commits
3e3719dd
Commit
3e3719dd
authored
9 years ago
by
Georgy Kirichenko
Committed by
Roman Tsisyk
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Randomize snapshot start time. Fixed #732
parent
e074c948
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/box/lua/snapshot_daemon.lua
+15
-30
15 additions, 30 deletions
src/box/lua/snapshot_daemon.lua
test/box/snapshot_daemon.result
+43
-0
43 additions, 0 deletions
test/box/snapshot_daemon.result
test/box/snapshot_daemon.test.lua
+23
-0
23 additions, 0 deletions
test/box/snapshot_daemon.test.lua
with
81 additions
and
30 deletions
src/box/lua/snapshot_daemon.lua
+
15
−
30
View file @
3e3719dd
...
...
@@ -6,11 +6,14 @@ do
local
fio
=
require
'fio'
local
yaml
=
require
'yaml'
local
errno
=
require
'errno'
local
digest
=
require
'digest'
local
pickle
=
require
'pickle'
local
PREFIX
=
'snapshot_daemon'
local
daemon
=
{
snapshot_period
=
0
;
snapshot_period_bias
=
0
;
snapshot_count
=
6
;
}
...
...
@@ -145,7 +148,7 @@ do
local
function
next_snap_interval
(
self
)
-- don't do anything in hot_standby mode
if
box
.
info
.
status
~=
'running'
or
self
.
snapshot_period
==
nil
or
...
...
@@ -153,34 +156,8 @@ do
return
nil
end
local
interval
=
self
.
snapshot_period
/
10
local
time
=
fiber
.
time
()
local
snaps
=
fio
.
glob
(
fio
.
pathjoin
(
box
.
cfg
.
snap_dir
,
'*.snap'
))
if
snaps
==
nil
or
#
snaps
==
0
then
return
interval
end
local
last_snap
=
snaps
[
#
snaps
]
local
stat
=
fio
.
stat
(
last_snap
)
if
stat
==
nil
then
return
interval
end
-- there is no activity in xlogs
if
self
.
snapshot_period
*
2
+
stat
.
mtime
<
time
then
return
interval
end
local
time_left
=
self
.
snapshot_period
+
stat
.
mtime
-
time
if
time_left
>
0
then
return
time_left
end
return
interval
return
self
.
snapshot_period
-
(
fiber
.
time
()
+
self
.
snapshot_period_bias
)
%
self
.
snapshot_period
end
local
function
daemon_fiber
(
self
)
...
...
@@ -221,6 +198,12 @@ do
__index
=
{
set_snapshot_period
=
function
()
daemon
.
snapshot_period
=
box
.
cfg
.
snapshot_period
if
daemon
.
snapshot_period
>
0
then
local
rnd
=
pickle
.
unpack
(
'i'
,
digest
.
urandom
(
4
))
daemon
.
snapshot_period_bias
=
rnd
%
daemon
.
snapshot_period
else
daemon
.
snapshot_period_bias
=
0
end
reload
(
daemon
)
return
end
,
...
...
@@ -232,7 +215,9 @@ do
end
daemon
.
snapshot_count
=
box
.
cfg
.
snapshot_count
reload
(
daemon
)
end
end
,
next_snap_interval
=
next_snap_interval
}
})
...
...
This diff is collapsed.
Click to expand it.
test/box/snapshot_daemon.result
+
43
−
0
View file @
3e3719dd
...
...
@@ -132,3 +132,46 @@ daemon.snapshot_count = 20
box.cfg{ snapshot_count = 0 }
---
...
-- first start daemon
box.cfg{ snapshot_count = 2, snapshot_period = 3600}
---
...
period_bias = daemon.snapshot_period_bias
---
...
next_snap_interval = daemon.next_snap_interval(daemon)
---
...
test_snap_interval = 3600 - (fiber.time() + period_bias) % 3600
---
...
(next_snap_interval - test_snap_interval + 3600) % 3600 < 2
---
- true
...
biases = {}
---
...
max_equals = 0
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
for i = 1, 20 do
box.cfg{ snapshot_period = 0}
box.cfg{ snapshot_period = 3600}
biases[daemon.snapshot_period_bias] = (biases[daemon.snapshot_period_bias] or 0) + 1
if biases[daemon.snapshot_period_bias] > max_equals then
max_equals = biases[daemon.snapshot_period_bias]
end
end
test_run:cmd("setopt delimiter ''");
---
...
max_equals < 4
---
- true
...
This diff is collapsed.
Click to expand it.
test/box/snapshot_daemon.test.lua
+
23
−
0
View file @
3e3719dd
...
...
@@ -72,3 +72,26 @@ daemon.snapshot_count = 20
-- stop daemon
box
.
cfg
{
snapshot_count
=
0
}
-- first start daemon
box
.
cfg
{
snapshot_count
=
2
,
snapshot_period
=
3600
}
period_bias
=
daemon
.
snapshot_period_bias
next_snap_interval
=
daemon
.
next_snap_interval
(
daemon
)
test_snap_interval
=
3600
-
(
fiber
.
time
()
+
period_bias
)
%
3600
(
next_snap_interval
-
test_snap_interval
+
3600
)
%
3600
<
2
biases
=
{}
max_equals
=
0
test_run
:
cmd
(
"setopt delimiter ';'"
)
for
i
=
1
,
20
do
box
.
cfg
{
snapshot_period
=
0
}
box
.
cfg
{
snapshot_period
=
3600
}
biases
[
daemon
.
snapshot_period_bias
]
=
(
biases
[
daemon
.
snapshot_period_bias
]
or
0
)
+
1
if
biases
[
daemon
.
snapshot_period_bias
]
>
max_equals
then
max_equals
=
biases
[
daemon
.
snapshot_period_bias
]
end
end
test_run
:
cmd
(
"setopt delimiter ''"
);
max_equals
<
4
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