@Test public void testTruncate() { BusiestTracker tracker = newTestTracker(3); Collection<Tablet> data1 = createTablets("e1", 5L, "e2", 6L, "e3", 7L, "e4", 8L, "e5", 8L); Collection<ComparablePair<Long,KeyExtent>> busy1 = tracker.computeBusiest(data1); assertEquals(createExpected("e3", 7L, "e4", 8L, "e5", 8L), new HashSet<>(busy1)); Collection<Tablet> data2 = createTablets("e1", 100L, "e2", 100L, "e3", 100L, "e4", 100L, "e5", 100L); Collection<ComparablePair<Long,KeyExtent>> busy2 = tracker.computeBusiest(data2); assertEquals(createExpected("e1", 100L - 5L, "e2", 100L - 6L, "e3", 100L - 7L), new HashSet<>(busy2)); Collection<Tablet> data3 = createTablets("e1", 112L, "e2", 110L, "e3", 111L, "e4", 112L, "e5", 110L, "e6", 50L); Collection<ComparablePair<Long,KeyExtent>> busy3 = tracker.computeBusiest(data3); assertEquals(createExpected("e1", 112L - 100L, "e4", 112L - 100L, "e6", 50L), new HashSet<>(busy3)); }
public List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets) { HashMap<KeyExtent,Long> counts = new HashMap<>(); ArrayList<ComparablePair<Long,KeyExtent>> tabletsWithDelta = new ArrayList<>(); for (Tablet tablet : tablets) { KeyExtent extent = tablet.getExtent(); long count = extractCount(tablet); if (count == 0) continue; counts.put(extent, count); long lastCount = lastCounts.getOrDefault(extent, 0L); long delta = (lastCount > count) ? count : count - lastCount; if (delta > 0) tabletsWithDelta.add(new ComparablePair<>(delta, extent)); } lastCounts = counts; return Ordering.natural().greatestOf(tabletsWithDelta, numBusiestTabletsToLog); }
BusiestTracker { public List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets) { HashMap<KeyExtent,Long> counts = new HashMap<>(); ArrayList<ComparablePair<Long,KeyExtent>> tabletsWithDelta = new ArrayList<>(); for (Tablet tablet : tablets) { KeyExtent extent = tablet.getExtent(); long count = extractCount(tablet); if (count == 0) continue; counts.put(extent, count); long lastCount = lastCounts.getOrDefault(extent, 0L); long delta = (lastCount > count) ? count : count - lastCount; if (delta > 0) tabletsWithDelta.add(new ComparablePair<>(delta, extent)); } lastCounts = counts; return Ordering.natural().greatestOf(tabletsWithDelta, numBusiestTabletsToLog); } }
BusiestTracker { public List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets) { HashMap<KeyExtent,Long> counts = new HashMap<>(); ArrayList<ComparablePair<Long,KeyExtent>> tabletsWithDelta = new ArrayList<>(); for (Tablet tablet : tablets) { KeyExtent extent = tablet.getExtent(); long count = extractCount(tablet); if (count == 0) continue; counts.put(extent, count); long lastCount = lastCounts.getOrDefault(extent, 0L); long delta = (lastCount > count) ? count : count - lastCount; if (delta > 0) tabletsWithDelta.add(new ComparablePair<>(delta, extent)); } lastCounts = counts; return Ordering.natural().greatestOf(tabletsWithDelta, numBusiestTabletsToLog); } BusiestTracker(int numBusiestTabletsToLog); }
BusiestTracker { public List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets) { HashMap<KeyExtent,Long> counts = new HashMap<>(); ArrayList<ComparablePair<Long,KeyExtent>> tabletsWithDelta = new ArrayList<>(); for (Tablet tablet : tablets) { KeyExtent extent = tablet.getExtent(); long count = extractCount(tablet); if (count == 0) continue; counts.put(extent, count); long lastCount = lastCounts.getOrDefault(extent, 0L); long delta = (lastCount > count) ? count : count - lastCount; if (delta > 0) tabletsWithDelta.add(new ComparablePair<>(delta, extent)); } lastCounts = counts; return Ordering.natural().greatestOf(tabletsWithDelta, numBusiestTabletsToLog); } BusiestTracker(int numBusiestTabletsToLog); List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets); }
BusiestTracker { public List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets) { HashMap<KeyExtent,Long> counts = new HashMap<>(); ArrayList<ComparablePair<Long,KeyExtent>> tabletsWithDelta = new ArrayList<>(); for (Tablet tablet : tablets) { KeyExtent extent = tablet.getExtent(); long count = extractCount(tablet); if (count == 0) continue; counts.put(extent, count); long lastCount = lastCounts.getOrDefault(extent, 0L); long delta = (lastCount > count) ? count : count - lastCount; if (delta > 0) tabletsWithDelta.add(new ComparablePair<>(delta, extent)); } lastCounts = counts; return Ordering.natural().greatestOf(tabletsWithDelta, numBusiestTabletsToLog); } BusiestTracker(int numBusiestTabletsToLog); List<ComparablePair<Long,KeyExtent>> computeBusiest(Collection<Tablet> tablets);  }