keith-turner commented on code in PR #3451: URL: https://github.com/apache/accumulo/pull/3451#discussion_r1220032484
########## core/src/main/java/org/apache/accumulo/core/clientImpl/TableOperationsImpl.java: ########## @@ -2145,4 +2150,37 @@ public void setTabletHostingGoal(String tableName, Range range, TabletHostingGoa } } + @Override + public Stream<HostingGoalForTablet> getTabletHostingGoal(final String tableName, + final Range range) throws TableNotFoundException { + EXISTING_TABLE_NAME.validate(tableName); + + List<HostingGoalForTablet> hostingInfo = new ArrayList<>(); + + final Text scanRangeStart = (range.getStartKey() == null) ? null : range.getStartKey().getRow(); + TableId tableId = context.getTableId(tableName); + + try (TabletsMetadata m = context.getAmple().readTablets().forTable(tableId) + .overlapping(scanRangeStart, true, null).build()) { + + for (TabletMetadata tm : m) { + final KeyExtent tabletExtent = tm.getExtent(); + if (scanRangeStart != null && tm.getEndRow() != null + && tm.getEndRow().compareTo(scanRangeStart) < 0) { + // the end row of this tablet is before the start row, skip it + log.debug(">>>> tablet {} is before scan start range: {}", tabletExtent, scanRangeStart); + throw new RuntimeException("Bug in ample or this code."); + } + if (tm.getPrevEndRow() != null + && range.afterEndKey(new Key(tm.getPrevEndRow()).followingKey(PartialKey.ROW))) { + break; + } + hostingInfo + .add(new HostingGoalForTablet(new TabletIdImpl(tabletExtent), tm.getHostingGoal())); + } + + } Review Comment: The TabletsMetadata class has a stream() method. So the following would create a stream that closes the tablets metadata object (and therefore the scanner) when the stream is closed. ```java TabletsMetadata tabletsMetadata = context.getAmple().readTablets().forTable(tableId).overlapping(scanRangeStart, true, null) .fetch(HOSTING_GOAL, PREV_ROW).checkConsistency().build(); Stream<TabletMetadata> tabletStream = tabletsMetadata.stream().onClose(tabletsMetadata::close); ``` So with the stream above can use peek(), takeWhile(), and map() to returns a stream that does the transformation w/o buffering data in memory. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org