}
}
}
private WriteBatch enqueue(WriteCommand writeRecord) throws IOException {
WriteBatch currentBatch = null;
int spinnings = 0;
int limit = SPIN_RETRIES;
while (true) {
if (shutdown) {
throw new IOException("DataFileAppender Writer Thread Shutdown!");
}
if (firstAsyncException.get() != null) {
throw new IOException(firstAsyncException.get());
}
try {
if (batching.compareAndSet(false, true) && !shutdown) {
try {
if (nextWriteBatch == null) {
DataFile file = journal.getCurrentWriteFile();
boolean canBatch = false;
currentBatch = new WriteBatch(file, file.getLength());
canBatch = currentBatch.canBatch(writeRecord, journal.getMaxWriteBatchSize(), journal.getMaxFileLength());
if (!canBatch) {
file = journal.rotateWriteFile();
currentBatch = new WriteBatch(file, file.getLength());
}
WriteCommand controlRecord = currentBatch.prepareBatch();
currentBatch.appendBatch(writeRecord);
if (!writeRecord.isSync()) {
journal.getInflightWrites().put(controlRecord.getLocation(), controlRecord);
journal.getInflightWrites().put(writeRecord.getLocation(), writeRecord);
nextWriteBatch = currentBatch;
} else {