Callable<Void> producerThread = new Callable<Void>() {
@Override
public Void call() throws Exception {
int currentTxId = 0;
try {
FileJournalManager jm = new FileJournalManager(storageDirectory);
for (int segment = 0; segment < numSegments; segment++) {
// 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++;
}
FSEditLogTestUtil.flushStreams(out);
FSEditLogTestUtil.closeStreams(out);
jm.finalizeLogSegment(firstTxId, currentTxId - 1);
// simulate NFS cache delay (reader won't see
// the new file for 1 second
if (r.nextBoolean())
;