use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class DescribeJournal method describeBindingsJournal.
public static void describeBindingsJournal(final File bindingsDir, PrintStream out, boolean safe) throws Exception {
SequentialFileFactory bindingsFF = new NIOSequentialFileFactory(bindingsDir, null, 1);
JournalImpl bindings = new JournalImpl(1024 * 1024, 2, 2, -1, 0, bindingsFF, "activemq-bindings", "bindings", 1);
describeJournal(bindingsFF, bindings, bindingsDir, out, safe);
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class DescribeJournal method describeMessagesJournal.
public static DescribeJournal describeMessagesJournal(final File messagesDir, PrintStream out, boolean safe) throws Exception {
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1);
// Will use only default values. The load function should adapt to anything different
ConfigurationImpl defaultValues = new ConfigurationImpl();
JournalImpl messagesJournal = new JournalImpl(defaultValues.getJournalFileSize(), defaultValues.getJournalMinFiles(), defaultValues.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1);
return describeJournal(messagesFF, messagesJournal, messagesDir, out, safe);
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class JournalStorageManager method init.
@Override
protected void init(Configuration config, IOCriticalErrorListener criticalErrorListener) {
if (!EnumSet.allOf(JournalType.class).contains(config.getJournalType())) {
throw ActiveMQMessageBundle.BUNDLE.invalidJournal();
}
bindingsFF = new NIOSequentialFileFactory(config.getBindingsLocation(), criticalErrorListener, config.getJournalMaxIO_NIO());
bindingsFF.setDatasync(config.isJournalDatasync());
Journal localBindings = new JournalImpl(ioExecutorFactory, 1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), config.getJournalFileOpenTimeout(), bindingsFF, "activemq-bindings", "bindings", 1, 0, criticalErrorListener);
bindingsJournal = localBindings;
originalBindingsJournal = localBindings;
switch(config.getJournalType()) {
case NIO:
if (criticalErrorListener != null) {
ActiveMQServerLogger.LOGGER.journalUseNIO();
}
journalFF = new NIOSequentialFileFactory(config.getJournalLocation(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), config.getJournalMaxIO_NIO(), config.isLogJournalWriteRate(), criticalErrorListener, getCriticalAnalyzer());
break;
case ASYNCIO:
if (criticalErrorListener != null) {
ActiveMQServerLogger.LOGGER.journalUseAIO();
}
journalFF = new AIOSequentialFileFactory(config.getJournalLocation(), config.getJournalBufferSize_AIO(), config.getJournalBufferTimeout_AIO(), config.getJournalMaxIO_AIO(), config.isLogJournalWriteRate(), criticalErrorListener, getCriticalAnalyzer());
break;
case MAPPED:
if (criticalErrorListener != null) {
ActiveMQServerLogger.LOGGER.journalUseMAPPED();
}
journalFF = new MappedSequentialFileFactory(config.getJournalLocation(), config.getJournalFileSize(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), criticalErrorListener);
break;
default:
throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(config.getJournalType());
}
journalFF.setDatasync(config.isJournalDatasync());
int fileSize = config.getJournalFileSize();
// we need to correct the file size if its not a multiple of the alignement
int modulus = fileSize % journalFF.getAlignment();
if (modulus != 0) {
int difference = modulus;
int low = config.getJournalFileSize() - difference;
int high = low + journalFF.getAlignment();
fileSize = difference < journalFF.getAlignment() / 2 ? low : high;
ActiveMQServerLogger.LOGGER.invalidJournalFileSize(config.getJournalFileSize(), fileSize, journalFF.getAlignment());
}
Journal localMessage = createMessageJournal(config, criticalErrorListener, fileSize);
messageJournal = localMessage;
originalMessageJournal = localMessage;
largeMessagesDirectory = config.getLargeMessagesDirectory();
largeMessagesFactory = new NIOSequentialFileFactory(config.getLargeMessagesLocation(), false, criticalErrorListener, 1);
if (config.getPageMaxConcurrentIO() != 1) {
pageMaxConcurrentIO = new Semaphore(config.getPageMaxConcurrentIO());
} else {
pageMaxConcurrentIO = null;
}
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class DecodeJournal method importJournal.
public static void importJournal(final String directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final Reader reader) throws Exception {
File journalDir = new File(directory);
if (!journalDir.exists()) {
if (!journalDir.mkdirs())
System.err.println("Could not create directory " + directory);
}
NIOSequentialFileFactory nio = new NIOSequentialFileFactory(new File(directory), null, 1);
JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1);
if (journal.orderFiles().size() != 0) {
throw new IllegalStateException("Import needs to create a brand new journal");
}
journal.start();
// The journal is empty, as we checked already. Calling load just to initialize the internal data
journal.loadInternalOnly();
BufferedReader buffReader = new BufferedReader(reader);
String line;
HashMap<Long, AtomicInteger> txCounters = new HashMap<>();
long lineNumber = 0;
while ((line = buffReader.readLine()) != null) {
lineNumber++;
String[] splitLine = line.split(",");
if (splitLine[0].equals("#File")) {
txCounters.clear();
continue;
}
Properties lineProperties = parseLine(splitLine);
String operation = null;
try {
operation = lineProperties.getProperty("operation");
if (operation.equals("AddRecord")) {
RecordInfo info = parseRecord(lineProperties);
journal.appendAddRecord(info.id, info.userRecordType, info.data, false);
} else if (operation.equals("AddRecordTX")) {
long txID = parseLong("txID", lineProperties);
AtomicInteger counter = getCounter(txID, txCounters);
counter.incrementAndGet();
RecordInfo info = parseRecord(lineProperties);
journal.appendAddRecordTransactional(txID, info.id, info.userRecordType, info.data);
} else if (operation.equals("UpdateTX")) {
long txID = parseLong("txID", lineProperties);
AtomicInteger counter = getCounter(txID, txCounters);
counter.incrementAndGet();
RecordInfo info = parseRecord(lineProperties);
journal.appendUpdateRecordTransactional(txID, info.id, info.userRecordType, info.data);
} else if (operation.equals("Update")) {
RecordInfo info = parseRecord(lineProperties);
journal.appendUpdateRecord(info.id, info.userRecordType, info.data, false);
} else if (operation.equals("DeleteRecord")) {
long id = parseLong("id", lineProperties);
try {
journal.appendDeleteRecord(id, false);
} catch (IllegalStateException ignored) {
// If not found it means the append/update records were reclaimed already
}
} else if (operation.equals("DeleteRecordTX")) {
long txID = parseLong("txID", lineProperties);
long id = parseLong("id", lineProperties);
AtomicInteger counter = getCounter(txID, txCounters);
counter.incrementAndGet();
journal.appendDeleteRecordTransactional(txID, id);
} else if (operation.equals("Prepare")) {
long txID = parseLong("txID", lineProperties);
int numberOfRecords = parseInt("numberOfRecords", lineProperties);
AtomicInteger counter = getCounter(txID, txCounters);
byte[] data = parseEncoding("extraData", lineProperties);
if (counter.get() == numberOfRecords) {
journal.appendPrepareRecord(txID, data, false);
} else {
System.err.println("Transaction " + txID + " at line " + lineNumber + " is incomplete. The prepare record expected " + numberOfRecords + " while the import only had " + counter);
}
} else if (operation.equals("Commit")) {
long txID = parseLong("txID", lineProperties);
int numberOfRecords = parseInt("numberOfRecords", lineProperties);
AtomicInteger counter = getCounter(txID, txCounters);
if (counter.get() == numberOfRecords) {
journal.appendCommitRecord(txID, false);
} else {
System.err.println("Transaction " + txID + " at line " + lineNumber + " is incomplete. The commit record expected " + numberOfRecords + " while the import only had " + counter);
}
} else if (operation.equals("Rollback")) {
long txID = parseLong("txID", lineProperties);
journal.appendRollbackRecord(txID, false);
} else {
System.err.println("Invalid operation " + operation + " at line " + lineNumber);
}
} catch (Exception ex) {
System.err.println("Error at line " + lineNumber + ", operation=" + operation + " msg = " + ex.getMessage());
}
}
journal.stop();
}
use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.
the class ShutdownOnCriticalIOErrorMoveNextTest method createServer.
ActiveMQServer createServer(String folder) throws Exception {
final AtomicBoolean blocked = new AtomicBoolean(false);
Configuration conf = createConfig(folder);
ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
conf.setPersistenceEnabled(true);
ActiveMQServer server = new ActiveMQServerImpl(conf, securityManager) {
@Override
protected StorageManager createStorageManager() {
JournalStorageManager storageManager = new JournalStorageManager(conf, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO) {
@Override
protected Journal createMessageJournal(Configuration config, IOCriticalErrorListener criticalErrorListener, int fileSize) {
return new JournalImpl(ioExecutorFactory, fileSize, config.getJournalMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactMinFiles(), config.getJournalCompactPercentage(), config.getJournalFileOpenTimeout(), journalFF, "activemq-data", "amq", journalFF.getMaxIO(), 0, criticalErrorListener) {
@Override
protected void moveNextFile(boolean scheduleReclaim) throws Exception {
super.moveNextFile(scheduleReclaim);
if (blocked.get()) {
throw new IllegalStateException("forcibly down");
}
}
};
}
@Override
public void storeMessage(Message message) throws Exception {
super.storeMessage(message);
blocked.set(true);
}
};
this.getCriticalAnalyzer().add(storageManager);
return storageManager;
}
};
return server;
}
Aggregations