Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-flatfs
Commits
2df76d73
Commit
2df76d73
authored
Mar 24, 2018
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Insure disk usage is written to disk within 2 seconds.
parent
69ad27b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
15 deletions
+26
-15
flatfs.go
flatfs.go
+26
-15
No files found.
flatfs.go
View file @
2df76d73
...
...
@@ -28,6 +28,7 @@ var log = logging.Logger("flatfs")
const
(
extension
=
".data"
diskUsageCheckpointPercent
=
1.0
diskUsageCheckpointTimeout
=
2.0
*
time
.
Second
)
var
(
...
...
@@ -804,28 +805,38 @@ func (fs *Datastore) checkpointDiskUsage() {
}
func
(
fs
*
Datastore
)
checkpointLoop
()
{
timerActive
:=
true
timer
:=
time
.
NewTimer
(
0
)
for
{
_
,
more
:=
<-
fs
.
checkpointCh
fs
.
dirty
=
true
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
if
more
{
select
{
case
_
,
more
:=
<-
fs
.
checkpointCh
:
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
if
!
more
{
// shutting down
fs
.
writeDiskUsageFile
(
du
)
fs
.
done
<-
true
return
}
fs
.
dirty
=
true
// If the difference between the checkpointed disk usage and
// current one is larger than than `diskUsageCheckpointPercent`
// of the checkpointed: store it.
newDu
:=
float64
(
du
)
lastCheckpointDu
:=
float64
(
fs
.
storedValue
.
diskUsage
)
diff
:=
math
.
Abs
(
newDu
-
lastCheckpointDu
)
// If the difference between the checkpointed disk usage and
// current one is larger than than 1% of the checkpointed: store it.
if
(
lastCheckpointDu
*
diskUsageCheckpointPercent
/
100.0
)
<
diff
{
fs
.
writeDiskUsageFile
(
du
)
}
// FIXME: If dirty set a timer to write the diskusage
// anyway after X seconds of inactivity.
}
else
{
// shutting down, write the final value
fs
.
writeDiskUsageFile
(
du
)
fs
.
done
<-
true
return
// Otherwise insure the value will be written to disk after
// `diskUsageCheckpointTimeout`
if
fs
.
dirty
&&
!
timerActive
{
timer
.
Reset
(
diskUsageCheckpointTimeout
)
}
case
<-
timer
.
C
:
timerActive
=
false
if
fs
.
dirty
{
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
fs
.
writeDiskUsageFile
(
du
)
}
}
}
}
...
...
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