@Test public void testOrder() { BusiestTracker tracker = newTestTracker(3); Collection<Tablet> data1 = createTablets("e1", 5L, "e2", 6L, "e3", 13L, "e4", 8L, "e5", 9L); List<ComparablePair<Long,KeyExtent>> busy1 = tracker.computeBusiest(data1); assertEquals(3, busy1.size()); assertEquals(newPair("e3", 13L), busy1.get(0)); assertEquals(newPair("e5", 9L), busy1.get(1)); assertEquals(newPair("e4", 8L), busy1.get(2)); Collection<Tablet> data2 = createTablets("e1", 15L, "e2", 17L, "e3", 13L, "e4", 20L, "e5", 9L); List<ComparablePair<Long,KeyExtent>> busy2 = tracker.computeBusiest(data2); assertEquals(3, busy2.size()); assertEquals(newPair("e4", 12L), busy2.get(0)); assertEquals(newPair("e2", 11L), busy2.get(1)); assertEquals(newPair("e1", 10L), busy2.get(2)); }
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);  }