Search in sources :

Example 16 with JournalImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.

the class JournalImplTestUnit method internaltestSpeedNonTransactional.

private void internaltestSpeedNonTransactional() throws Exception {
    final long numMessages = 10000;
    int numFiles = (int) ((numMessages * 1024 + 512) / (10 * 1024 * 1024) * 1.3);
    if (numFiles < 2) {
        numFiles = 2;
    }
    JournalImplTestUnit.log.debug("num Files=" + numFiles);
    Journal journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    JournalImplTestUnit.log.debug("Adding data");
    SimpleEncoding data = new SimpleEncoding(700, (byte) 'j');
    long start = System.currentTimeMillis();
    for (int i = 0; i < numMessages; i++) {
        journal.appendAddRecord(i, (byte) 0, data, true);
    }
    long end = System.currentTimeMillis();
    double rate = 1000 * (double) numMessages / (end - start);
    JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
    journal.stop();
    journal = new JournalImpl(10 * 1024 * 1024, numFiles, numFiles, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    journal.stop();
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 17 with JournalImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.

the class JournalImplTestUnit method testSpeedTransactional.

@Test
public void testSpeedTransactional() throws Exception {
    Journal journal = new JournalImpl(10 * 1024 * 1024, 10, 10, 0, 0, getFileFactory(), "activemq-data", "amq", 5000);
    journal.start();
    journal.load(new ArrayList<RecordInfo>(), null, null);
    try {
        final int numMessages = 50050;
        SimpleEncoding data = new SimpleEncoding(1024, (byte) 'j');
        long start = System.currentTimeMillis();
        int count = 0;
        double[] rates = new double[50];
        for (int i = 0; i < 50; i++) {
            long startTrans = System.currentTimeMillis();
            for (int j = 0; j < 1000; j++) {
                journal.appendAddRecordTransactional(i, count++, (byte) 0, data);
            }
            journal.appendCommitRecord(i, true);
            long endTrans = System.currentTimeMillis();
            rates[i] = 1000 * (double) 1000 / (endTrans - startTrans);
        }
        long end = System.currentTimeMillis();
        for (double rate : rates) {
            JournalImplTestUnit.log.info("Transaction Rate = " + rate + " records/sec");
        }
        double rate = 1000 * (double) numMessages / (end - start);
        JournalImplTestUnit.log.info("Rate " + rate + " records/sec");
    } finally {
        journal.stop();
    }
}
Also used : RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) SimpleEncoding(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding) Journal(org.apache.activemq.artemis.core.journal.Journal) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Test(org.junit.Test)

Example 18 with JournalImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.

the class ActiveMQTestBase method internalCountJournalLivingRecords.

/**
 * This method will load a journal and count the living records
 *
 * @param config
 * @param messageJournal if true -> MessageJournal, false -> BindingsJournal
 * @return
 * @throws Exception
 */
protected HashMap<Integer, AtomicInteger> internalCountJournalLivingRecords(Configuration config, boolean messageJournal) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory ff;
    JournalImpl journal;
    if (messageJournal) {
        ff = new NIOSequentialFileFactory(config.getJournalLocation(), null, 1);
        journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, ff, "activemq-data", "amq", 1);
    } else {
        ff = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
        journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), ff, "activemq-bindings", "bindings", 1);
    }
    journal.start();
    final List<RecordInfo> committedRecords = new LinkedList<>();
    final List<PreparedTransactionInfo> preparedTransactions = new LinkedList<>();
    journal.load(committedRecords, preparedTransactions, null, false);
    for (RecordInfo info : committedRecords) {
        Integer ikey = new Integer(info.getUserRecordType());
        AtomicInteger value = recordsType.get(ikey);
        if (value == null) {
            value = new AtomicInteger();
            recordsType.put(ikey, value);
        }
        value.incrementAndGet();
    }
    journal.stop();
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PreparedTransactionInfo(org.apache.activemq.artemis.core.journal.PreparedTransactionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) LinkedList(java.util.LinkedList) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 19 with JournalImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.

the class ActiveMQTestBase method countBindingJournal.

protected HashMap<Integer, AtomicInteger> countBindingJournal(Configuration config) throws Exception {
    final HashMap<Integer, AtomicInteger> recordsType = new HashMap<>();
    SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getBindingsLocation(), null, 1);
    JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), config.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
    List<JournalFile> filesToRead = messagesJournal.orderFiles();
    for (JournalFile file : filesToRead) {
        JournalImpl.readJournalFile(messagesFF, file, new RecordTypeCounter(recordsType));
    }
    return recordsType;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) 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 20 with JournalImpl

