canBatch = currentBatch.canBatch(writeRecord, journal.getMaxWriteBatchSize(), journal.getMaxFileLength());
if (!canBatch) {
file = journal.rotateWriteFile();
currentBatch = new WriteBatch(file, 0);
}
WriteCommand controlRecord = currentBatch.prepareBatch();
writeRecord.getLocation().setDataFileId(file.getDataFileId());
writeRecord.getLocation().setPointer(currentBatch.incrementAndGetPointer());
writeRecord.getLocation().setLatch(currentBatch.getLatch());
currentBatch.appendBatch(writeRecord);
if (!writeRecord.isSync()) {
journal.getInflightWrites().put(controlRecord.getLocation(), controlRecord);
journal.getInflightWrites().put(writeRecord.getLocation(), writeRecord);
nextWriteBatch = currentBatch;
} else {
batchQueue.offer(currentBatch);
hasNewBatch = true;