Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Only fsync if there are waiters
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffstyr committed Sep 22, 2011
1 parent 3808ba7 commit 91b89c9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/scala/net/lag/kestrel/PeriodicSyncFile.scala
Expand Up @@ -21,7 +21,7 @@ class PeriodicSyncFile(file: File, timer: Timer, period: Duration) {

if (period > 0.seconds && period < Duration.MaxValue) {
timer.schedule(Time.now, period) {
if (!closed) fsync()
if (!closed && !promises.isEmpty) fsync()
}
}

Expand All @@ -31,14 +31,16 @@ class PeriodicSyncFile(file: File, timer: Timer, period: Duration) {
val completed = promises.size
try {
writer.force(false)
for (i <- 0 until completed) {
promises.poll().setValue(())
}
} catch {
case e: IOException =>
for (i <- 0 until completed) {
promises.poll().setException(e)
}
return;
}

for (i <- 0 until completed) {
promises.poll().setValue(())
}
}
}
Expand Down

0 comments on commit 91b89c9

Please sign in to comment.