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
Show 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")
...
@@ -28,6 +28,7 @@ var log = logging.Logger("flatfs")
const
(
const
(
extension
=
".data"
extension
=
".data"
diskUsageCheckpointPercent
=
1.0
diskUsageCheckpointPercent
=
1.0
diskUsageCheckpointTimeout
=
2.0
*
time
.
Second
)
)
var
(
var
(
...
@@ -804,28 +805,38 @@ func (fs *Datastore) checkpointDiskUsage() {
...
@@ -804,28 +805,38 @@ func (fs *Datastore) checkpointDiskUsage() {
}
}
func
(
fs
*
Datastore
)
checkpointLoop
()
{
func
(
fs
*
Datastore
)
checkpointLoop
()
{
timerActive
:=
true
timer
:=
time
.
NewTimer
(
0
)
for
{
for
{
_
,
more
:=
<-
fs
.
checkpointCh
select
{
fs
.
dirty
=
true
case
_
,
more
:=
<-
fs
.
checkpointCh
:
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
if
more
{
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
)
newDu
:=
float64
(
du
)
lastCheckpointDu
:=
float64
(
fs
.
storedValue
.
diskUsage
)
lastCheckpointDu
:=
float64
(
fs
.
storedValue
.
diskUsage
)
diff
:=
math
.
Abs
(
newDu
-
lastCheckpointDu
)
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
{
if
(
lastCheckpointDu
*
diskUsageCheckpointPercent
/
100.0
)
<
diff
{
fs
.
writeDiskUsageFile
(
du
)
fs
.
writeDiskUsageFile
(
du
)
}
}
// Otherwise insure the value will be written to disk after
// FIXME: If dirty set a timer to write the diskusage
// `diskUsageCheckpointTimeout`
// anyway after X seconds of inactivity.
if
fs
.
dirty
&&
!
timerActive
{
}
else
{
timer
.
Reset
(
diskUsageCheckpointTimeout
)
// shutting down, write the final value
}
case
<-
timer
.
C
:
timerActive
=
false
if
fs
.
dirty
{
du
:=
atomic
.
LoadInt64
(
&
fs
.
diskUsage
)
fs
.
writeDiskUsageFile
(
du
)
fs
.
writeDiskUsageFile
(
du
)
fs
.
done
<-
true
}
return
}
}
}
}
}
}
...
...
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