use of org.apache.activemq.artemis.core.journal.impl.JournalImpl in project activemq-artemis by apache.

the class JournalStorageManager method startReplication.

@Override
public void startReplication(ReplicationManager replicationManager, PagingManager pagingManager, String nodeID, final boolean autoFailBack, long initialReplicationSyncTimeout) throws Exception {
    if (!started) {
        throw new IllegalStateException("JournalStorageManager must be started...");
    }
    assert replicationManager != null;
    if (!(messageJournal instanceof JournalImpl) || !(bindingsJournal instanceof JournalImpl)) {
        throw ActiveMQMessageBundle.BUNDLE.notJournalImpl();
    }
    // We first do a compact without any locks, to avoid copying unnecessary data over the network.
    // We do this without holding the storageManager lock, so the journal stays open while compact is being done
    originalMessageJournal.scheduleCompactAndBlock(-1);
    originalBindingsJournal.scheduleCompactAndBlock(-1);
    JournalFile[] messageFiles = null;
    JournalFile[] bindingsFiles = null;
    // We get a picture of the current sitaution on the large messages
    // and we send the current messages while more state is coming
    Map<Long, Pair<String, Long>> pendingLargeMessages = null;
    try {
        Map<SimpleString, Collection<Integer>> pageFilesToSync;
        storageManagerLock.writeLock().lock();
        try {
            if (isReplicated())
                throw new ActiveMQIllegalStateException("already replicating");
            replicator = replicationManager;
            if (!((JournalImpl) originalMessageJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
                throw new Exception("Live message journal is busy");
            }
            if (!((JournalImpl) originalBindingsJournal).flushAppendExecutor(10, TimeUnit.SECONDS)) {
                throw new Exception("Live bindings journal is busy");
            }
            // Establishes lock
            originalMessageJournal.synchronizationLock();
            originalBindingsJournal.synchronizationLock();
            try {
                originalBindingsJournal.replicationSyncPreserveOldFiles();
                originalMessageJournal.replicationSyncPreserveOldFiles();
                pagingManager.lock();
                try {
                    pagingManager.disableCleanup();
                    messageFiles = prepareJournalForCopy(originalMessageJournal, JournalContent.MESSAGES, nodeID, autoFailBack);
                    bindingsFiles = prepareJournalForCopy(originalBindingsJournal, JournalContent.BINDINGS, nodeID, autoFailBack);
                    pageFilesToSync = getPageInformationForSync(pagingManager);
                    pendingLargeMessages = recoverPendingLargeMessages();
                } finally {
                    pagingManager.unlock();
                }
            } finally {
                originalMessageJournal.synchronizationUnlock();
                originalBindingsJournal.synchronizationUnlock();
            }
            bindingsJournal = new ReplicatedJournal(((byte) 0), originalBindingsJournal, replicator);
            messageJournal = new ReplicatedJournal((byte) 1, originalMessageJournal, replicator);
            // We need to send the list while locking otherwise part of the body might get sent too soon
            // it will send a list of IDs that we are allocating
            replicator.sendLargeMessageIdListMessage(pendingLargeMessages);
        } finally {
            storageManagerLock.writeLock().unlock();
        }
        sendJournalFile(messageFiles, JournalContent.MESSAGES);
        sendJournalFile(bindingsFiles, JournalContent.BINDINGS);
        sendLargeMessageFiles(pendingLargeMessages);
        sendPagesToBackup(pageFilesToSync, pagingManager);
        storageManagerLock.writeLock().lock();
        try {
            if (replicator != null) {
                replicator.sendSynchronizationDone(nodeID, initialReplicationSyncTimeout);
                performCachedLargeMessageDeletes();
            }
        } finally {
            storageManagerLock.writeLock().unlock();
        }
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.unableToStartReplication(e);
        stopReplication();
        throw e;
    } finally {
        // Re-enable compact and reclaim of journal files
        originalBindingsJournal.replicationSyncFinished();
        originalMessageJournal.replicationSyncFinished();
        pagingManager.resumeCleanup();
    }
}
Also used : ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) JournalFile(org.apache.activemq.artemis.core.journal.impl.JournalFile) Collection(java.util.Collection) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Pair(org.apache.activemq.artemis.api.core.Pair)

Aggregations

JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)41 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)20 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)19 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)13 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)13 Test (org.junit.Test)12 File (java.io.File)10 ArrayList (java.util.ArrayList)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)6 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)6 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)5 Pair (org.apache.activemq.artemis.api.core.Pair)4 Journal (org.apache.activemq.artemis.core.journal.Journal)4 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Configuration (org.apache.activemq.artemis.core.config.Configuration)3 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)3