/** * 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 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); } } }
@Override protected RawMessageTableEntry computeNext() { if (closed || (!iterator.hasNext())) { return endOfData(); } Map.Entry<byte[], byte[]> row = iterator.next(); Map<String, byte[]> columns = decodeValue(row.getValue()); return tableEntry.set(row.getKey(), columns.get(TX_COL), columns.get(PAYLOAD_COL)); }
@Override public List<TopicId> listTopics() throws IOException { return listTopics(null, null); }
@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 PayloadTable createPayloadTable(String tableName) throws IOException { if (payloadTable != null) { return payloadTable; } File dbPath = ensureDirExists(new File(baseDir, NamespaceId.SYSTEM.getNamespace() + "." + tableName)); payloadTable = new LevelDBPayloadTable(LEVEL_DB_FACTORY.open(dbPath, dbOptions)); LOG.info("Messaging payload table created at {}", dbPath); return payloadTable; }
@Override public synchronized MessageTable createMessageTable(String tableName) throws IOException { if (messageTable != null) { return messageTable; } File dbPath = ensureDirExists(new File(baseDir, NamespaceId.SYSTEM.getNamespace() + "." + tableName)); messageTable = new LevelDBMessageTable(LEVEL_DB_FACTORY.open(dbPath, dbOptions)); LOG.info("Messaging message table created at {}", dbPath); return messageTable; }
@Override public void close() { try { iterator.close(); } finally { endOfData(); closed = true; } } };
private File getDataDBPath(String tableName, TopicId topicId, int generation) throws IOException { return getDataDBPath(tableName, topicId, generation, true); }
@Override protected MessageTable getMessageTable(TopicMetadata topicMetadata) throws Exception { MessageTable messageTable = super.getMessageTable(topicMetadata); return new CachingMessageTable(cConf, messageTable, cacheProvider); }
@Override protected RawMessageTableEntry computeNext() { if (closed || (!iterator.hasNext())) { return endOfData(); } Map.Entry<byte[], byte[]> row = iterator.next(); Map<String, byte[]> columns = decodeValue(row.getValue()); return tableEntry.set(row.getKey(), columns.get(TX_COL), columns.get(PAYLOAD_COL)); }
/** * 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); }
@Override public void close() { try { iterator.close(); } finally { endOfData(); closed = true; } } };