use of io.cdap.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);
}
}
use of io.cdap.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());
}
}
use of io.cdap.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());
}
}
use of io.cdap.cdap.messaging.store.MetadataTable in project cdap by caskdata.
the class HBaseTableFactory method createMetadataTable.
@Override
public MetadataTable createMetadataTable() throws IOException {
TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName);
Table table = null;
// If the table descriptor is in the cache, we assume the table exists.
if (!tableDescriptors.containsKey(tableId)) {
synchronized (this) {
if (!tableDescriptors.containsKey(tableId)) {
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
table = tableUtil.createTable(hConf, tableId);
tableDescriptors.put(tableId, table.getTableDescriptor());
}
}
}
}
if (table == null) {
table = tableUtil.createTable(hConf, tableId);
}
return new HBaseMetadataTable(tableUtil, table, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
use of io.cdap.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));
}
}
Aggregations