Code review comment: why not write code like  ``` try { } finally {      journal.commit() } ``` This can make sure that the current transaction can be commit or abort

Code under review:
protected void runOneCycle() {
        try {
            
            JournalTask task = logQueue.take();

            long start = System.nanoTime();
            long uncommitedEstimatedBytes = 0;
            staggingLogs.clear();

            
            while (true) {
                if (!staggingLogs.isEmpty()) {
                    task = logQueue.take();
                }
                
                journal.writeWithinTxn(task.getOp(), task.getBuffer());
                staggingLogs.add(task);

                
                if (task.getBetterCommitBeforeTime() > 0) {
                    long delayMillis = (System.nanoTime() - task.getBetterCommitBeforeTime()) / 1000000;
                    if (delayMillis >= 0) {
                        LOG.warn("log expect commit before {} is delayed {} mills, will commit now",
                                task.getBetterCommitBeforeTime(), delayMillis);
                        break;
                    }
                }

                
                if (staggingLogs.size() >= Config.batch_journal_cnt) {
                    LOG.warn("staging log {} >= {}, will commit now",
                            staggingLogs.size(), Config.batch_journal_cnt);
                    break;
                }

                
                uncommitedEstimatedBytes += task.estimatedSizeByte();
                if (uncommitedEstimatedBytes >= Config.batch_journal_size_mb * 1024 * 1024) {
                    LOG.warn("uncommitted estimated bytes {} >= {}MB, will commit now",
                            uncommitedEstimatedBytes, Config.batch_journal_size_mb);
                    break;
                }

                
                if (logQueue.peek() == null) {
                    break;
                }
            }

            
            journal.commitTxn();

            
            for (JournalTask e : staggingLogs) {
                e.markDone();
            }

            
            if (MetricRepo.isInit) {
                MetricRepo.COUNTER_EDIT_LOG_WRITE.increase((long) staggingLogs.size());
                MetricRepo.HISTO_JOURNAL_WRITE_LATENCY.update((System.nanoTime() - start) / 1000000);
                MetricRepo.HISTO_JOURNAL_WRITE_BATCH.update(staggingLogs.size());
                MetricRepo.HISTO_JOURNAL_WRITE_BYTES.update(uncommitedEstimatedBytes);
                MetricRepo.GAUGE_STACKED_EDIT_LOG_NUM.setValue((long) logQueue.size());
            }
            if (logQueue.size() > Config.batch_journal_cnt) {
                Log.warn("log has piled up: {} in queue after consume", logQueue.size());
            }

            
            rollEditCounter += staggingLogs.size();
            if (rollEditCounter >= Config.edit_log_roll_num) {
                LOG.info("rollEditiCounter {} is equal to or larger than edit_log_roll_num {}, will roll edit.",
                        rollEditCounter, Config.edit_log_roll_num);
                journal.rollJournal();
                rollEditCounter = 0;
            }
        } catch (InterruptedException e) {
            
            LOG.warn("got interruption exception, will continue to next loop, ", e);
        }
    }

Line commented on: journal.writeWithinTxn(task.getOp(), task.getBuffer());

Revised code:
protected void runOneCycle() {
                try {
                    writeOneBatch();
                } catch (InterruptedException e) {
                    String msg = "got interrupted exception when trying to write one batch, will exit now.";
                    LOG.error(msg, e);
                    
                    Util.stdoutWithTime(msg);
                    System.exit(-1);
                }
            }