You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/08/10 17:13:05 UTC
[06/53] [abbrv] [partial] activemq-artemis git commit: automatic
checkstyle change
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java
index 1f657a2..0216c19 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java
@@ -40,8 +40,8 @@ import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalInternalR
import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalRollbackRecordTX;
import org.apache.activemq.artemis.journal.ActiveMQJournalLogger;
-public class JournalCompactor extends AbstractJournalUpdateTask implements JournalRecordProvider
-{
+public class JournalCompactor extends AbstractJournalUpdateTask implements JournalRecordProvider {
+
// We try to separate old record from new ones when doing the compacting
// this is a split line
// We will force a moveNextFiles when the compactCount is bellow than COMPACT_SPLIT_LINE
@@ -54,58 +54,51 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
private final Map<Long, JournalTransaction> newTransactions = new HashMap<Long, JournalTransaction>();
- /** Commands that happened during compacting
- * We can't process any counts during compacting, as we won't know in what files the records are taking place, so
- * we cache those updates. As soon as we are done we take the right account. */
+ /**
+ * Commands that happened during compacting
+ * We can't process any counts during compacting, as we won't know in what files the records are taking place, so
+ * we cache those updates. As soon as we are done we take the right account.
+ */
private final LinkedList<CompactCommand> pendingCommands = new LinkedList<CompactCommand>();
public static SequentialFile readControlFile(final SequentialFileFactory fileFactory,
final List<String> dataFiles,
final List<String> newFiles,
- final List<Pair<String, String>> renameFile) throws Exception
- {
+ final List<Pair<String, String>> renameFile) throws Exception {
SequentialFile controlFile = fileFactory.createSequentialFile(AbstractJournalUpdateTask.FILE_COMPACT_CONTROL);
- if (controlFile.exists())
- {
+ if (controlFile.exists()) {
JournalFile file = new JournalFileImpl(controlFile, 0, JournalImpl.FORMAT_VERSION);
final ArrayList<RecordInfo> records = new ArrayList<RecordInfo>();
- JournalImpl.readJournalFile(fileFactory, file, new JournalReaderCallbackAbstract()
- {
+ JournalImpl.readJournalFile(fileFactory, file, new JournalReaderCallbackAbstract() {
@Override
- public void onReadAddRecord(final RecordInfo info) throws Exception
- {
+ public void onReadAddRecord(final RecordInfo info) throws Exception {
records.add(info);
}
});
- if (records.size() == 0)
- {
+ if (records.size() == 0) {
return null;
}
- else
- {
+ else {
ActiveMQBuffer input = ActiveMQBuffers.wrappedBuffer(records.get(0).data);
int numberDataFiles = input.readInt();
- for (int i = 0; i < numberDataFiles; i++)
- {
+ for (int i = 0; i < numberDataFiles; i++) {
dataFiles.add(input.readUTF());
}
int numberNewFiles = input.readInt();
- for (int i = 0; i < numberNewFiles; i++)
- {
+ for (int i = 0; i < numberNewFiles; i++) {
newFiles.add(input.readUTF());
}
int numberRenames = input.readInt();
- for (int i = 0; i < numberRenames; i++)
- {
+ for (int i = 0; i < numberRenames; i++) {
String from = input.readUTF();
String to = input.readUTF();
renameFile.add(new Pair<String, String>(from, to));
@@ -115,24 +108,20 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
return controlFile;
}
- else
- {
+ else {
return null;
}
}
- public List<JournalFile> getNewDataFiles()
- {
+ public List<JournalFile> getNewDataFiles() {
return newDataFiles;
}
- public Map<Long, JournalRecord> getNewRecords()
- {
+ public Map<Long, JournalRecord> getNewRecords() {
return newRecords;
}
- public Map<Long, JournalTransaction> getNewTransactions()
- {
+ public Map<Long, JournalTransaction> getNewTransactions() {
return newTransactions;
}
@@ -140,19 +129,18 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
final JournalImpl journal,
final JournalFilesRepository filesRepository,
final Set<Long> recordsSnapshot,
- final long firstFileID)
- {
+ final long firstFileID) {
super(fileFactory, journal, filesRepository, recordsSnapshot, firstFileID);
}
- /** This methods informs the Compactor about the existence of a pending (non committed) transaction */
- public void addPendingTransaction(final long transactionID, final long[] ids)
- {
+ /**
+ * This methods informs the Compactor about the existence of a pending (non committed) transaction
+ */
+ public void addPendingTransaction(final long transactionID, final long[] ids) {
pendingTransactions.put(transactionID, new PendingTransaction(ids));
}
- public void addCommandCommit(final JournalTransaction liveTransaction, final JournalFile currentFile)
- {
+ public void addCommandCommit(final JournalTransaction liveTransaction, final JournalFile currentFile) {
pendingCommands.add(new CommitCompactCommand(liveTransaction, currentFile));
long[] ids = liveTransaction.getPositiveArray();
@@ -160,32 +148,26 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
PendingTransaction oldTransaction = pendingTransactions.get(liveTransaction.getId());
long[] ids2 = null;
- if (oldTransaction != null)
- {
+ if (oldTransaction != null) {
ids2 = oldTransaction.pendingIDs;
}
/** If a delete comes for these records, while the compactor still working, we need to be able to take them into account for later deletes
* instead of throwing exceptions about non existent records */
- if (ids != null)
- {
- for (long id : ids)
- {
+ if (ids != null) {
+ for (long id : ids) {
addToRecordsSnaptshot(id);
}
}
- if (ids2 != null)
- {
- for (long id : ids2)
- {
+ if (ids2 != null) {
+ for (long id : ids2) {
addToRecordsSnaptshot(id);
}
}
}
- public void addCommandRollback(final JournalTransaction liveTransaction, final JournalFile currentFile)
- {
+ public void addCommandRollback(final JournalTransaction liveTransaction, final JournalFile currentFile) {
pendingCommands.add(new RollbackCompactCommand(liveTransaction, currentFile));
}
@@ -193,8 +175,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
* @param id
* @param usedFile
*/
- public void addCommandDelete(final long id, final JournalFile usedFile)
- {
+ public void addCommandDelete(final long id, final JournalFile usedFile) {
pendingCommands.add(new DeleteCompactCommand(id, usedFile));
}
@@ -202,40 +183,31 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
* @param id
* @param usedFile
*/
- public void addCommandUpdate(final long id, final JournalFile usedFile, final int size)
- {
+ public void addCommandUpdate(final long id, final JournalFile usedFile, final int size) {
pendingCommands.add(new UpdateCompactCommand(id, usedFile, size));
}
- private void checkSize(final int size) throws Exception
- {
+ private void checkSize(final int size) throws Exception {
checkSize(size, -1);
}
- private void checkSize(final int size, final int compactCount) throws Exception
- {
- if (getWritingChannel() == null)
- {
- if (!checkCompact(compactCount))
- {
+ private void checkSize(final int size, final int compactCount) throws Exception {
+ if (getWritingChannel() == null) {
+ if (!checkCompact(compactCount)) {
// will need to open a file either way
openFile();
}
}
- else
- {
- if (compactCount >= 0)
- {
- if (checkCompact(compactCount))
- {
+ else {
+ if (compactCount >= 0) {
+ if (checkCompact(compactCount)) {
// The file was already moved on this case, no need to check for the size.
// otherwise we will also need to check for the size
return;
}
}
- if (getWritingChannel().writerIndex() + size > getWritingChannel().capacity())
- {
+ if (getWritingChannel().writerIndex() + size > getWritingChannel().capacity()) {
openFile();
}
}
@@ -248,22 +220,18 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
boolean splitted = false;
- private boolean checkCompact(final int compactCount) throws Exception
- {
- if (compactCount >= COMPACT_SPLIT_LINE && !splitted)
- {
+ private boolean checkCompact(final int compactCount) throws Exception {
+ if (compactCount >= COMPACT_SPLIT_LINE && !splitted) {
willNeedToSplit = true;
}
- if (willNeedToSplit && compactCount < COMPACT_SPLIT_LINE)
- {
+ if (willNeedToSplit && compactCount < COMPACT_SPLIT_LINE) {
willNeedToSplit = false;
splitted = false;
openFile();
return true;
}
- else
- {
+ else {
return false;
}
}
@@ -271,16 +239,12 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
/**
* Replay pending counts that happened during compacting
*/
- public void replayPendingCommands()
- {
- for (CompactCommand command : pendingCommands)
- {
- try
- {
+ public void replayPendingCommands() {
+ for (CompactCommand command : pendingCommands) {
+ try {
command.execute();
}
- catch (Exception e)
- {
+ catch (Exception e) {
ActiveMQJournalLogger.LOGGER.errorReplayingCommands(e);
}
}
@@ -290,15 +254,10 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
// JournalReaderCallback implementation -------------------------------------------
- public void onReadAddRecord(final RecordInfo info) throws Exception
- {
- if (lookupRecord(info.id))
- {
- JournalInternalRecord addRecord = new JournalAddRecord(true,
- info.id,
- info.getUserRecordType(),
- new ByteArrayEncoding(info.data));
- addRecord.setCompactCount((short)(info.compactCount + 1));
+ public void onReadAddRecord(final RecordInfo info) throws Exception {
+ if (lookupRecord(info.id)) {
+ JournalInternalRecord addRecord = new JournalAddRecord(true, info.id, info.getUserRecordType(), new ByteArrayEncoding(info.data));
+ addRecord.setCompactCount((short) (info.compactCount + 1));
checkSize(addRecord.getEncodeSize(), info.compactCount);
@@ -308,19 +267,13 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadAddRecordTX(final long transactionID, final RecordInfo info) throws Exception
- {
- if (pendingTransactions.get(transactionID) != null || lookupRecord(info.id))
- {
+ public void onReadAddRecordTX(final long transactionID, final RecordInfo info) throws Exception {
+ if (pendingTransactions.get(transactionID) != null || lookupRecord(info.id)) {
JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
- JournalInternalRecord record = new JournalAddRecordTX(true,
- transactionID,
- info.id,
- info.getUserRecordType(),
- new ByteArrayEncoding(info.data));
+ JournalInternalRecord record = new JournalAddRecordTX(true, transactionID, info.id, info.getUserRecordType(), new ByteArrayEncoding(info.data));
- record.setCompactCount((short)(info.compactCount + 1));
+ record.setCompactCount((short) (info.compactCount + 1));
checkSize(record.getEncodeSize(), info.compactCount);
@@ -330,21 +283,16 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception
- {
+ public void onReadCommitRecord(final long transactionID, final int numberOfRecords) throws Exception {
- if (pendingTransactions.get(transactionID) != null)
- {
+ if (pendingTransactions.get(transactionID) != null) {
// Sanity check, this should never happen
ActiveMQJournalLogger.LOGGER.inconsistencyDuringCompacting(transactionID);
}
- else
- {
+ else {
JournalTransaction newTransaction = newTransactions.remove(transactionID);
- if (newTransaction != null)
- {
- JournalInternalRecord commitRecord =
- new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, transactionID, null);
+ if (newTransaction != null) {
+ JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, transactionID, null);
checkSize(commitRecord.getEncodeSize());
@@ -355,25 +303,19 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadDeleteRecord(final long recordID) throws Exception
- {
- if (newRecords.get(recordID) != null)
- {
+ public void onReadDeleteRecord(final long recordID) throws Exception {
+ if (newRecords.get(recordID) != null) {
// Sanity check, it should never happen
ActiveMQJournalLogger.LOGGER.inconsistencyDuringCompactingDelete(recordID);
}
}
- public void onReadDeleteRecordTX(final long transactionID, final RecordInfo info) throws Exception
- {
- if (pendingTransactions.get(transactionID) != null)
- {
+ public void onReadDeleteRecordTX(final long transactionID, final RecordInfo info) throws Exception {
+ if (pendingTransactions.get(transactionID) != null) {
JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
- JournalInternalRecord record = new JournalDeleteRecordTX(transactionID,
- info.id,
- new ByteArrayEncoding(info.data));
+ JournalInternalRecord record = new JournalDeleteRecordTX(transactionID, info.id, new ByteArrayEncoding(info.data));
checkSize(record.getEncodeSize());
@@ -384,20 +326,18 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
// else.. nothing to be done
}
- public void markAsDataFile(final JournalFile file)
- {
+ public void markAsDataFile(final JournalFile file) {
// nothing to be done here
}
- public void onReadPrepareRecord(final long transactionID, final byte[] extraData, final int numberOfRecords) throws Exception
- {
- if (pendingTransactions.get(transactionID) != null)
- {
+ public void onReadPrepareRecord(final long transactionID,
+ final byte[] extraData,
+ final int numberOfRecords) throws Exception {
+ if (pendingTransactions.get(transactionID) != null) {
JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
- JournalInternalRecord prepareRecord =
- new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, transactionID, new ByteArrayEncoding(extraData));
+ JournalInternalRecord prepareRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.PREPARE, transactionID, new ByteArrayEncoding(extraData));
checkSize(prepareRecord.getEncodeSize());
@@ -408,19 +348,15 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadRollbackRecord(final long transactionID) throws Exception
- {
- if (pendingTransactions.get(transactionID) != null)
- {
+ public void onReadRollbackRecord(final long transactionID) throws Exception {
+ if (pendingTransactions.get(transactionID) != null) {
// Sanity check, this should never happen
throw new IllegalStateException("Inconsistency during compacting: RollbackRecord ID = " + transactionID +
- " for an already rolled back transaction during compacting");
+ " for an already rolled back transaction during compacting");
}
- else
- {
+ else {
JournalTransaction newTransaction = newTransactions.remove(transactionID);
- if (newTransaction != null)
- {
+ if (newTransaction != null) {
JournalInternalRecord rollbackRecord = new JournalRollbackRecordTX(transactionID);
@@ -434,27 +370,20 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadUpdateRecord(final RecordInfo info) throws Exception
- {
- if (lookupRecord(info.id))
- {
- JournalInternalRecord updateRecord = new JournalAddRecord(false,
- info.id,
- info.userRecordType,
- new ByteArrayEncoding(info.data));
+ public void onReadUpdateRecord(final RecordInfo info) throws Exception {
+ if (lookupRecord(info.id)) {
+ JournalInternalRecord updateRecord = new JournalAddRecord(false, info.id, info.userRecordType, new ByteArrayEncoding(info.data));
- updateRecord.setCompactCount((short)(info.compactCount + 1));
+ updateRecord.setCompactCount((short) (info.compactCount + 1));
checkSize(updateRecord.getEncodeSize(), info.compactCount);
JournalRecord newRecord = newRecords.get(info.id);
- if (newRecord == null)
- {
+ if (newRecord == null) {
ActiveMQJournalLogger.LOGGER.compactingWithNoAddRecord(info.id);
}
- else
- {
+ else {
newRecord.addUpdateFile(currentFile, updateRecord.getEncodeSize());
}
@@ -462,19 +391,13 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- public void onReadUpdateRecordTX(final long transactionID, final RecordInfo info) throws Exception
- {
- if (pendingTransactions.get(transactionID) != null || lookupRecord(info.id))
- {
+ public void onReadUpdateRecordTX(final long transactionID, final RecordInfo info) throws Exception {
+ if (pendingTransactions.get(transactionID) != null || lookupRecord(info.id)) {
JournalTransaction newTransaction = getNewJournalTransaction(transactionID);
- JournalInternalRecord updateRecordTX = new JournalAddRecordTX(false,
- transactionID,
- info.id,
- info.userRecordType,
- new ByteArrayEncoding(info.data));
+ JournalInternalRecord updateRecordTX = new JournalAddRecordTX(false, transactionID, info.id, info.userRecordType, new ByteArrayEncoding(info.data));
- updateRecordTX.setCompactCount((short)(info.compactCount + 1));
+ updateRecordTX.setCompactCount((short) (info.compactCount + 1));
checkSize(updateRecordTX.getEncodeSize(), info.compactCount);
@@ -482,8 +405,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
newTransaction.addPositive(currentFile, info.id, updateRecordTX.getEncodeSize());
}
- else
- {
+ else {
onReadUpdateRecord(info);
}
}
@@ -492,102 +414,92 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
* @param transactionID
* @return
*/
- private JournalTransaction getNewJournalTransaction(final long transactionID)
- {
+ private JournalTransaction getNewJournalTransaction(final long transactionID) {
JournalTransaction newTransaction = newTransactions.get(transactionID);
- if (newTransaction == null)
- {
+ if (newTransaction == null) {
newTransaction = new JournalTransaction(transactionID, this);
newTransactions.put(transactionID, newTransaction);
}
return newTransaction;
}
- private abstract static class CompactCommand
- {
+ private abstract static class CompactCommand {
+
abstract void execute() throws Exception;
}
- private class DeleteCompactCommand extends CompactCommand
- {
+ private class DeleteCompactCommand extends CompactCommand {
+
long id;
JournalFile usedFile;
- public DeleteCompactCommand(final long id, final JournalFile usedFile)
- {
+ public DeleteCompactCommand(final long id, final JournalFile usedFile) {
this.id = id;
this.usedFile = usedFile;
}
@Override
- void execute() throws Exception
- {
+ void execute() throws Exception {
JournalRecord deleteRecord = journal.getRecords().remove(id);
- if (deleteRecord == null)
- {
+ if (deleteRecord == null) {
ActiveMQJournalLogger.LOGGER.noRecordDuringCompactReplay(id);
}
- else
- {
+ else {
deleteRecord.delete(usedFile);
}
}
}
- private static class PendingTransaction
- {
+ private static class PendingTransaction {
+
long[] pendingIDs;
- PendingTransaction(final long[] ids)
- {
+ PendingTransaction(final long[] ids) {
pendingIDs = ids;
}
}
- private class UpdateCompactCommand extends CompactCommand
- {
+ private class UpdateCompactCommand extends CompactCommand {
+
private final long id;
private final JournalFile usedFile;
private final int size;
- public UpdateCompactCommand(final long id, final JournalFile usedFile, final int size)
- {
+ public UpdateCompactCommand(final long id, final JournalFile usedFile, final int size) {
this.id = id;
this.usedFile = usedFile;
this.size = size;
}
@Override
- void execute() throws Exception
- {
+ void execute() throws Exception {
JournalRecord updateRecord = journal.getRecords().get(id);
updateRecord.addUpdateFile(usedFile, size);
}
}
- private class CommitCompactCommand extends CompactCommand
- {
+ private class CommitCompactCommand extends CompactCommand {
+
private final JournalTransaction liveTransaction;
- /** File containing the commit record */
+ /**
+ * File containing the commit record
+ */
private final JournalFile commitFile;
- public CommitCompactCommand(final JournalTransaction liveTransaction, final JournalFile commitFile)
- {
+ public CommitCompactCommand(final JournalTransaction liveTransaction, final JournalFile commitFile) {
this.liveTransaction = liveTransaction;
this.commitFile = commitFile;
}
@Override
- void execute() throws Exception
- {
+ void execute() throws Exception {
JournalTransaction newTransaction = newTransactions.get(liveTransaction.getId());
- if (newTransaction != null)
- {
+ if (newTransaction != null) {
liveTransaction.merge(newTransaction);
liveTransaction.commit(commitFile);
}
@@ -595,25 +507,24 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
}
- private class RollbackCompactCommand extends CompactCommand
- {
+ private class RollbackCompactCommand extends CompactCommand {
+
private final JournalTransaction liveTransaction;
- /** File containing the commit record */
+ /**
+ * File containing the commit record
+ */
private final JournalFile rollbackFile;
- public RollbackCompactCommand(final JournalTransaction liveTransaction, final JournalFile rollbackFile)
- {
+ public RollbackCompactCommand(final JournalTransaction liveTransaction, final JournalFile rollbackFile) {
this.liveTransaction = liveTransaction;
this.rollbackFile = rollbackFile;
}
@Override
- void execute() throws Exception
- {
+ void execute() throws Exception {
JournalTransaction newTransaction = newTransactions.get(liveTransaction.getId());
- if (newTransaction != null)
- {
+ if (newTransaction != null) {
liveTransaction.merge(newTransaction);
liveTransaction.rollback(rollbackFile);
}
@@ -622,14 +533,12 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ
}
@Override
- public JournalCompactor getCompactor()
- {
+ public JournalCompactor getCompactor() {
return null;
}
@Override
- public Map<Long, JournalRecord> getRecords()
- {
+ public Map<Long, JournalRecord> getRecords() {
return newRecords;
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java
index 8bc20c7..257065a 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java
@@ -16,12 +16,11 @@
*/
package org.apache.activemq.artemis.core.journal.impl;
-public final class JournalConstants
-{
+public final class JournalConstants {
public static final int DEFAULT_JOURNAL_BUFFER_SIZE_AIO = 490 * 1024;
- public static final int DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO = (int)(1000000000d / 2000);
- public static final int DEFAULT_JOURNAL_BUFFER_TIMEOUT_NIO = (int)(1000000000d / 300);
+ public static final int DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO = (int) (1000000000d / 2000);
+ public static final int DEFAULT_JOURNAL_BUFFER_TIMEOUT_NIO = (int) (1000000000d / 300);
public static final int DEFAULT_JOURNAL_BUFFER_SIZE_NIO = 490 * 1024;
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFile.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFile.java
index dcfc1a2..83b3cf8 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFile.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFile.java
@@ -18,8 +18,8 @@ package org.apache.activemq.artemis.core.journal.impl;
import org.apache.activemq.artemis.core.io.SequentialFile;
-public interface JournalFile
-{
+public interface JournalFile {
+
int getNegCount(JournalFile file);
void incNegCount(JournalFile file);
@@ -36,24 +36,30 @@ public interface JournalFile
int getLiveSize();
- /** The total number of deletes this file has */
+ /**
+ * The total number of deletes this file has
+ */
int getTotalNegativeToOthers();
/**
* Whether this file's contents can deleted and the file reused.
+ *
* @param canDelete if {@code true} then this file's contents are unimportant and may be deleted
- * at any time.
+ * at any time.
*/
void setCanReclaim(boolean canDelete);
/**
* Whether this file's contents can deleted and the file reused.
+ *
* @return {@code true} if the file can already be deleted.
*/
boolean isCanReclaim();
- /** This is a field to identify that records on this file actually belong to the current file.
- * The possible implementation for this is fileID & Integer.MAX_VALUE */
+ /**
+ * This is a field to identify that records on this file actually belong to the current file.
+ * The possible implementation for this is fileID & Integer.MAX_VALUE
+ */
int getRecordID();
long getFileID();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
index 7e96575..4cc23f1 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java
@@ -23,8 +23,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.activemq.artemis.core.io.SequentialFile;
-public class JournalFileImpl implements JournalFile
-{
+public class JournalFileImpl implements JournalFile {
+
private final SequentialFile file;
private final long fileID;
@@ -45,130 +45,108 @@ public class JournalFileImpl implements JournalFile
private final Map<JournalFile, AtomicInteger> negCounts = new ConcurrentHashMap<JournalFile, AtomicInteger>();
- public JournalFileImpl(final SequentialFile file, final long fileID, final int version)
- {
+ public JournalFileImpl(final SequentialFile file, final long fileID, final int version) {
this.file = file;
this.fileID = fileID;
this.version = version;
- recordID = (int)(fileID & Integer.MAX_VALUE);
+ recordID = (int) (fileID & Integer.MAX_VALUE);
}
- public int getPosCount()
- {
+ public int getPosCount() {
return posCount.intValue();
}
@Override
- public boolean isCanReclaim()
- {
+ public boolean isCanReclaim() {
return canReclaim;
}
@Override
- public void setCanReclaim(final boolean canReclaim)
- {
+ public void setCanReclaim(final boolean canReclaim) {
this.canReclaim = canReclaim;
}
- public void incNegCount(final JournalFile file)
- {
- if (file != this)
- {
+ public void incNegCount(final JournalFile file) {
+ if (file != this) {
totalNegativeToOthers.incrementAndGet();
}
getOrCreateNegCount(file).incrementAndGet();
}
- public int getNegCount(final JournalFile file)
- {
+ public int getNegCount(final JournalFile file) {
AtomicInteger count = negCounts.get(file);
- if (count == null)
- {
+ if (count == null) {
return 0;
}
- else
- {
+ else {
return count.intValue();
}
}
- public int getJournalVersion()
- {
+ public int getJournalVersion() {
return version;
}
- public void incPosCount()
- {
+ public void incPosCount() {
posCount.incrementAndGet();
}
- public void decPosCount()
- {
+ public void decPosCount() {
posCount.decrementAndGet();
}
- public long getOffset()
- {
+ public long getOffset() {
return offset;
}
- public long getFileID()
- {
+ public long getFileID() {
return fileID;
}
- public int getRecordID()
- {
+ public int getRecordID() {
return recordID;
}
- public void setOffset(final long offset)
- {
+ public void setOffset(final long offset) {
this.offset = offset;
}
- public SequentialFile getFile()
- {
+ public SequentialFile getFile() {
return file;
}
@Override
- public String toString()
- {
- try
- {
+ public String toString() {
+ try {
return "JournalFileImpl: (" + file.getFileName() + " id = " + fileID + ", recordID = " + recordID + ")";
}
- catch (Exception e)
- {
+ catch (Exception e) {
e.printStackTrace();
return "Error:" + e.toString();
}
}
- /** Receive debug information about the journal */
- public String debug()
- {
+ /**
+ * Receive debug information about the journal
+ */
+ public String debug() {
StringBuilder builder = new StringBuilder();
- for (Entry<JournalFile, AtomicInteger> entry : negCounts.entrySet())
- {
+ for (Entry<JournalFile, AtomicInteger> entry : negCounts.entrySet()) {
builder.append(" file = " + entry.getKey() + " negcount value = " + entry.getValue() + "\n");
}
return builder.toString();
}
- private synchronized AtomicInteger getOrCreateNegCount(final JournalFile file)
- {
+ private synchronized AtomicInteger getOrCreateNegCount(final JournalFile file) {
AtomicInteger count = negCounts.get(file);
- if (count == null)
- {
+ if (count == null) {
count = new AtomicInteger();
negCounts.put(file, count);
}
@@ -177,25 +155,21 @@ public class JournalFileImpl implements JournalFile
}
@Override
- public void addSize(final int bytes)
- {
+ public void addSize(final int bytes) {
liveBytes.addAndGet(bytes);
}
@Override
- public void decSize(final int bytes)
- {
+ public void decSize(final int bytes) {
liveBytes.addAndGet(-bytes);
}
@Override
- public int getLiveSize()
- {
+ public int getLiveSize() {
return liveBytes.get();
}
- public int getTotalNegativeToOthers()
- {
+ public int getTotalNegativeToOthers() {
return totalNegativeToOthers.get();
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
index 268a23d..a837dd3 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java
@@ -39,8 +39,8 @@ import org.apache.activemq.artemis.journal.ActiveMQJournalLogger;
* This is a helper class for the Journal, which will control access to dataFiles, openedFiles and freeFiles
* Guaranteeing that they will be delivered in order to the Journal
*/
-public class JournalFilesRepository
-{
+public class JournalFilesRepository {
+
private static final boolean trace = ActiveMQJournalLogger.LOGGER.isTraceEnabled();
/**
@@ -53,8 +53,7 @@ public class JournalFilesRepository
// This method exists just to make debug easier.
// I could replace log.trace by log.info temporarily while I was debugging
// Journal
- private static void trace(final String message)
- {
+ private static void trace(final String message) {
ActiveMQJournalLogger.LOGGER.trace(message);
}
@@ -86,16 +85,12 @@ public class JournalFilesRepository
private Executor openFilesExecutor;
- private final Runnable pushOpenRunnable = new Runnable()
- {
- public void run()
- {
- try
- {
+ private final Runnable pushOpenRunnable = new Runnable() {
+ public void run() {
+ try {
pushOpenedFile();
}
- catch (Exception e)
- {
+ catch (Exception e) {
ActiveMQJournalLogger.LOGGER.errorPushingFile(e);
}
}
@@ -108,18 +103,14 @@ public class JournalFilesRepository
final int userVersion,
final int maxAIO,
final int fileSize,
- final int minFiles)
- {
- if (filePrefix == null)
- {
+ final int minFiles) {
+ if (filePrefix == null) {
throw new IllegalArgumentException("filePrefix cannot be null");
}
- if (fileExtension == null)
- {
+ if (fileExtension == null) {
throw new IllegalArgumentException("fileExtension cannot be null");
}
- if (maxAIO <= 0)
- {
+ if (maxAIO <= 0) {
throw new IllegalArgumentException("maxAIO must be a positive number");
}
this.fileFactory = fileFactory;
@@ -134,53 +125,43 @@ public class JournalFilesRepository
// Public --------------------------------------------------------
- public void setExecutor(final Executor fileExecutor)
- {
+ public void setExecutor(final Executor fileExecutor) {
this.openFilesExecutor = fileExecutor;
}
- public void clear() throws Exception
- {
+ public void clear() throws Exception {
dataFiles.clear();
freeFiles.clear();
freeFilesCount.set(0);
- for (JournalFile file : openedFiles)
- {
- try
- {
+ for (JournalFile file : openedFiles) {
+ try {
file.getFile().close();
}
- catch (Exception e)
- {
+ catch (Exception e) {
ActiveMQJournalLogger.LOGGER.errorClosingFile(e);
}
}
openedFiles.clear();
}
- public int getMaxAIO()
- {
+ public int getMaxAIO() {
return maxAIO;
}
- public String getFileExtension()
- {
+ public String getFileExtension() {
return fileExtension;
}
- public String getFilePrefix()
- {
+ public String getFilePrefix() {
return filePrefix;
}
- public void calculateNextfileID(final List<JournalFile> files)
- {
+ public void calculateNextfileID(final List<JournalFile> files) {
- for (JournalFile file : files)
- {
+ for (JournalFile file : files) {
final long fileIdFromFile = file.getFileID();
final long fileIdFromName = getFileNameID(file.getFile().getFileName());
@@ -199,10 +180,8 @@ public class JournalFilesRepository
*
* @param targetUpdate
*/
- public void setNextFileID(final long targetUpdate)
- {
- while (true)
- {
+ public void setNextFileID(final long targetUpdate) {
+ while (true) {
final long current = nextFileID.get();
if (current >= targetUpdate)
return;
@@ -212,14 +191,11 @@ public class JournalFilesRepository
}
}
- public void ensureMinFiles() throws Exception
- {
+ public void ensureMinFiles() throws Exception {
int filesToCreate = minFiles - (dataFiles.size() + freeFilesCount.get());
- if (filesToCreate > 0)
- {
- for (int i = 0; i < filesToCreate; i++)
- {
+ if (filesToCreate > 0) {
+ for (int i = 0; i < filesToCreate; i++) {
// Keeping all files opened can be very costly (mainly on AIO)
freeFiles.add(createFile(false, false, true, false, -1));
freeFilesCount.getAndIncrement();
@@ -228,14 +204,11 @@ public class JournalFilesRepository
}
- public void openFile(final JournalFile file, final boolean multiAIO) throws Exception
- {
- if (multiAIO)
- {
+ public void openFile(final JournalFile file, final boolean multiAIO) throws Exception {
+ if (multiAIO) {
file.getFile().open();
}
- else
- {
+ else {
file.getFile().open(1, false);
}
@@ -244,92 +217,74 @@ public class JournalFilesRepository
// Data File Operations ==========================================
- public JournalFile[] getDataFilesArray()
- {
+ public JournalFile[] getDataFilesArray() {
return dataFiles.toArray(new JournalFile[dataFiles.size()]);
}
- public JournalFile pollLastDataFile()
- {
+ public JournalFile pollLastDataFile() {
return dataFiles.pollLast();
}
- public void removeDataFile(final JournalFile file)
- {
- if (!dataFiles.remove(file))
- {
+ public void removeDataFile(final JournalFile file) {
+ if (!dataFiles.remove(file)) {
ActiveMQJournalLogger.LOGGER.couldNotRemoveFile(file);
}
}
- public int getDataFilesCount()
- {
+ public int getDataFilesCount() {
return dataFiles.size();
}
- public Collection<JournalFile> getDataFiles()
- {
+ public Collection<JournalFile> getDataFiles() {
return dataFiles;
}
- public void clearDataFiles()
- {
+ public void clearDataFiles() {
dataFiles.clear();
}
- public void addDataFileOnTop(final JournalFile file)
- {
+ public void addDataFileOnTop(final JournalFile file) {
dataFiles.addFirst(file);
- if (CHECK_CONSISTENCE)
- {
+ if (CHECK_CONSISTENCE) {
checkDataFiles();
}
}
- public String debugFiles()
- {
+ public String debugFiles() {
StringBuilder buffer = new StringBuilder();
buffer.append("**********\nCurrent File = " + journal.getCurrentFile() + "\n");
buffer.append("**********\nDataFiles:\n");
- for (JournalFile file : dataFiles)
- {
+ for (JournalFile file : dataFiles) {
buffer.append(file.toString() + "\n");
}
buffer.append("*********\nFreeFiles:\n");
- for (JournalFile file : freeFiles)
- {
+ for (JournalFile file : freeFiles) {
buffer.append(file.toString() + "\n");
}
return buffer.toString();
}
- public synchronized void checkDataFiles()
- {
+ public synchronized void checkDataFiles() {
long seq = -1;
- for (JournalFile file : dataFiles)
- {
- if (file.getFileID() <= seq)
- {
+ for (JournalFile file : dataFiles) {
+ if (file.getFileID() <= seq) {
ActiveMQJournalLogger.LOGGER.checkFiles();
ActiveMQJournalLogger.LOGGER.info(debugFiles());
ActiveMQJournalLogger.LOGGER.seqOutOfOrder();
System.exit(-1);
}
- if (journal.getCurrentFile() != null && journal.getCurrentFile().getFileID() <= file.getFileID())
- {
+ if (journal.getCurrentFile() != null && journal.getCurrentFile().getFileID() <= file.getFileID()) {
ActiveMQJournalLogger.LOGGER.checkFiles();
ActiveMQJournalLogger.LOGGER.info(debugFiles());
- ActiveMQJournalLogger.LOGGER.currentFile(file.getFileID(), journal.getCurrentFile().getFileID(),
- file.getFileID(), (journal.getCurrentFile() == file));
+ ActiveMQJournalLogger.LOGGER.currentFile(file.getFileID(), journal.getCurrentFile().getFileID(), file.getFileID(), (journal.getCurrentFile() == file));
// throw new RuntimeException ("Check failure!");
}
- if (journal.getCurrentFile() == file)
- {
+ if (journal.getCurrentFile() == file) {
throw new RuntimeException("Check failure! Current file listed as data file!");
}
@@ -337,10 +292,8 @@ public class JournalFilesRepository
}
long lastFreeId = -1;
- for (JournalFile file : freeFiles)
- {
- if (file.getFileID() <= lastFreeId)
- {
+ for (JournalFile file : freeFiles) {
+ if (file.getFileID() <= lastFreeId) {
ActiveMQJournalLogger.LOGGER.checkFiles();
ActiveMQJournalLogger.LOGGER.info(debugFiles());
ActiveMQJournalLogger.LOGGER.fileIdOutOfOrder();
@@ -350,8 +303,7 @@ public class JournalFilesRepository
lastFreeId = file.getFileID();
- if (file.getFileID() < seq)
- {
+ if (file.getFileID() < seq) {
ActiveMQJournalLogger.LOGGER.checkFiles();
ActiveMQJournalLogger.LOGGER.info(debugFiles());
ActiveMQJournalLogger.LOGGER.fileTooSmall();
@@ -361,20 +313,17 @@ public class JournalFilesRepository
}
}
- public void addDataFileOnBottom(final JournalFile file)
- {
+ public void addDataFileOnBottom(final JournalFile file) {
dataFiles.add(file);
- if (CHECK_CONSISTENCE)
- {
+ if (CHECK_CONSISTENCE) {
checkDataFiles();
}
}
// Free File Operations ==========================================
- public int getFreeFilesCount()
- {
+ public int getFreeFilesCount() {
return freeFilesCount.get();
}
@@ -382,8 +331,7 @@ public class JournalFilesRepository
* @param file
* @throws Exception
*/
- public synchronized void addFreeFile(final JournalFile file, final boolean renameTmp) throws Exception
- {
+ public synchronized void addFreeFile(final JournalFile file, final boolean renameTmp) throws Exception {
addFreeFile(file, renameTmp, true);
}
@@ -393,73 +341,62 @@ public class JournalFilesRepository
* @param checkDelete - should delete the file if max condition has been met
* @throws Exception
*/
- public synchronized void addFreeFile(final JournalFile file, final boolean renameTmp, final boolean checkDelete) throws Exception
- {
+ public synchronized void addFreeFile(final JournalFile file,
+ final boolean renameTmp,
+ final boolean checkDelete) throws Exception {
long calculatedSize = 0;
- try
- {
+ try {
calculatedSize = file.getFile().size();
}
- catch (Exception e)
- {
+ catch (Exception e) {
e.printStackTrace();
System.out.println("Can't get file size on " + file);
System.exit(-1);
}
- if (calculatedSize != fileSize)
- {
+ if (calculatedSize != fileSize) {
ActiveMQJournalLogger.LOGGER.deletingFile(file);
file.getFile().delete();
}
- else
- if (!checkDelete || (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size() < minFiles))
- {
- // Re-initialise it
-
- if (JournalFilesRepository.trace)
- {
- JournalFilesRepository.trace("Adding free file " + file);
- }
+ else if (!checkDelete || (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size() < minFiles)) {
+ // Re-initialise it
- JournalFile jf = reinitializeFile(file);
+ if (JournalFilesRepository.trace) {
+ JournalFilesRepository.trace("Adding free file " + file);
+ }
- if (renameTmp)
- {
- jf.getFile().renameTo(JournalImpl.renameExtensionFile(jf.getFile().getFileName(), ".tmp"));
- }
+ JournalFile jf = reinitializeFile(file);
- freeFiles.add(jf);
- freeFilesCount.getAndIncrement();
+ if (renameTmp) {
+ jf.getFile().renameTo(JournalImpl.renameExtensionFile(jf.getFile().getFileName(), ".tmp"));
}
- else
- {
- if (trace)
- {
- ActiveMQJournalLogger.LOGGER.trace("DataFiles.size() = " + dataFiles.size());
- ActiveMQJournalLogger.LOGGER.trace("openedFiles.size() = " + openedFiles.size());
- ActiveMQJournalLogger.LOGGER.trace("minfiles = " + minFiles);
- ActiveMQJournalLogger.LOGGER.trace("Free Files = " + freeFilesCount.get());
- ActiveMQJournalLogger.LOGGER.trace("File " + file +
- " being deleted as freeFiles.size() + dataFiles.size() + 1 + openedFiles.size() (" +
- (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size()) +
- ") < minFiles (" + minFiles + ")");
- }
- file.getFile().delete();
+
+ freeFiles.add(jf);
+ freeFilesCount.getAndIncrement();
+ }
+ else {
+ if (trace) {
+ ActiveMQJournalLogger.LOGGER.trace("DataFiles.size() = " + dataFiles.size());
+ ActiveMQJournalLogger.LOGGER.trace("openedFiles.size() = " + openedFiles.size());
+ ActiveMQJournalLogger.LOGGER.trace("minfiles = " + minFiles);
+ ActiveMQJournalLogger.LOGGER.trace("Free Files = " + freeFilesCount.get());
+ ActiveMQJournalLogger.LOGGER.trace("File " + file +
+ " being deleted as freeFiles.size() + dataFiles.size() + 1 + openedFiles.size() (" +
+ (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size()) +
+ ") < minFiles (" + minFiles + ")");
}
+ file.getFile().delete();
+ }
- if (CHECK_CONSISTENCE)
- {
+ if (CHECK_CONSISTENCE) {
checkDataFiles();
}
}
- public Collection<JournalFile> getFreeFiles()
- {
+ public Collection<JournalFile> getFreeFiles() {
return freeFiles;
}
- public JournalFile getFreeFile()
- {
+ public JournalFile getFreeFile() {
JournalFile file = freeFiles.remove();
freeFilesCount.getAndDecrement();
return file;
@@ -467,8 +404,7 @@ public class JournalFilesRepository
// Opened files operations =======================================
- public int getOpenedFilesCount()
- {
+ public int getOpenedFilesCount() {
return openedFiles.size();
}
@@ -477,35 +413,28 @@ public class JournalFilesRepository
* <p>In case there are no cached opened files, this method will block until the file was opened,
* what would happen only if the system is under heavy load by another system (like a backup system, or a DB sharing the same box as ActiveMQ).</p>
*/
- public JournalFile openFile() throws InterruptedException
- {
- if (JournalFilesRepository.trace)
- {
+ public JournalFile openFile() throws InterruptedException {
+ if (JournalFilesRepository.trace) {
JournalFilesRepository.trace("enqueueOpenFile with openedFiles.size=" + openedFiles.size());
}
- if (openFilesExecutor == null)
- {
+ if (openFilesExecutor == null) {
pushOpenRunnable.run();
}
- else
- {
+ else {
openFilesExecutor.execute(pushOpenRunnable);
}
JournalFile nextFile = null;
- while (nextFile == null)
- {
+ while (nextFile == null) {
nextFile = openedFiles.poll(5, TimeUnit.SECONDS);
- if (nextFile == null)
- {
+ if (nextFile == null) {
ActiveMQJournalLogger.LOGGER.errorOpeningFile(new Exception("trace"));
}
}
- if (JournalFilesRepository.trace)
- {
+ if (JournalFilesRepository.trace) {
JournalFilesRepository.trace("Returning file " + nextFile);
}
@@ -515,23 +444,19 @@ public class JournalFilesRepository
/**
* Open a file and place it into the openedFiles queue
*/
- public void pushOpenedFile() throws Exception
- {
+ public void pushOpenedFile() throws Exception {
JournalFile nextOpenedFile = takeFile(true, true, true, false);
- if (JournalFilesRepository.trace)
- {
+ if (JournalFilesRepository.trace) {
JournalFilesRepository.trace("pushing openFile " + nextOpenedFile);
}
- if (!openedFiles.offer(nextOpenedFile))
- {
+ if (!openedFiles.offer(nextOpenedFile)) {
ActiveMQJournalLogger.LOGGER.failedToAddFile(nextOpenedFile);
}
}
- public void closeFile(final JournalFile file) throws Exception
- {
+ public void closeFile(final JournalFile file) throws Exception {
fileFactory.deactivateBuffer();
file.getFile().close();
dataFiles.add(file);
@@ -547,31 +472,25 @@ public class JournalFilesRepository
public JournalFile takeFile(final boolean keepOpened,
final boolean multiAIO,
final boolean initFile,
- final boolean tmpCompactExtension) throws Exception
- {
+ final boolean tmpCompactExtension) throws Exception {
JournalFile nextFile = null;
nextFile = freeFiles.poll();
- if (nextFile != null)
- {
+ if (nextFile != null) {
freeFilesCount.getAndDecrement();
}
- if (nextFile == null)
- {
+ if (nextFile == null) {
nextFile = createFile(keepOpened, multiAIO, initFile, tmpCompactExtension, -1);
}
- else
- {
- if (tmpCompactExtension)
- {
+ else {
+ if (tmpCompactExtension) {
SequentialFile sequentialFile = nextFile.getFile();
sequentialFile.renameTo(sequentialFile.getFileName() + ".cmp");
}
- if (keepOpened)
- {
+ if (keepOpened) {
openFile(nextFile, multiAIO);
}
}
@@ -586,8 +505,7 @@ public class JournalFilesRepository
*
* @param fileID the fileID to use when creating the file.
*/
- public JournalFile createRemoteBackupSyncFile(long fileID) throws Exception
- {
+ public JournalFile createRemoteBackupSyncFile(long fileID) throws Exception {
return createFile(false, false, true, false, fileID);
}
@@ -602,45 +520,34 @@ public class JournalFilesRepository
final boolean multiAIO,
final boolean init,
final boolean tmpCompact,
- final long fileIdPreSet) throws Exception
- {
- if (System.getSecurityManager() == null)
- {
+ final long fileIdPreSet) throws Exception {
+ if (System.getSecurityManager() == null) {
return createFile0(keepOpened, multiAIO, init, tmpCompact, fileIdPreSet);
}
- else
- {
- try
- {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<JournalFile>()
- {
+ else {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<JournalFile>() {
@Override
- public JournalFile run() throws Exception
- {
+ public JournalFile run() throws Exception {
return createFile0(keepOpened, multiAIO, init, tmpCompact, fileIdPreSet);
}
});
}
- catch (PrivilegedActionException e)
- {
+ catch (PrivilegedActionException e) {
throw unwrapException(e);
}
}
}
- private RuntimeException unwrapException(PrivilegedActionException e) throws Exception
- {
+ private RuntimeException unwrapException(PrivilegedActionException e) throws Exception {
Throwable c = e.getCause();
- if (c instanceof RuntimeException)
- {
+ if (c instanceof RuntimeException) {
throw (RuntimeException) c;
}
- else if (c instanceof Error)
- {
+ else if (c instanceof Error) {
throw (Error) c;
}
- else
- {
+ else {
throw new RuntimeException(c);
}
}
@@ -649,14 +556,12 @@ public class JournalFilesRepository
final boolean multiAIO,
final boolean init,
final boolean tmpCompact,
- final long fileIdPreSet) throws Exception
- {
+ final long fileIdPreSet) throws Exception {
long fileID = fileIdPreSet != -1 ? fileIdPreSet : generateFileID();
final String fileName = createFileName(tmpCompact, fileID);
- if (JournalFilesRepository.trace)
- {
+ if (JournalFilesRepository.trace) {
JournalFilesRepository.trace("Creating file " + fileName);
}
@@ -666,8 +571,7 @@ public class JournalFilesRepository
sequentialFile.open(1, false);
- if (init)
- {
+ if (init) {
sequentialFile.fill(fileSize);
JournalImpl.initFileHeader(fileFactory, sequentialFile, userVersion, fileID);
@@ -677,21 +581,17 @@ public class JournalFilesRepository
sequentialFile.close();
- if (JournalFilesRepository.trace)
- {
+ if (JournalFilesRepository.trace) {
JournalFilesRepository.trace("Renaming file " + tmpFileName + " as " + fileName);
}
sequentialFile.renameTo(fileName);
- if (keepOpened)
- {
- if (multiAIO)
- {
+ if (keepOpened) {
+ if (multiAIO) {
sequentialFile.open();
}
- else
- {
+ else {
sequentialFile.open(1, false);
}
sequentialFile.position(position);
@@ -705,44 +605,36 @@ public class JournalFilesRepository
* @param fileID
* @return
*/
- private String createFileName(final boolean tmpCompact, final long fileID)
- {
+ private String createFileName(final boolean tmpCompact, final long fileID) {
String fileName;
- if (tmpCompact)
- {
+ if (tmpCompact) {
fileName = filePrefix + "-" + fileID + "." + fileExtension + ".cmp";
}
- else
- {
+ else {
fileName = filePrefix + "-" + fileID + "." + fileExtension;
}
return fileName;
}
- private long generateFileID()
- {
+ private long generateFileID() {
return nextFileID.incrementAndGet();
}
/**
* Get the ID part of the name
*/
- private long getFileNameID(final String fileName)
- {
- try
- {
+ private long getFileNameID(final String fileName) {
+ try {
return Long.parseLong(fileName.substring(filePrefix.length() + 1, fileName.indexOf('.')));
}
- catch (Throwable e)
- {
+ catch (Throwable e) {
ActiveMQJournalLogger.LOGGER.errorRetrievingID(e, fileName);
return 0;
}
}
// Discard the old JournalFile and set it with a new ID
- private JournalFile reinitializeFile(final JournalFile file) throws Exception
- {
+ private JournalFile reinitializeFile(final JournalFile file) throws Exception {
long newFileID = generateFileID();
SequentialFile sf = file.getFile();
@@ -761,8 +653,7 @@ public class JournalFilesRepository
}
@Override
- public String toString()
- {
+ public String toString() {
return "JournalFilesRepository(dataFiles=" + dataFiles + ", freeFiles=" + freeFiles + ", openedFiles=" +
openedFiles + ")";
}