Search in sources :

Example 1 with MetadataTable

use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class LevelDBMetadataTableTest method testScanTopics.

@Test
public void testScanTopics() throws Exception {
    try (MetadataTable metadataTable = createMetadataTable()) {
        LevelDBMetadataTable table = (LevelDBMetadataTable) metadataTable;
        TopicMetadata t1 = new TopicMetadata(NamespaceId.CDAP.topic("t1"), ImmutableMap.of(TopicMetadata.TTL_KEY, "10", TopicMetadata.GENERATION_KEY, "1"));
        TopicMetadata t2 = new TopicMetadata(NamespaceId.SYSTEM.topic("t2"), ImmutableMap.of(TopicMetadata.TTL_KEY, "20", TopicMetadata.GENERATION_KEY, "1"));
        metadataTable.createTopic(t1);
        metadataTable.createTopic(t2);
        List<TopicId> allTopics = table.listTopics();
        Assert.assertEquals(2, allTopics.size());
        List<TopicMetadata> metadatas = new ArrayList<>();
        Iterators.addAll(metadatas, table.scanTopics());
        Assert.assertEquals(2, metadatas.size());
        allTopics = table.listTopics(NamespaceId.CDAP);
        Assert.assertEquals(1, allTopics.size());
        allTopics = table.listTopics(NamespaceId.SYSTEM);
        Assert.assertEquals(1, allTopics.size());
        metadataTable.deleteTopic(t1.getTopicId());
        metadatas.clear();
        Iterators.addAll(metadatas, table.scanTopics());
        Assert.assertEquals(2, metadatas.size());
        Assert.assertEquals(1, metadataTable.listTopics().size());
        Assert.assertEquals(1, metadataTable.listTopics(NamespaceId.SYSTEM).size());
        Assert.assertTrue(metadataTable.listTopics(NamespaceId.CDAP).isEmpty());
        metadataTable.deleteTopic(t2.getTopicId());
        metadatas.clear();
        Iterators.addAll(metadatas, table.scanTopics());
        for (TopicMetadata metadata : metadatas) {
            Assert.assertEquals(-1, metadata.getGeneration());
        }
        Assert.assertTrue(metadataTable.listTopics().isEmpty());
    }
}
Also used : MetadataTable(co.cask.cdap.messaging.store.MetadataTable) ArrayList(java.util.ArrayList) TopicId(co.cask.cdap.proto.id.TopicId) TopicMetadata(co.cask.cdap.messaging.TopicMetadata) Test(org.junit.Test) MetadataTableTest(co.cask.cdap.messaging.store.MetadataTableTest)

Example 2 with MetadataTable

use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method deleteTopic.

@Override
public void deleteTopic(TopicId topicId) throws TopicNotFoundException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        metadataTable.deleteTopic(topicId);
        topicCache.invalidate(topicId);
        messageTableWriterCache.invalidate(topicId);
        payloadTableWriterCache.invalidate(topicId);
    }
}
Also used : MetadataTable(co.cask.cdap.messaging.store.MetadataTable)

Example 3 with MetadataTable

use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method createTopic.

@Override
public void createTopic(TopicMetadata topicMetadata) throws TopicAlreadyExistsException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        Map<String, String> properties = createDefaultProperties();
        properties.putAll(topicMetadata.getProperties());
        metadataTable.createTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
    }
}
Also used : MetadataTable(co.cask.cdap.messaging.store.MetadataTable) TopicMetadata(co.cask.cdap.messaging.TopicMetadata)

Example 4 with MetadataTable

use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class HBaseTableCoprocessorTestRun method testInvalidTx.

@Test
public void testInvalidTx() throws Exception {
    try (MetadataTable metadataTable = getMetadataTable();
        MessageTable messageTable = getMessageTable()) {
        TopicId topicId = NamespaceId.DEFAULT.topic("invalidTx");
        TopicMetadata topic = new TopicMetadata(topicId, TopicMetadata.TTL_KEY, "1000000", TopicMetadata.GENERATION_KEY, Integer.toString(GENERATION));
        metadataTable.createTopic(topic);
        List<MessageTable.Entry> entries = new ArrayList<>();
        long invalidTxWritePtr = invalidList.toRawList().get(0);
        entries.add(new TestMessageEntry(topicId, GENERATION, "data", invalidTxWritePtr, (short) 0));
        messageTable.store(entries.iterator());
        // Fetch the entries and make sure we are able to read it
        try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
            checkEntry(iterator, invalidTxWritePtr);
        }
        // Fetch the entries with tx and make sure we are able to read it
        Transaction tx = new Transaction(V[8], V[8], new long[0], new long[0], -1);
        try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
            checkEntry(iterator, invalidTxWritePtr);
        }
        // Now run full compaction
        forceFlushAndCompact(Table.MESSAGE);
        // Try to fetch the entry non-transactionally and the entry should still be there
        try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
            checkEntry(iterator, invalidTxWritePtr);
        }
        // Fetch the entries transactionally and we should see no entries returned
        try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, tx)) {
            Assert.assertFalse(iterator.hasNext());
        }
        metadataTable.deleteTopic(topicId);
        // Sleep so that the metadata cache expires
        TimeUnit.SECONDS.sleep(3 * METADATA_CACHE_EXPIRY);
        forceFlushAndCompact(Table.MESSAGE);
        // Test deletion of messages from a deleted topic
        try (CloseableIterator<MessageTable.Entry> iterator = messageTable.fetch(topic, 0, Integer.MAX_VALUE, null)) {
            Assert.assertFalse(iterator.hasNext());
        }
    }
}
Also used : Transaction(org.apache.tephra.Transaction) MetadataTable(co.cask.cdap.messaging.store.MetadataTable) MessageTable(co.cask.cdap.messaging.store.MessageTable) ArrayList(java.util.ArrayList) TopicId(co.cask.cdap.proto.id.TopicId) TopicMetadata(co.cask.cdap.messaging.TopicMetadata) DataCleanupTest(co.cask.cdap.messaging.store.DataCleanupTest) Test(org.junit.Test)

Example 5 with MetadataTable

use of co.cask.cdap.messaging.store.MetadataTable in project cdap by caskdata.

the class CoreMessagingService method updateTopic.

@Override
public void updateTopic(TopicMetadata topicMetadata) throws TopicNotFoundException, IOException {
    try (MetadataTable metadataTable = createMetadataTable()) {
        Map<String, String> properties = createDefaultProperties();
        properties.putAll(topicMetadata.getProperties());
        metadataTable.updateTopic(new TopicMetadata(topicMetadata.getTopicId(), properties, true));
        topicCache.invalidate(topicMetadata.getTopicId());
    }
}
Also used : MetadataTable(co.cask.cdap.messaging.store.MetadataTable) TopicMetadata(co.cask.cdap.messaging.TopicMetadata)

Aggregations

MetadataTable (co.cask.cdap.messaging.store.MetadataTable)5 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)4 TopicId (co.cask.cdap.proto.id.TopicId)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DataCleanupTest (co.cask.cdap.messaging.store.DataCleanupTest)1 MessageTable (co.cask.cdap.messaging.store.MessageTable)1 MetadataTableTest (co.cask.cdap.messaging.store.MetadataTableTest)1 Transaction (org.apache.tephra.Transaction)1