Make sure the leveldb append log file is flushed to disk before it's closed to avoid data loss.

This commit is contained in:
Hiram Chirino 2013-10-09 11:48:55 -04:00
parent 7319697da5
commit d609d2ae38
3 changed files with 11 additions and 11 deletions

View File

@ -114,12 +114,10 @@ case class RecordLog(directory: File, logSuffix:String) {
override def open = new RandomAccessFile(file, "rw") override def open = new RandomAccessFile(file, "rw")
override def dispose() = { override def on_close ={
flush force
super.dispose()
} }
val flushed_offset = new AtomicLong(0) val flushed_offset = new AtomicLong(0)
def append_position = { def append_position = {
@ -233,9 +231,12 @@ case class RecordLog(directory: File, logSuffix:String) {
val channel = fd.getChannel val channel = fd.getChannel
override def dispose() { override def dispose() {
on_close
fd.close() fd.close()
} }
def on_close = {}
def check_read_flush(end_offset:Long) = {} def check_read_flush(end_offset:Long) = {}
def read(record_position:Long, length:Int) = { def read(record_position:Long, length:Int) = {

View File

@ -148,6 +148,9 @@ class MasterLevelDBClient(val store:MasterLevelDBStore) extends LevelDBClient(st
} }
} }
override def on_close {
super.force
}
} }
} }

View File

@ -347,15 +347,11 @@ class DFSLevelDBClient(val store:DFSLevelDBStore) extends LevelDBClient(store) {
dfs_os.sync() dfs_os.sync()
} }
override def dispose() = { override def on_close {
try { super.force
super.dispose()
} finally {
dfs_os.close() dfs_os.close()
} }
} }
}
} }
} }
} }