// start new segment
int firstTxId = currentTxId;
EditLogOutputStream out = jm.startLogSegment(currentTxId);
// starting transaction
FSEditLogOp startOp = new LogSegmentOp(
FSEditLogOpCodes.OP_START_LOG_SEGMENT);
startOp.setTransactionId(firstTxId);
FSEditLogTestUtil.writeToStreams(startOp, out);
LOG.info("Written op: " + startOp);
writtenTransactions.add(startOp);
currentTxId++;
// other transactions
List<FSEditLogOp> transactions = FSEditLogTestUtil
.getContiguousLogSegment(currentTxId, currentTxId
+ editsPerFile);
for (int i = 0; i < editsPerFile; i++) {
FSEditLogOp op = transactions.get(i);
op.setTransactionId(currentTxId);
FSEditLogTestUtil.writeToStreams(op, out);
writtenTransactions.add(op);
currentTxId++;
LOG.info("Written op: " + op);
if (i % 100 == 0) {
Thread.sleep(10);
FSEditLogTestUtil.flushStreams(out);
}
}
// write ending transactions if needed
if (endLogSegment || (segment == numSegments - 1)) {
int lastTxId = currentTxId;
FSEditLogOp endOp = new LogSegmentOp(
FSEditLogOpCodes.OP_END_LOG_SEGMENT);
endOp.setTransactionId(lastTxId);
FSEditLogTestUtil.writeToStreams(endOp, out);
LOG.info("Written op: " + endOp);
writtenTransactions.add(endOp);
currentTxId++;
}