Search in sources :

Example 1 with SequentialFile

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

the class JournalStorageManager method deleteLargeMessageFile.

// This should be accessed from this package only
void deleteLargeMessageFile(final LargeServerMessage largeServerMessage) throws ActiveMQException {
    if (largeServerMessage.getPendingRecordID() < 0) {
        try {
            // The delete file happens asynchronously
            // And the client won't be waiting for the actual file to be deleted.
            // We set a temporary record (short lived) on the journal
            // to avoid a situation where the server is restarted and pending large message stays on forever
            largeServerMessage.setPendingRecordID(storePendingLargeMessage(largeServerMessage.getMessageID(), largeServerMessage.getPendingRecordID()));
        } catch (Exception e) {
            throw new ActiveMQInternalErrorException(e.getMessage(), e);
        }
    }
    final SequentialFile file = largeServerMessage.getFile();
    if (file == null) {
        return;
    }
    if (largeServerMessage.isDurable() && isReplicated()) {
        readLock();
        try {
            if (isReplicated() && replicator.isSynchronizing()) {
                synchronized (largeMessagesToDelete) {
                    largeMessagesToDelete.add(Long.valueOf(largeServerMessage.getMessageID()));
                    confirmLargeMessage(largeServerMessage);
                }
                return;
            }
        } finally {
            readUnLock();
        }
    }
    Runnable deleteAction = new Runnable() {

        @Override
        public void run() {
            try {
                readLock();
                try {
                    if (replicator != null) {
                        replicator.largeMessageDelete(largeServerMessage.getMessageID(), JournalStorageManager.this);
                    }
                    file.delete();
                    // The confirm could only be done after the actual delete is done
                    confirmLargeMessage(largeServerMessage);
                } finally {
                    readUnLock();
                }
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.journalErrorDeletingMessage(e, largeServerMessage.getMessageID());
            }
        }
    };
    if (executor == null) {
        deleteAction.run();
    } else {
        executor.execute(deleteAction);
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) 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)

Example 2 with SequentialFile

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

the class JournalStorageManager method sendLargeMessageFiles.

private void sendLargeMessageFiles(final Map<Long, Pair<String, Long>> pendingLargeMessages) throws Exception {
    Iterator<Map.Entry<Long, Pair<String, Long>>> iter = pendingLargeMessages.entrySet().iterator();
    while (started && iter.hasNext()) {
        Map.Entry<Long, Pair<String, Long>> entry = iter.next();
        String fileName = entry.getValue().getA();
        final long id = entry.getKey();
        long size = entry.getValue().getB();
        SequentialFile seqFile = largeMessagesFactory.createSequentialFile(fileName);
        if (!seqFile.exists())
            continue;
        if (replicator != null) {
            replicator.syncLargeMessageFile(seqFile, size, id);
        } else {
            throw ActiveMQMessageBundle.BUNDLE.replicatorIsNull();
        }
    }
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 3 with SequentialFile

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

the class LargeServerMessageInSync method joinSyncedData.

public synchronized void joinSyncedData(ByteBuffer buffer) throws Exception {
    if (deleted)
        return;
    SequentialFile mainSeqFile = mainLM.getFile();
    if (!mainSeqFile.isOpen()) {
        mainSeqFile.open();
    }
    try {
        if (appendFile != null) {
            if (logger.isTraceEnabled()) {
                logger.trace("joinSyncedData on " + mainLM + ", currentSize on mainMessage=" + mainSeqFile.size() + ", appendFile size = " + appendFile.size());
            }
            FileIOUtil.copyData(appendFile, mainSeqFile, buffer);
            deleteAppendFile();
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("joinSyncedData, appendFile is null, ignoring joinSyncedData on " + mainLM);
            }
        }
    } catch (Throwable e) {
        ActiveMQServerLogger.LOGGER.errorWhileSyncingData(mainLM.toString(), e);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("joinedSyncData on " + mainLM + " finished with " + mainSeqFile.size());
    }
    syncDone = true;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile)

Example 4 with SequentialFile

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

the class PagingStoreImpl method checkPageFileExists.

@Override
public boolean checkPageFileExists(final int pageNumber) {
    String fileName = createFileName(pageNumber);
    try {
        checkFileFactory();
    } catch (Exception ignored) {
    }
    SequentialFile file = fileFactory.createSequentialFile(fileName);
    return file.exists();
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 5 with SequentialFile

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

the class ReplicationEndpoint method handleReplicationSynchronization.

/**
 * Receives 'raw' journal/page/large-message data from live server for synchronization of logs.
 *
 * @param msg
 * @throws Exception
 */
private void handleReplicationSynchronization(ReplicationSyncFileMessage msg) throws Exception {
    long id = msg.getId();
    byte[] data = msg.getData();
    SequentialFile channel1;
    switch(msg.getFileType()) {
        case LARGE_MESSAGE:
            {
                ReplicatedLargeMessage largeMessage = lookupLargeMessage(id, false, false);
                if (!(largeMessage instanceof LargeServerMessageInSync)) {
                    ActiveMQServerLogger.LOGGER.largeMessageIncompatible();
                    return;
                }
                LargeServerMessageInSync largeMessageInSync = (LargeServerMessageInSync) largeMessage;
                channel1 = largeMessageInSync.getSyncFile();
                break;
            }
        case PAGE:
            {
                Page page = getPage(msg.getPageStore(), (int) msg.getId());
                channel1 = page.getFile();
                break;
            }
        case JOURNAL:
            {
                JournalSyncFile journalSyncFile = filesReservedForSync.get(msg.getJournalContent()).get(id);
                FileChannel channel2 = journalSyncFile.getChannel();
                if (data == null) {
                    channel2.close();
                    return;
                }
                channel2.write(ByteBuffer.wrap(data));
                return;
            }
        default:
            throw ActiveMQMessageBundle.BUNDLE.replicationUnhandledFileType(msg.getFileType());
    }
    if (data == null) {
        return;
    }
    if (!channel1.isOpen()) {
        channel1.open();
    }
    channel1.writeDirect(ByteBuffer.wrap(data), false);
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) FileChannel(java.nio.channels.FileChannel) LargeServerMessageInSync(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageInSync) Page(org.apache.activemq.artemis.core.paging.impl.Page)

Aggregations

SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)53 Test (org.junit.Test)21 ByteBuffer (java.nio.ByteBuffer)15 ArrayList (java.util.ArrayList)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)7 Pair (org.apache.activemq.artemis.api.core.Pair)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)4 Page (org.apache.activemq.artemis.core.paging.impl.Page)4 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)4 SimpleEncoding (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEncoding)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 IOCriticalErrorListener (org.apache.activemq.artemis.core.io.IOCriticalErrorListener)3 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2