Search in sources :

Example 1 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10 method convertToStoredMessage.

private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
    final byte[] convertedContent = convertedContentAndMimeType.getContent();
    final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg, addressSpace, convertedContentAndMimeType.getMimeType(), convertedContent.length);
    final int metadataSize = messageMetaData_0_10.getStorableSize();
    return new StoredMessage<MessageMetaData_0_10>() {

        @Override
        public MessageMetaData_0_10 getMetaData() {
            return messageMetaData_0_10;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(convertedContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return convertedContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInMemory() {
            return true;
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType) MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 2 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method convertToStoredMessage.

private StoredMessage<MessageMetaData> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
    final byte[] convertedContent = convertedContentAndMimeType.getContent();
    final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg, convertedContentAndMimeType.getMimeType(), convertedContent.length, addressSpace);
    final int metadataSize = messageMetaData_0_8.getStorableSize();
    return new StoredMessage<MessageMetaData>() {

        @Override
        public MessageMetaData getMetaData() {
            return messageMetaData_0_8;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(convertedContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return convertedContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInMemory() {
            return true;
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) StoredMessage(org.apache.qpid.server.store.StoredMessage) ConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType) MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)

Example 3 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class MessageStoreSerializer_v1 method deserialize.

@Override
public void deserialize(final Map<String, UUID> queueMap, final MessageStore store, final InputStream inputStream) throws IOException {
    final Deserializer deserializer = new Deserializer(inputStream);
    Map<Long, StoredMessage<?>> messageMap = new HashMap<>();
    Map<UUID, UUID> queueIdMap = new HashMap<>();
    Record nextRecord = deserializer.readRecord();
    switch(nextRecord.getType()) {
        case VERSION:
            break;
        default:
            throw new IllegalArgumentException("Unexpected record type: " + nextRecord.getType() + " expecting VERSION");
    }
    nextRecord = deserializer.readRecord();
    nextRecord = deserializeQueueMappings(queueMap, queueIdMap, deserializer, nextRecord);
    nextRecord = deserializeMessages(messageMap, store, deserializer, nextRecord);
    nextRecord = deserializeMessageInstances(store, queueIdMap, messageMap, deserializer, nextRecord);
    nextRecord = deserializeDistributedTransactions(store, queueIdMap, messageMap, deserializer, nextRecord);
    if (nextRecord.getType() != RecordType.DIGEST) {
        throw new IllegalArgumentException("Unexpected record type '" + nextRecord.getType() + "' expecting DIGEST");
    }
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) HashMap(java.util.HashMap) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) UUID(java.util.UUID)

Example 4 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class SynchronousMessageStoreRecoverer method recover.

@Override
public ListenableFuture<Void> recover(QueueManagingVirtualHost<?> virtualHost) {
    EventLogger eventLogger = virtualHost.getEventLogger();
    MessageStore store = virtualHost.getMessageStore();
    MessageStore.MessageStoreReader storeReader = store.newMessageStoreReader();
    MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
    Map<Queue<?>, Integer> queueRecoveries = new TreeMap<>();
    Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
    Map<Long, StoredMessage<?>> unusedMessages = new TreeMap<>();
    Map<UUID, Integer> unknownQueuesWithMessages = new HashMap<>();
    Map<Queue<?>, Integer> queuesWithUnknownMessages = new HashMap<>();
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
    storeReader.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
    try {
        storeReader.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries, recoveredMessages, unusedMessages, unknownQueuesWithMessages, queuesWithUnknownMessages));
    } finally {
        if (!unknownQueuesWithMessages.isEmpty()) {
            unknownQueuesWithMessages.forEach((queueId, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue id '{}' as a queue with this " + "id does not appear in the configuration.", count, queueId);
            });
        }
        if (!queuesWithUnknownMessages.isEmpty()) {
            queuesWithUnknownMessages.forEach((queue, count) -> {
                LOGGER.info("Discarded {} entry(s) associated with queue '{}' as the referenced message " + "does not exist.", count, queue.getName());
            });
        }
    }
    for (Map.Entry<Queue<?>, Integer> entry : queueRecoveries.entrySet()) {
        Queue<?> queue = entry.getKey();
        Integer deliveredCount = entry.getValue();
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(deliveredCount, queue.getName()));
        eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(queue.getName(), true));
        queue.completeRecovery();
    }
    for (Queue<?> q : virtualHost.getChildren(Queue.class)) {
        if (!queueRecoveries.containsKey(q)) {
            q.completeRecovery();
        }
    }
    storeReader.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, eventLogger, logSubject, recoveredMessages, unusedMessages));
    for (StoredMessage<?> m : unusedMessages.values()) {
        LOGGER.debug("Message id '{}' is orphaned, removing", m.getMessageNumber());
        m.remove();
    }
    if (unusedMessages.size() > 0) {
        LOGGER.info("Discarded {} orphaned message(s).", unusedMessages.size());
    }
    eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
    eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
    return Futures.immediateFuture(null);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) TreeMap(java.util.TreeMap) StoredMessage(org.apache.qpid.server.store.StoredMessage) MessageStoreLogSubject(org.apache.qpid.server.logging.subjects.MessageStoreLogSubject) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with StoredMessage

