public PartitionIterator executeInternal(ReadExecutionController controller) { return UnfilteredPartitionIterators.filter(executeLocally(controller), nowInSec()); }
public static PartitionIterator mergeAndFilter(List<UnfilteredPartitionIterator> iterators, int nowInSec, MergeListener listener) { // TODO: we could have a somewhat faster version if we were to merge the UnfilteredRowIterators directly as RowIterators return filter(merge(iterators, nowInSec, listener), nowInSec); }
/** * Implementation of {@link ReadQuery#executeLocally(ReadExecutionController)}. * * @param executionController - the {@code ReadExecutionController} protecting the read. * @param sort - whether to sort the inner commands by partition key, required for merging the iterator * later on. This will be false when called by {@link ReadQuery#executeInternal(ReadExecutionController)} * because in this case it is safe to do so as there is no merging involved and we don't want to * change the old behavior which was to not sort by partition. * * @return - the iterator that can be used to retrieve the query result. */ private UnfilteredPartitionIterator executeLocally(ReadExecutionController executionController, boolean sort) { List<Pair<DecoratedKey, UnfilteredPartitionIterator>> partitions = new ArrayList<>(commands.size()); for (SinglePartitionReadCommand cmd : commands) partitions.add(Pair.of(cmd.partitionKey, cmd.executeLocally(executionController))); if (sort) Collections.sort(partitions, (p1, p2) -> p1.getLeft().compareTo(p2.getLeft())); return UnfilteredPartitionIterators.concat(partitions.stream().map(p -> p.getRight()).collect(Collectors.toList())); }
private UnfilteredPartitionIterator mergeWithShortReadProtection(List<UnfilteredPartitionIterator> results, InetAddress[] sources, DataLimits.Counter mergedResultCounter) { // If we have only one results, there is no read repair to do and we can't get short reads if (results.size() == 1) return results.get(0); /* * So-called short reads stems from nodes returning only a subset of the results they have due to the limit, * but that subset not being enough post-reconciliation. So if we don't have a limit, don't bother. */ if (!command.limits().isUnlimited()) for (int i = 0; i < results.size(); i++) results.set(i, extendWithShortReadProtection(results.get(i), sources[i], mergedResultCounter)); return UnfilteredPartitionIterators.merge(results, command.nowInSec(), new RepairMergeListener(sources)); }
private void buildKey(DecoratedKey key) { ReadQuery selectQuery = view.getReadQuery(); if (!selectQuery.selectsKey(key)) { logger.trace("Skipping {}, view query filters", key); return; } int nowInSec = FBUtilities.nowInSeconds(); SinglePartitionReadCommand command = view.getSelectStatement().internalReadForView(key, nowInSec); // We're rebuilding everything from what's on disk, so we read everything, consider that as new updates // and pretend that there is nothing pre-existing. UnfilteredRowIterator empty = UnfilteredRowIterators.noRowsIterator(baseCfs.metadata, key, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false); try (ReadExecutionController orderGroup = command.executionController(); UnfilteredRowIterator data = UnfilteredPartitionIterators.getOnlyElement(command.executeLocally(orderGroup), command)) { Iterator<Collection<Mutation>> mutations = baseCfs.keyspace.viewManager .forTable(baseCfs.metadata) .generateViewUpdates(Collections.singleton(view), data, empty, nowInSec, true); AtomicLong noBase = new AtomicLong(Long.MAX_VALUE); mutations.forEachRemaining(m -> StorageProxy.mutateMV(key.getKey(), m, true, noBase, System.nanoTime())); } }
private static ByteBuffer build(UnfilteredPartitionIterator iter, ColumnFilter selection) { try (DataOutputBuffer buffer = new DataOutputBuffer()) { UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter, selection, buffer, MessagingService.current_version); return buffer.buffer(); } catch (IOException e) { // We're serializing in memory so this shouldn't happen throw new RuntimeException(e); } } }
protected static ByteBuffer makeDigest(UnfilteredPartitionIterator iterator, ReadCommand command) { MessageDigest digest = FBUtilities.threadLocalMD5Digest(); UnfilteredPartitionIterators.digest(command, iterator, digest, command.digestVersion()); return ByteBuffer.wrap(digest.digest()); }
: checkCacheFilter(UnfilteredPartitionIterators.mergeLazily(iterators, nowInSec()), cfs);
private UnfilteredPartitionIterator mergeWithShortReadProtection(List<UnfilteredPartitionIterator> results, InetAddress[] sources, DataLimits.Counter mergedResultCounter) { // If we have only one results, there is no read repair to do and we can't get short reads if (results.size() == 1) return results.get(0); /* * So-called short reads stems from nodes returning only a subset of the results they have due to the limit, * but that subset not being enough post-reconciliation. So if we don't have a limit, don't bother. */ if (!command.limits().isUnlimited()) for (int i = 0; i < results.size(); i++) results.set(i, extendWithShortReadProtection(results.get(i), sources[i], mergedResultCounter)); return UnfilteredPartitionIterators.merge(results, command.nowInSec(), new RepairMergeListener(sources)); }
private void buildKey(DecoratedKey key) { ReadQuery selectQuery = view.getReadQuery(); if (!selectQuery.selectsKey(key)) { logger.trace("Skipping {}, view query filters", key); return; } int nowInSec = FBUtilities.nowInSeconds(); SinglePartitionReadCommand command = view.getSelectStatement().internalReadForView(key, nowInSec); // We're rebuilding everything from what's on disk, so we read everything, consider that as new updates // and pretend that there is nothing pre-existing. UnfilteredRowIterator empty = UnfilteredRowIterators.noRowsIterator(baseCfs.metadata, key, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false); try (ReadExecutionController orderGroup = command.executionController(); UnfilteredRowIterator data = UnfilteredPartitionIterators.getOnlyElement(command.executeLocally(orderGroup), command)) { Iterator<Collection<Mutation>> mutations = baseCfs.keyspace.viewManager .forTable(baseCfs.metadata) .generateViewUpdates(Collections.singleton(view), data, empty, nowInSec, true); AtomicLong noBase = new AtomicLong(Long.MAX_VALUE); mutations.forEachRemaining(m -> StorageProxy.mutateMV(key.getKey(), m, true, noBase, System.nanoTime())); } }
private static ByteBuffer build(UnfilteredPartitionIterator iter, ColumnFilter selection) { try (DataOutputBuffer buffer = new DataOutputBuffer()) { UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter, selection, buffer, MessagingService.current_version); return buffer.buffer(); } catch (IOException e) { // We're serializing in memory so this shouldn't happen throw new RuntimeException(e); } } }
protected static ByteBuffer makeDigest(UnfilteredPartitionIterator iterator, ReadCommand command) { MessageDigest digest = FBUtilities.threadLocalMD5Digest(); UnfilteredPartitionIterators.digest(command, iterator, digest, command.digestVersion()); return ByteBuffer.wrap(digest.digest()); }
: checkCacheFilter(UnfilteredPartitionIterators.mergeLazily(iterators, nowInSec()), cfs);
public PartitionIterator executeInternal(ReadExecutionController controller) { return UnfilteredPartitionIterators.filter(executeLocally(controller), nowInSec()); }
private UnfilteredPartitionIterator mergeWithShortReadProtection(List<UnfilteredPartitionIterator> results, InetAddress[] sources, DataLimits.Counter mergedResultCounter) { // If we have only one results, there is no read repair to do and we can't get short reads if (results.size() == 1) return results.get(0); /* * So-called short reads stems from nodes returning only a subset of the results they have due to the limit, * but that subset not being enough post-reconciliation. So if we don't have a limit, don't bother. */ if (!command.limits().isUnlimited()) for (int i = 0; i < results.size(); i++) results.set(i, extendWithShortReadProtection(results.get(i), sources[i], mergedResultCounter)); return UnfilteredPartitionIterators.merge(results, command.nowInSec(), new RepairMergeListener(sources)); }
private void buildKey(DecoratedKey key) { ReadQuery selectQuery = view.getReadQuery(); if (!selectQuery.selectsKey(key)) { logger.trace("Skipping {}, view query filters", key); return; } int nowInSec = FBUtilities.nowInSeconds(); SinglePartitionReadCommand command = view.getSelectStatement().internalReadForView(key, nowInSec); // We're rebuilding everything from what's on disk, so we read everything, consider that as new updates // and pretend that there is nothing pre-existing. UnfilteredRowIterator empty = UnfilteredRowIterators.noRowsIterator(baseCfs.metadata, key, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false); try (ReadExecutionController orderGroup = command.executionController(); UnfilteredRowIterator data = UnfilteredPartitionIterators.getOnlyElement(command.executeLocally(orderGroup), command)) { Iterator<Collection<Mutation>> mutations = baseCfs.keyspace.viewManager .forTable(baseCfs.metadata) .generateViewUpdates(Collections.singleton(view), data, empty, nowInSec, true); AtomicLong noBase = new AtomicLong(Long.MAX_VALUE); mutations.forEachRemaining(m -> StorageProxy.mutateMV(key.getKey(), m, true, noBase, System.nanoTime())); } }
private static ByteBuffer build(UnfilteredPartitionIterator iter, ColumnFilter selection) { try (DataOutputBuffer buffer = new DataOutputBuffer()) { UnfilteredPartitionIterators.serializerForIntraNode().serialize(iter, selection, buffer, MessagingService.current_version); return buffer.buffer(); } catch (IOException e) { // We're serializing in memory so this shouldn't happen throw new RuntimeException(e); } } }
protected static ByteBuffer makeDigest(UnfilteredPartitionIterator iterator, ReadCommand command) { MessageDigest digest = FBUtilities.threadLocalMD5Digest(); UnfilteredPartitionIterators.digest(command, iterator, digest, command.digestVersion()); return ByteBuffer.wrap(digest.digest()); }
/** * Implementation of {@link ReadQuery#executeLocally(ReadExecutionController)}. * * @param executionController - the {@code ReadExecutionController} protecting the read. * @param sort - whether to sort the inner commands by partition key, required for merging the iterator * later on. This will be false when called by {@link ReadQuery#executeInternal(ReadExecutionController)} * because in this case it is safe to do so as there is no merging involved and we don't want to * change the old behavior which was to not sort by partition. * * @return - the iterator that can be used to retrieve the query result. */ private UnfilteredPartitionIterator executeLocally(ReadExecutionController executionController, boolean sort) { List<Pair<DecoratedKey, UnfilteredPartitionIterator>> partitions = new ArrayList<>(commands.size()); for (SinglePartitionReadCommand cmd : commands) partitions.add(Pair.of(cmd.partitionKey, cmd.executeLocally(executionController))); if (sort) Collections.sort(partitions, (p1, p2) -> p1.getLeft().compareTo(p2.getLeft())); return UnfilteredPartitionIterators.concat(partitions.stream().map(p -> p.getRight()).collect(Collectors.toList())); }
: checkCacheFilter(UnfilteredPartitionIterators.mergeLazily(iterators, nowInSec()), cfs);