public static EntryList convert(RecordIterator<KeyValueEntry> iterator) throws BackendException { try { return StaticArrayEntryList.ofStaticBuffer(iterator, KVEntryGetter.INSTANCE); } finally { try { iterator.close(); } catch (IOException e) { throw new TemporaryBackendException(e); } } }
private EntryList convert(RecordIterator<KeyValueEntry> entries) throws BackendException { try { return StaticArrayEntryList.ofStaticBuffer(entries,kvEntryGetter); } finally { try { entries.close(); } catch (IOException e) { /* * IOException could be permanent or temporary. Choosing temporary * allows useful retries of transient failures but also allows * futile retries of permanent failures. */ throw new TemporaryBackendException(e); } } }
@Override public void run() { try { while (keyIterator.hasNext()) { StaticBuffer key = keyIterator.next(); RecordIterator<Entry> entries = keyIterator.getEntries(); if (!keyFilter.test(key)) continue; EntryList entryList = StaticArrayEntryList.ofStaticBuffer(entries, StaticArrayEntry.ENTRY_GETTER); queue.put(new SliceResult(query, key, entryList)); } finished = true; } catch (InterruptedException e) { log.error("Data-pulling thread interrupted while waiting on queue or data", e); } catch (Throwable e) { log.error("Could not load data from storage: {}",e); } finally { try { keyIterator.close(); } catch (IOException e) { log.warn("Could not close storage iterator ", e); } } }
private static EntryList fromResultSet(final ResultSet resultSet, final GetColVal<Tuple3<StaticBuffer, StaticBuffer, Row>, StaticBuffer> getter) { final Lazy<ArrayList<Row>> lazyList = Lazy.of(() -> Lists.newArrayList(resultSet)); // Use the Iterable overload of ofByteBuffer as it's able to allocate // the byte array up front. // To ensure that the Iterator instance is recreated, it is created // within the closure otherwise // the same iterator would be reused and would be exhausted. return StaticArrayEntryList.ofStaticBuffer(() -> Iterator.ofAll(lazyList.get()).map(row -> Tuple.of( StaticArrayBuffer.of(row.getBytes(COLUMN_COLUMN_NAME)), StaticArrayBuffer.of(row.getBytes(VALUE_COLUMN_NAME)), row)), getter); }