Search in sources :

Example 1 with RawPayloadTableEntry

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

the class LevelDBPayloadTable method read.

@Override
protected CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
    final DBScanIterator iterator = new DBScanIterator(levelDB, startRow, stopRow);
    return new AbstractCloseableIterator<RawPayloadTableEntry>() {

        private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();

        private boolean closed = false;

        private int maxLimit = limit;

        @Override
        protected RawPayloadTableEntry computeNext() {
            if (closed || maxLimit <= 0 || (!iterator.hasNext())) {
                return endOfData();
            }
            Map.Entry<byte[], byte[]> row = iterator.next();
            maxLimit--;
            return tableEntry.set(row.getKey(), row.getValue());
        }

        @Override
        public void close() {
            try {
                iterator.close();
            } finally {
                endOfData();
                closed = true;
            }
        }
    };
}
Also used : AbstractCloseableIterator(io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator) RawPayloadTableEntry(io.cdap.cdap.messaging.store.RawPayloadTableEntry) Map(java.util.Map)

Example 2 with RawPayloadTableEntry

use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by cdapio.

the class HBasePayloadTable method read.

@Override
public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
    Scan scan = tableUtil.buildScan().setStartRow(startRow).setStopRow(stopRow).setCaching(scanCacheRows).build();
    final ResultScanner scanner = DistributedScanner.create(table, scan, rowKeyDistributor, scanExecutor);
    return new AbstractCloseableIterator<RawPayloadTableEntry>() {

        private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();

        private boolean closed = false;

        private int maxLimit = limit;

        @Override
        protected RawPayloadTableEntry computeNext() {
            if (closed || maxLimit <= 0) {
                return endOfData();
            }
            Result result;
            try {
                result = scanner.next();
            } catch (IOException e) {
                throw exceptionHandler.handleAndWrap(e);
            }
            if (result == null) {
                return endOfData();
            }
            maxLimit--;
            return tableEntry.set(rowKeyDistributor.getOriginalKey(result.getRow()), result.getValue(columnFamily, COL));
        }

        @Override
        public void close() {
            try {
                scanner.close();
            } finally {
                endOfData();
                closed = true;
            }
        }
    };
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) AbstractCloseableIterator(io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator) Scan(org.apache.hadoop.hbase.client.Scan) RawPayloadTableEntry(io.cdap.cdap.messaging.store.RawPayloadTableEntry) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Example 3 with RawPayloadTableEntry

use of io.cdap.cdap.messaging.store.RawPayloadTableEntry in project cdap by cdapio.

the class LevelDBPayloadTable method read.

@Override
protected CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
    final DBScanIterator iterator = new DBScanIterator(levelDB, startRow, stopRow);
    return new AbstractCloseableIterator<RawPayloadTableEntry>() {

        private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();

        private boolean closed = false;

        private int maxLimit = limit;

        @Override
        protected RawPayloadTableEntry computeNext() {
            if (closed || maxLimit <= 0 || (!iterator.hasNext())) {
                return endOfData();
            }
            Map.Entry<byte[], byte[]> row = iterator.next();
            maxLimit--;
            return tableEntry.set(row.getKey(), row.getValue());
        }

        @Override
        public void close() {
            try {
                iterator.close();
            } finally {
                endOfData();
                closed = true;
            }
        }
    };
}
Also used : AbstractCloseableIterator(io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator) RawPayloadTableEntry(io.cdap.cdap.messaging.store.RawPayloadTableEntry) Map(java.util.Map)

Example 4 with RawPayloadTableEntry

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

the class HBasePayloadTable method persist.

@Override
public void persist(Iterator<RawPayloadTableEntry> entries) throws IOException {
    List<Put> batchPuts = new ArrayList<>();
    while (entries.hasNext()) {
        RawPayloadTableEntry tableEntry = entries.next();
        Put put = tableUtil.buildPut(rowKeyDistributor.getDistributedKey(tableEntry.getKey())).add(columnFamily, COL, tableEntry.getValue()).build();
        batchPuts.add(put);
    }
    try {
        if (!batchPuts.isEmpty()) {
            mutator.mutate(batchPuts);
            mutator.flush();
        }
    } catch (IOException e) {
        throw exceptionHandler.handle(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RawPayloadTableEntry(io.cdap.cdap.messaging.store.RawPayloadTableEntry) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put)

Example 5 with RawPayloadTableEntry

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

the class HBasePayloadTable method read.

@Override
public CloseableIterator<RawPayloadTableEntry> read(byte[] startRow, byte[] stopRow, final int limit) throws IOException {
    Scan scan = tableUtil.buildScan().setStartRow(startRow).setStopRow(stopRow).setCaching(scanCacheRows).build();
    final ResultScanner scanner = DistributedScanner.create(table, scan, rowKeyDistributor, scanExecutor);
    return new AbstractCloseableIterator<RawPayloadTableEntry>() {

        private final RawPayloadTableEntry tableEntry = new RawPayloadTableEntry();

        private boolean closed = false;

        private int maxLimit = limit;

        @Override
        protected RawPayloadTableEntry computeNext() {
            if (closed || maxLimit <= 0) {
                return endOfData();
            }
            Result result;
            try {
                result = scanner.next();
            } catch (IOException e) {
                throw exceptionHandler.handleAndWrap(e);
            }
            if (result == null) {
                return endOfData();
            }
            maxLimit--;
            return tableEntry.set(rowKeyDistributor.getOriginalKey(result.getRow()), result.getValue(columnFamily, COL));
        }

        @Override
        public void close() {
            try {
                scanner.close();
            } finally {
                endOfData();
                closed = true;
            }
        }
    };
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) AbstractCloseableIterator(io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator) Scan(org.apache.hadoop.hbase.client.Scan) RawPayloadTableEntry(io.cdap.cdap.messaging.store.RawPayloadTableEntry) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

RawPayloadTableEntry (io.cdap.cdap.messaging.store.RawPayloadTableEntry)8 IOException (java.io.IOException)6 AbstractCloseableIterator (io.cdap.cdap.api.dataset.lib.AbstractCloseableIterator)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Put (org.apache.hadoop.hbase.client.Put)2 Result (org.apache.hadoop.hbase.client.Result)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Scan (org.apache.hadoop.hbase.client.Scan)2 DBException (org.iq80.leveldb.DBException)2 WriteBatch (org.iq80.leveldb.WriteBatch)2