/** * Scans for program run information * * @param limit maximum number of task info to return * @param lastProgramRunId an optional {@link ProgramRunId} returned from previous scan to continue the scanning * @return a {@link List} of {@link ProgramRunId} to the corresponding {@link ProgramOptions} for each run */ public List<Map.Entry<ProgramRunId, ProgramOptions>> scan(int limit, @Nullable ProgramRunId lastProgramRunId) { MDSKey startKey = new MDSKey.Builder().add(KEY_PREFIX).build(); MDSKey stopKey = new MDSKey(Bytes.stopKeyForPrefix(startKey.getKey())); if (lastProgramRunId != null) { // If there is a start program run id, scan from that id instead of from the beginning startKey = getKey(lastProgramRunId); } List<Map.Entry<ProgramRunId, ProgramOptions>> result = new LinkedList<>(); super.<ProgramOptions>scan(startKey, stopKey, ProgramOptions.class, keyValue -> { if (result.size() >= limit) { return false; } ProgramRunId programRunId = getProgramRunId(keyValue.getKey()); // Skip the lastProgramRunId if (lastProgramRunId != null && lastProgramRunId.equals(programRunId)) { return true; } result.add(Maps.immutableEntry(programRunId, keyValue.getValue())); return true; }); return result; }
/** * Scans for program run information * * @param limit maximum number of task info to return * @param lastProgramRunId an optional {@link ProgramRunId} returned from previous scan to continue the scanning * @return a {@link List} of {@link ProgramRunId} to the corresponding {@link ProgramOptions} for each run */ public List<Map.Entry<ProgramRunId, ProgramOptions>> scan(int limit, @Nullable ProgramRunId lastProgramRunId) { MDSKey startKey = new MDSKey.Builder().add(KEY_PREFIX).build(); MDSKey stopKey = new MDSKey(Bytes.stopKeyForPrefix(startKey.getKey())); if (lastProgramRunId != null) { // If there is a start program run id, scan from that id instead of from the beginning startKey = getKey(lastProgramRunId); } List<Map.Entry<ProgramRunId, ProgramOptions>> result = new LinkedList<>(); super.<ProgramOptions>scan(startKey, stopKey, ProgramOptions.class, keyValue -> { if (result.size() >= limit) { return false; } ProgramRunId programRunId = getProgramRunId(keyValue.getKey()); // Skip the lastProgramRunId if (lastProgramRunId != null && lastProgramRunId.equals(programRunId)) { return true; } result.add(Maps.immutableEntry(programRunId, keyValue.getValue())); return true; }); return result; }
final ScanFunction function = new ScanFunction(scanLimit); final MDSKey finalStart = start; txnl.execute(() -> metadataStoreDataset.scan(finalStart, end, Integer.class, function)); if (function.getNumProcessed() == 0) { break;