use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.

the class AsynchronousMessageStoreRecovererTest method testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted.

public void testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted() throws Exception {
    Queue<?> queue = mock(Queue.class);
    when(queue.getId()).thenReturn(UUID.randomUUID());
    when(_virtualHost.getChildren(eq(Queue.class))).thenReturn(Collections.singleton(queue));
    when(_store.getNextMessageId()).thenReturn(3L);
    when(_store.newTransaction()).thenReturn(mock(Transaction.class));
    final List<StoredMessage<?>> testMessages = new ArrayList<>();
    StoredMessage<?> storedMessage = createTestMessage(1L);
    testMessages.add(storedMessage);
    StoredMessage<?> orphanedMessage = createTestMessage(2L);
    testMessages.add(orphanedMessage);
    StoredMessage newMessage = createTestMessage(4L);
    testMessages.add(newMessage);
    final MessageEnqueueRecord messageEnqueueRecord = mock(MessageEnqueueRecord.class);
    UUID id = queue.getId();
    when(messageEnqueueRecord.getQueueId()).thenReturn(id);
    when(messageEnqueueRecord.getMessageNumber()).thenReturn(1L);
    MockStoreReader storeReader = new MockStoreReader(Collections.singletonList(messageEnqueueRecord), testMessages);
    when(_store.newMessageStoreReader()).thenReturn(storeReader);
    AsynchronousMessageStoreRecoverer recoverer = new AsynchronousMessageStoreRecoverer();
    ListenableFuture<Void> result = recoverer.recover(_virtualHost);
    assertNull(result.get());
    verify(orphanedMessage, times(1)).remove();
    verify(newMessage, times(0)).remove();
    verify(queue).recover(argThat(new ArgumentMatcher<ServerMessage>() {

        @Override
        public boolean matches(final Object argument) {
            if (argument instanceof ServerMessage) {
                ServerMessage serverMessage = (ServerMessage) argument;
                return serverMessage.getMessageNumber() == storedMessage.getMessageNumber();
            }
            return false;
        }
    }), same(messageEnqueueRecord));
}
Also used : ArrayList(java.util.ArrayList) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Transaction(org.apache.qpid.server.store.Transaction) StoredMessage(org.apache.qpid.server.store.StoredMessage) ArgumentMatcher(org.mockito.ArgumentMatcher) UUID(java.util.UUID) Queue(org.apache.qpid.server.model.Queue)

Aggregations

StoredMessage (org.apache.qpid.server.store.StoredMessage)23 MessageReference (org.apache.qpid.server.message.MessageReference)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)4 Transaction (org.apache.qpid.server.store.Transaction)4 UUID (java.util.UUID)3 LogMessage (org.apache.qpid.server.logging.LogMessage)3 HashMap (java.util.HashMap)2 ObjectToMimeContentConverter (org.apache.qpid.server.message.mimecontentconverter.ObjectToMimeContentConverter)2 Queue (org.apache.qpid.server.model.Queue)2 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)2 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)2 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)2 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)2 MessageStore (org.apache.qpid.server.store.MessageStore)2 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)2 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1