Search in sources :

Example 11 with MessageId

use of co.cask.cdap.messaging.data.MessageId in project cdap by caskdata.

the class DataCleanupTest method testPayloadTTLCleanup.

@Test
public void testPayloadTTLCleanup() throws Exception {
    try (MetadataTable metadataTable = getMetadataTable();
        PayloadTable payloadTable = getPayloadTable();
        MessageTable messageTable = getMessageTable()) {
        Assert.assertNotNull(messageTable);
        TopicId topicId = NamespaceId.DEFAULT.topic("t2");
        TopicMetadata topic = new TopicMetadata(topicId, "ttl", "3", TopicMetadata.GENERATION_KEY, Integer.toString(GENERATION));
        metadataTable.createTopic(topic);
        List<PayloadTable.Entry> entries = new ArrayList<>();
        entries.add(new TestPayloadEntry(topicId, GENERATION, "payloaddata", 101, (short) 0));
        payloadTable.store(entries.iterator());
        byte[] messageId = new byte[MessageId.RAW_ID_SIZE];
        MessageId.putRawId(0L, (short) 0, 0L, (short) 0, messageId, 0);
        CloseableIterator<PayloadTable.Entry> iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
        Assert.assertTrue(iterator.hasNext());
        PayloadTable.Entry entry = iterator.next();
        Assert.assertFalse(iterator.hasNext());
        Assert.assertEquals("payloaddata", Bytes.toString(entry.getPayload()));
        Assert.assertEquals(101L, entry.getTransactionWritePointer());
        iterator.close();
        forceFlushAndCompact(Table.PAYLOAD);
        // Entry should still be there since ttl has not expired
        iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
        Assert.assertTrue(iterator.hasNext());
        entry = iterator.next();
        Assert.assertFalse(iterator.hasNext());
        Assert.assertEquals("payloaddata", Bytes.toString(entry.getPayload()));
        Assert.assertEquals(101L, entry.getTransactionWritePointer());
        iterator.close();
        TimeUnit.SECONDS.sleep(3 * METADATA_CACHE_EXPIRY);
        forceFlushAndCompact(Table.PAYLOAD);
        iterator = payloadTable.fetch(topic, 101L, new MessageId(messageId), true, Integer.MAX_VALUE);
        Assert.assertFalse(iterator.hasNext());
        iterator.close();
        metadataTable.deleteTopic(topicId);
    }
}
Also used : ArrayList(java.util.ArrayList) TopicMetadata(co.cask.cdap.messaging.TopicMetadata) TopicId(co.cask.cdap.proto.id.TopicId) MessageId(co.cask.cdap.messaging.data.MessageId) Test(org.junit.Test)

Example 12 with MessageId

use of co.cask.cdap.messaging.data.MessageId in project cdap by caskdata.

the class DefaultMetricStore method getMetricsProcessorStats.

/**
 * Read the metrics processing stats from meta table and return the map of topic information to stats
 * @return Map of topic to metrics processing stats
 * @throws Exception
 */
@Override
public Map<String, MetricsProcessorStatus> getMetricsProcessorStats() throws Exception {
    MetricsConsumerMetaTable metaTable = metaTableSupplier.get();
    Map<String, MetricsProcessorStatus> processMap = new HashMap<>();
    for (TopicId topicId : metricsTopics) {
        TopicProcessMeta topicProcessMeta = metaTable.getTopicProcessMeta(new TopicIdMetaKey(topicId));
        if (topicProcessMeta != null) {
            MessageId messageId = new MessageId(topicProcessMeta.getMessageId());
            MetricsMessageId metricsMessageId = new MetricsMessageId(messageId.getPublishTimestamp(), messageId.getSequenceId(), messageId.getPayloadWriteTimestamp(), messageId.getPayloadSequenceId());
            processMap.put(topicId.getTopic(), new MetricsProcessorStatus(metricsMessageId, topicProcessMeta.getOldestMetricsTimestamp(), topicProcessMeta.getLatestMetricsTimestamp(), topicProcessMeta.getMessagesProcessed(), topicProcessMeta.getLastProcessedTimestamp()));
        }
    }
    return processMap;
}
Also used : MetricsConsumerMetaTable(co.cask.cdap.metrics.process.MetricsConsumerMetaTable) TopicProcessMeta(co.cask.cdap.metrics.process.TopicProcessMeta) TopicIdMetaKey(co.cask.cdap.metrics.process.TopicIdMetaKey) HashMap(java.util.HashMap) TopicId(co.cask.cdap.proto.id.TopicId) MetricsProcessorStatus(co.cask.cdap.api.metrics.MetricsProcessorStatus) MetricsMessageId(co.cask.cdap.api.metrics.MetricsMessageId) MetricsMessageId(co.cask.cdap.api.metrics.MetricsMessageId) MessageId(co.cask.cdap.messaging.data.MessageId)

Aggregations

MessageId (co.cask.cdap.messaging.data.MessageId)12 Test (org.junit.Test)11 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)10 TopicId (co.cask.cdap.proto.id.TopicId)10 ArrayList (java.util.ArrayList)9 TimeProvider (co.cask.cdap.common.utils.TimeProvider)4 RawMessage (co.cask.cdap.messaging.data.RawMessage)4 NamespaceId (co.cask.cdap.proto.id.NamespaceId)4 Transaction (org.apache.tephra.Transaction)3 RollbackDetail (co.cask.cdap.messaging.RollbackDetail)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TopicNotFoundException (co.cask.cdap.api.messaging.TopicNotFoundException)1 MetricsCollector (co.cask.cdap.api.metrics.MetricsCollector)1 MetricsMessageId (co.cask.cdap.api.metrics.MetricsMessageId)1 MetricsProcessorStatus (co.cask.cdap.api.metrics.MetricsProcessorStatus)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 StoreRequest (co.cask.cdap.messaging.StoreRequest)1 ImmutableMessageTableEntry (co.cask.cdap.messaging.store.ImmutableMessageTableEntry)1 MessageTable (co.cask.cdap.messaging.store.MessageTable)1 LevelDBMessageTableTest (co.cask.cdap.messaging.store.leveldb.LevelDBMessageTableTest)1