Search in sources :

Example 1 with ScanRequest

use of io.cdap.cdap.messaging.store.ScanRequest in project cdap by caskdata.

the class LevelDBMessageTable method scan.

@Override
protected CloseableIterator<RawMessageTableEntry> scan(ScanRequest scanRequest) throws IOException {
    Collection<LevelDBPartition> partitions = partitionManager.getPartitions(scanRequest.getStartTime());
    if (partitions.isEmpty()) {
        return CloseableIterator.empty();
    }
    RawMessageTableEntry tableEntry = new RawMessageTableEntry();
    TopicMetadata topicMetadata = scanRequest.getTopicMetadata();
    byte[] topic = MessagingUtils.toDataKeyPrefix(topicMetadata.getTopicId(), topicMetadata.getGeneration());
    MessageTableKey messageTableKey = MessageTableKey.fromTopic(topic);
    BiFunction<byte[], byte[], RawMessageTableEntry> decodeFunction = (key, value) -> {
        Map<String, byte[]> columns = decodeValue(value);
        messageTableKey.setFromRowKey(key);
        return tableEntry.set(messageTableKey, columns.get(TX_COL), columns.get(PAYLOAD_COL));
    };
    return new PartitionedDBScanIterator<>(partitions.iterator(), scanRequest.getStartRow(), scanRequest.getStopRow(), decodeFunction);
}
Also used : WriteBatch(org.iq80.leveldb.WriteBatch) MessagingUtils(io.cdap.cdap.messaging.MessagingUtils) DB(org.iq80.leveldb.DB) AbstractMessageTable(io.cdap.cdap.messaging.store.AbstractMessageTable) WriteOptions(org.iq80.leveldb.WriteOptions) Arrays(java.util.Arrays) ScanRequest(io.cdap.cdap.messaging.store.ScanRequest) MessageTable(io.cdap.cdap.messaging.store.MessageTable) Iterator(java.util.Iterator) DBException(org.iq80.leveldb.DBException) Collection(java.util.Collection) BiFunction(java.util.function.BiFunction) Bytes(io.cdap.cdap.api.common.Bytes) IOException(java.io.IOException) HashMap(java.util.HashMap) CloseableIterator(io.cdap.cdap.api.dataset.lib.CloseableIterator) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata) RawMessageTableEntry(io.cdap.cdap.messaging.store.RawMessageTableEntry) Map(java.util.Map) Preconditions(com.google.common.base.Preconditions) MessageTableKey(io.cdap.cdap.messaging.store.MessageTableKey) RollbackRequest(io.cdap.cdap.messaging.store.RollbackRequest) Nullable(javax.annotation.Nullable) RawMessageTableEntry(io.cdap.cdap.messaging.store.RawMessageTableEntry) HashMap(java.util.HashMap) Map(java.util.Map) TopicMetadata(io.cdap.cdap.messaging.TopicMetadata) MessageTableKey(io.cdap.cdap.messaging.store.MessageTableKey)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Bytes (io.cdap.cdap.api.common.Bytes)1 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)1 MessagingUtils (io.cdap.cdap.messaging.MessagingUtils)1 TopicMetadata (io.cdap.cdap.messaging.TopicMetadata)1 AbstractMessageTable (io.cdap.cdap.messaging.store.AbstractMessageTable)1 MessageTable (io.cdap.cdap.messaging.store.MessageTable)1 MessageTableKey (io.cdap.cdap.messaging.store.MessageTableKey)1 RawMessageTableEntry (io.cdap.cdap.messaging.store.RawMessageTableEntry)1 RollbackRequest (io.cdap.cdap.messaging.store.RollbackRequest)1 ScanRequest (io.cdap.cdap.messaging.store.ScanRequest)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 BiFunction (java.util.function.BiFunction)1 Nullable (javax.annotation.Nullable)1 DB (org.iq80.leveldb.DB)1