long recordID = idGenerator.generateID();
addTx(transactionID, recordID);
updateTx(transactionID, recordID);
if (preXA)
{
prepare(transactionID, new SimpleEncoding(10, (byte)0));
}
transactedRecords.add(new Pair<Long, Long>(transactionID++, recordID));
}
}
if (regularAdd)
{
for (int i = 0; i < NIOJournalCompactTest.NUMBER_OF_RECORDS; i++)
{
if (!(i % 10 == 0))
{
delete(i);
}
else
{
liveIDs.add((long)i);
}
}
}
journal.forceMoveNextFile();
Thread t = new Thread()
{
@Override
public void run()
{
try
{
journal.testCompact();
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
t.start();
latchDone.await();
int nextID = NIOJournalCompactTest.NUMBER_OF_RECORDS;
if (performAppend)
{
for (int i = 0; i < 50; i++)
{
add(nextID++);
if (i % 10 == 0)
{
journal.forceMoveNextFile();
}
}
for (int i = 0; i < 50; i++)
{
// A Total new transaction (that was created after the compact started) to add new record while compacting
// is still working
addTx(transactionID, nextID++);
commit(transactionID++);
if (i % 10 == 0)
{
journal.forceMoveNextFile();
}
}
}
if (performUpdate)
{
int count = 0;
for (Long liveID : liveIDs)
{
if (count++ % 2 == 0)
{
update(liveID);
}
else
{
// A Total new transaction (that was created after the compact started) to update a record that is being
// compacted
updateTx(transactionID, liveID);
commit(transactionID++);
}
}
}
if (performDelete)
{
int count = 0;
for (long liveID : liveIDs)
{
if (count++ % 2 == 0)
{
System.out.println("Deleting no trans " + liveID);
delete(liveID);
}
else
{
System.out.println("Deleting TX " + liveID);
// A Total new transaction (that was created after the compact started) to delete a record that is being
// compacted
deleteTx(transactionID, liveID);
commit(transactionID++);
}
System.out.println("Deletes are going into " + ((JournalImpl)journal).getCurrentFile());
}
}
if (performNonTransactionalDelete)
{
for (long liveID : liveIDs)
{
delete(liveID);
}
}
if (pendingTransactions && !delayCommit)
{
for (Pair<Long, Long> tx : transactedRecords)
{
if (postXA)
{
prepare(tx.a, new SimpleEncoding(10, (byte)0));
}
if (tx.a % 2 == 0)
{
commit(tx.a);
if (deleteTransactRecords)
{
delete(tx.b);
}
}
else
{
rollback(tx.a);
}
}
}
/** Some independent adds and updates */
for (int i = 0; i < 1000; i++)
{
long id = idGenerator.generateID();
add(id);
delete(id);
if (i % 100 == 0)
{
journal.forceMoveNextFile();
}
}
journal.forceMoveNextFile();
latchWait.countDown();
t.join();
if (pendingTransactions && delayCommit)
{
for (Pair<Long, Long> tx : transactedRecords)
{
if (postXA)
{
prepare(tx.a, new SimpleEncoding(10, (byte)0));
}
if (tx.a % 2 == 0)
{
commit(tx.a);