@Override
    public void batchWriteAppend(long journalId, DataOutputBuffer buffer) throws InterruptedException, JournalException {
        if (currentTransaction == null) {
            throw new JournalException("failed to append because no running txn!");
        }
        // id is the key
        DatabaseEntry theKey = new DatabaseEntry();
        TupleBinding<Long> idBinding = TupleBinding.getPrimitiveBinding(Long.class);
        idBinding.objectToEntry(journalId, theKey);
        // entity is the value
        DatabaseEntry theData = new DatabaseEntry(buffer.getData(), 0, buffer.getLength());

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

                OperationStatus status = currentJournalDB.put(currentTransaction, theKey, theData);
                if (status != OperationStatus.SUCCESS) {
                    throw new JournalException(String.format(
                            "failed to append journal after retried %d times! status[%s] db[%s] key[%s] data[%s]",
                            i + 1, status, currentJournalDB, theKey, theData));
                }
                // success
                uncommittedEntries.add(Pair.create(theKey, theData));
                return;
            } catch (DatabaseException e) {
                String errMsg = String.format(
                        "failed to append journal after retried %d times! key[%s] value[%s] txn[%s] db[%s]",
                        i + 1, theKey, theData, currentTransaction, currentJournalDB);
                LOG.error(errMsg, e);
                exception = new JournalException(errMsg);
                exception.initCause(e);
            } catch (JournalException e) {
                LOG.error("failed to write journal", e);
                exception = e;
            }
        }
        // failed after retried
        throw exception;
    }
@Test(expected = JournalException.class)
    public void testAppendNoBegin(
            @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.batchWriteAppend(1, buffer);
        Assert.fail();
    }