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);
}
}
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();
}
}
}
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;
}
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();
}
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);
}
Aggregations