void checkpoint() {
// 尝试加载磁盘备份snapshot
List snapshotCopy = loadFromDisk();
// 关闭cleaner
closeLruCleaner();
// marshal + snapshot
marshal();
List snapshot = snapshot();
// 合并两次的snapshot
if (snapshotCopy != null) {
snapshot = merge(snapshotCopy, snapshot);
}
// 备份snapshot
snapshotCopy = snapshot.copy();
// flush + 重试逻辑
int retryCnt = 0;
do {
retryCnt = flush() ? 0 : retryCnt + 1;
} while (retryCnt > 0 && retryCnt < N);
// 如果没重试则打开cleaner,否则根据snapshot的大小来决定是否要进行更激进的操作。
if (retryCnt >= N) {
if (snapshotCopy.size() > M) {
// wtf! shutdown.
}
storeToDisk(snapshotCopy);
} else {
openLruCleaner();
}
}