Search in sources :

Example 1 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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);
}
Also used : NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 2 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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);
}
Also used : ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 3 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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;
    }
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) Semaphore(java.util.concurrent.Semaphore) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 4 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory 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();
}
Also used : HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) Properties(java.util.Properties) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferedReader(java.io.BufferedReader) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 5 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class SyncCalculation method newFactory.

private static SequentialFileFactory newFactory(File datafolder, boolean datasync, JournalType journalType, int fileSize, int maxAIO) {
    SequentialFileFactory factory;
    if (journalType == JournalType.ASYNCIO && !LibaioContext.isLoaded()) {
        journalType = JournalType.NIO;
    }
    switch(journalType) {
        case NIO:
            factory = new NIOSequentialFileFactory(datafolder, 1).setDatasync(datasync);
            ((NIOSequentialFileFactory) factory).disableBufferReuse();
            factory.start();
            return factory;
        case ASYNCIO:
            factory = new AIOSequentialFileFactory(datafolder, maxAIO).setDatasync(datasync);
            factory.start();
            ((AIOSequentialFileFactory) factory).disableBufferReuse();
            return factory;
        case MAPPED:
            factory = new MappedSequentialFileFactory(datafolder, fileSize, false, 0, 0, null).setDatasync(datasync).disableBufferReuse();
            factory.start();
            return factory;
        default:
            throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(journalType);
    }
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Aggregations

NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)33 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)19 File (java.io.File)18 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)15 Test (org.junit.Test)11 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)4 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2