SyncThread is a background thread which flushes ledger index pages periodically. Also it takes responsibility of garbage collecting journal files.
Before flushing, SyncThread first records a log marker {journalId, journalPos} in memory, which indicates entries before this log marker would be persisted to ledger files. Then sync thread begins flushing ledger index pages to ledger index files, flush entry logger to ensure all entries persisted to entry loggers for future reads.
After all data has been persisted to ledger index files and entry loggers, it is safe to persist the log marker to disk. If bookie failed after persist log mark, bookie is able to relay journal entries started from last log mark without losing any entries.
Those journal files whose id are less than the log id in last log mark, could be removed safely after persisting last log mark. We provide a setting to let user keeping number of old journal files which may be used for manual recovery in critical disaster.