@Override public List<TopicId> listTopics() throws IOException { return listTopics(null, null); }
/** * Returns an iterator of {@link TopicMetadata} of all the topics including the ones that were deleted. * * @return {@link CloseableIterator} of {@link TopicMetadata} * @throws IOException if failed to scan topics */ public CloseableIterator<TopicMetadata> scanTopics() throws IOException { return scanTopics(null, null); }
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()); Iterators.addAll(metadatas, table.scanTopics()); Assert.assertEquals(2, metadatas.size()); Iterators.addAll(metadatas, table.scanTopics());
@Override public synchronized MetadataTable createMetadataTable() throws IOException { if (metadataTable != null) { return metadataTable; } File dbPath = getMetadataDBPath(metadataTableName); metadataTable = new LevelDBMetadataTable(LEVEL_DB_FACTORY.open(dbPath, dbOptions)); LOG.info("Messaging metadata table created at {}", dbPath); return metadataTable; }
@Override public synchronized MetadataTable createMetadataTable(String tableName) throws IOException { if (metadataTable != null) { return metadataTable; } File dbPath = ensureDirExists(new File(baseDir, NamespaceId.SYSTEM.getNamespace() + "." + tableName)); metadataTable = new LevelDBMetadataTable(LEVEL_DB_FACTORY.open(dbPath, dbOptions)); LOG.info("Messaging metadata table created at {}", dbPath); return metadataTable; }
/** * Returns an iterator of {@link TopicMetadata} of all the topics including the ones that were deleted. * * @return {@link CloseableIterator} of {@link TopicMetadata} * @throws IOException if failed to scan topics */ public CloseableIterator<TopicMetadata> scanTopics() throws IOException { return scanTopics(null, null); }
@Override public List<TopicId> listTopics() throws IOException { return listTopics(null, null); }
private List<TopicId> listTopics(@Nullable byte[] startKey, @Nullable byte[] stopKey) throws IOException { List<TopicId> topicList = new ArrayList<>(); try (CloseableIterator<TopicMetadata> iterator = scanTopics(startKey, stopKey)) { while (iterator.hasNext()) { TopicMetadata metadata = iterator.next(); if (metadata.exists()) { topicList.add(metadata.getTopicId()); } } } return topicList; }
@Override public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException { byte[] startKey = MessagingUtils.topicScanKey(namespaceId); byte[] stopKey = Bytes.stopKeyForPrefix(startKey); return listTopics(startKey, stopKey); }
private List<TopicId> listTopics(@Nullable byte[] startKey, @Nullable byte[] stopKey) throws IOException { List<TopicId> topicList = new ArrayList<>(); try (CloseableIterator<TopicMetadata> iterator = scanTopics(startKey, stopKey)) { while (iterator.hasNext()) { TopicMetadata metadata = iterator.next(); if (metadata.exists()) { topicList.add(metadata.getTopicId()); } } } return topicList; }
@Override public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException { byte[] startKey = MessagingUtils.topicScanKey(namespaceId); byte[] stopKey = Bytes.stopKeyForPrefix(startKey); return listTopics(startKey, stopKey); }
@Override public void run() { if (metadataTable == null || payloadTable == null || messageTable == null) { return; } long timeStamp = System.currentTimeMillis(); try (CloseableIterator<TopicMetadata> metadataIterator = metadataTable.scanTopics()) { while (metadataIterator.hasNext()) { TopicMetadata metadata = metadataIterator.next(); messageTable.pruneMessages(metadata, timeStamp); payloadTable.pruneMessages(metadata, timeStamp); } } catch (IOException ex) { LOG.debug("Unable to perform data cleanup in TMS LevelDB tables", ex); } } }
try (CloseableIterator<TopicMetadata> metadataIterator = metadataTable.scanTopics()) { while (metadataIterator.hasNext()) { TopicMetadata metadata = metadataIterator.next();