@Override
    public void batchWriteCommit() throws InterruptedException, JournalException {
        if (currentTransaction == null) {
            throw new JournalException("failed to commit because no running txn!");
        }

        JournalException exception = null;
        try {
            for (int i = 0; i < RETRY_TIME; i++) {
                // retry cleanups
                if (i != 0) {
                    Thread.sleep(SLEEP_INTERVAL_SEC * 1000L);

                    if (currentTransaction == null || !currentTransaction.isValid()) {
                        try {
                            rebuildCurrentTransaction();
                        } catch (JournalException e) {
                            // failed to rebuild txn, will continue to next attempt
                            LOG.warn("failed to commit journal after retried {} times! failed to rebuild txn",
                                    i + 1, e);
                            currentTransaction = null;
                            exception = e;
                            continue;
                        }
                    }
                } // if i != 0

                // commit
                try {
                    if (currentTransaction != null) {
                        currentTransaction.commit();
                    }
                    return;
                } catch (DatabaseException e) {
                    String errMsg = String.format("failed to commit journal after retried %d times! txn[%s] db[%s]",
                            i + 1, currentTransaction, currentJournalDB);
                    LOG.error(errMsg, e);
                    exception = new JournalException(errMsg);
                    exception.initCause(e);
                }
            }
            // failed after retried
            if (exception != null) {
                throw exception;
            }
        } finally {
            // always reset current txn
            currentTransaction = null;
            uncommittedEntries.clear();
        }
    }
@Test(expected = JournalException.class)
    public void testCommitNoBegin(
            @Mocked CloseSafeDatabase database,
            @Mocked BDBEnvironment environment) throws Exception {
        BDBJEJournal journal = new BDBJEJournal(environment, database);
        String data = "petals on a wet black bough";
        DataOutputBuffer buffer = new DataOutputBuffer();
        Text.writeString(buffer, data);
        journal.batchWriteCommit();
        Assert.fail();
    }