Code style fixes in JDBC Journal

This commit is contained in:
Martyn Taylor 2016-02-04 15:18:53 +00:00
parent 0e4a164b39
commit af89b93004
4 changed files with 8 additions and 40 deletions

View File

@ -84,14 +84,12 @@ public class JDBCJournalImpl implements Journal {
// Track Tx Records
private Map<Long, TransactionHolder> transactions = new ConcurrentHashMap<>();
private boolean isLoaded = false;
public JDBCJournalImpl(String jdbcUrl, String tableName) {
this.tableName = tableName;
this.jdbcUrl = jdbcUrl;
timerThread = "Timer JDBC Journal(" + tableName + ")";
records = new ArrayList<JDBCJournalRecord>();
records = new ArrayList<>();
}
@Override
@ -169,7 +167,6 @@ public class JDBCJournalImpl implements Journal {
break;
case JDBCJournalRecord.ROLLBACK_RECORD:
// Roll back we remove all records associated with this TX ID. This query is always performed last.
holder = transactions.get(record.getTxId());
deleteJournalTxRecords.setLong(1, record.getTxId());
deleteJournalTxRecords.addBatch();
break;
@ -262,7 +259,7 @@ public class JDBCJournalImpl implements Journal {
// On rollback we must update the tx map to remove all the tx entries
for (TransactionHolder txH : txHolders) {
if (txH.prepared == false && txH.recordInfos.isEmpty() && txH.recordsToDelete.isEmpty()) {
if (!txH.prepared && txH.recordInfos.isEmpty() && txH.recordsToDelete.isEmpty()) {
transactions.remove(txH.transactionID);
}
}
@ -616,7 +613,6 @@ public class JDBCJournalImpl implements Journal {
jli.setMaxID(((JDBCJournalLoaderCallback) reloadManager).getMaxId());
jli.setNumberOfRecords(noRecords);
transactions = jrc.getTransactions();
isLoaded = true;
}
return jli;
}

View File

@ -29,19 +29,13 @@ import org.apache.activemq.artemis.core.journal.TransactionFailureCallback;
public class JDBCJournalLoaderCallback implements LoaderCallback {
private static final int DELETE_FLUSH = 20000;
private final List<PreparedTransactionInfo> preparedTransactions;
private final TransactionFailureCallback failureCallback;
private final boolean fixBadTX;
/* We keep track of list entries for each ID. This preserves order and allows multiple record insertions with the
same ID. We use this for deleting records */
private final Map<Long, List<Integer>> deleteReferences = new HashMap<Long, List<Integer>>();
private Runtime runtime = Runtime.getRuntime();
private final Map<Long, List<Integer>> deleteReferences = new HashMap<>();
private final List<RecordInfo> committedRecords;
@ -54,7 +48,6 @@ public class JDBCJournalLoaderCallback implements LoaderCallback {
this.committedRecords = committedRecords;
this.preparedTransactions = preparedTransactions;
this.failureCallback = failureCallback;
this.fixBadTX = fixBadTX;
}
public synchronized void checkMaxId(long id) {
@ -71,7 +64,7 @@ public class JDBCJournalLoaderCallback implements LoaderCallback {
int index = committedRecords.size();
committedRecords.add(index, info);
ArrayList<Integer> indexes = new ArrayList<Integer>();
ArrayList<Integer> indexes = new ArrayList<>();
indexes.add(index);
deleteReferences.put(info.id, indexes);
@ -89,10 +82,6 @@ public class JDBCJournalLoaderCallback implements LoaderCallback {
}
}
public int getNoRecords() {
return committedRecords.size();
}
@Override
public void failedTransaction(final long transactionID,
final List<RecordInfo> records,

View File

@ -29,7 +29,7 @@ import org.apache.activemq.artemis.journal.ActiveMQJournalLogger;
public class JDBCJournalReaderCallback implements JournalReaderCallback {
private final Map<Long, TransactionHolder> loadTransactions = new LinkedHashMap<Long, TransactionHolder>();
private final Map<Long, TransactionHolder> loadTransactions = new LinkedHashMap<>();
private final LoaderCallback loadManager;
@ -90,12 +90,11 @@ public class JDBCJournalReaderCallback implements JournalReaderCallback {
public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception {
// It is possible that the TX could be null, since deletes could have happened in the journal.
TransactionHolder tx = loadTransactions.get(transactionID);
tx.committed = true;
// We can remove local Tx without associated records
if (tx != null) {
tx.committed = true;
for (RecordInfo txRecord : tx.recordInfos) {
if (txRecord.isUpdate) {
loadManager.updateRecord(txRecord);

View File

@ -116,29 +116,18 @@ public class JDBCJournalRecord {
}
public static String selectRecordsSQL(String tableName) {
return "SELECT id," + "recordType," + "compactCount," + "txId," + "userRecordType," + "variableSize," + "record," + "txDataSize," + "txData," + "txCheckNoRecords " + "FROM " + tableName;
return "SELECT id,recordType,compactCount,txId,userRecordType,variableSize,record,txDataSize,txData,txCheckNoRecords "
+ "FROM " + tableName;
}
public static String deleteRecordsSQL(String tableName) {
return "DELETE FROM " + tableName + " WHERE id = ?";
}
public static String deleteCommittedDeleteRecordsForTxSQL(String tableName) {
return "DELETE FROM " + tableName + " WHERE id IN (SELECT id FROM " + tableName + " WHERE txID=?)";
}
public static String deleteCommittedTxRecordsSQL(String tableName) {
return "DELETE FROM " + tableName + " WHERE txId=? AND (recordType=" + PREPARE_RECORD + " OR recordType=" + COMMIT_RECORD + ")";
}
public static String deleteJournalTxRecordsSQL(String tableName) {
return "DELETE FROM " + tableName + " WHERE txId=?";
}
public static String deleteRolledBackTxSQL(String tableName) {
return "DELETE FROM " + tableName + " WHERE txId=?";
}
public void complete(boolean success) {
if (ioCompletion != null) {
if (success) {
@ -183,11 +172,6 @@ public class JDBCJournalRecord {
statement.addBatch();
}
protected void writeDeleteTxRecord(PreparedStatement deleteTxStatement) throws SQLException {
deleteTxStatement.setLong(1, txId);
deleteTxStatement.addBatch();
}
protected void writeDeleteRecord(PreparedStatement deleteStatement) throws SQLException {
deleteStatement.setLong(1, id);
deleteStatement.addBatch();