@Test public void testGetCompactionPlan() throws Exception { assertEquals(10, DefaultConfiguration.getInstance().getCount(Property.TSERV_MAJC_THREAD_MAXOPEN)); DefaultCompactionStrategy s = new DefaultCompactionStrategy(); TestCompactionRequest request = createRequest(MajorCompactionReason.IDLE, "file1", 10, "file2", 10); s.gatherInformation(request); CompactionPlan plan = s.getCompactionPlan(request); assertTrue(plan.inputFiles.isEmpty()); request = createRequest(MajorCompactionReason.IDLE, "file1", 10, "file2", 10, "file3", 10); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(3, plan.inputFiles.size()); request = createRequest(MajorCompactionReason.USER, "file1", 10, "file2", 10); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(2, plan.inputFiles.size()); request = createRequest(MajorCompactionReason.NORMAL, "file0", 100, "file1", 10, "file2", 10, "file3", 10); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(3, plan.inputFiles.size()); assertEquals(asStringSet(plan.inputFiles), asSet("file1,file2,file3".split(","))); request = createRequest(MajorCompactionReason.NORMAL, "file0", 100, "file1", 100, "file2", 100, "file3", 10, "file4", 10, "file5", 10, "file6", 10, "file7", 10, "file8", 10, "file9", 10, "fileA", 10); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(8, plan.inputFiles.size()); assertEquals(asStringSet(plan.inputFiles), asSet("file3,file4,file5,file6,file7,file8,file9,fileA".split(","))); request = createRequest(MajorCompactionReason.NORMAL, "file0", 19683, "file1", 19683, "file2", 19683, "file3", 6561, "file4", 2187, "file5", 729, "file6", 243, "file7", 81, "file8", 27, "file9", 9, "fileA", 3, "fileB", 1); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(10, plan.inputFiles.size()); assertEquals(asStringSet(plan.inputFiles), asSet("file0,file1,file2,file3,file4,file5,file6,file7,file8,file9".split(","))); request = createRequest(MajorCompactionReason.NORMAL, "file1", 19683, "file2", 19683, "file3", 6561, "file4", 2187, "file5", 729, "file6", 243, "file7", 81, "file8", 27, "file9", 9, "fileA", 3, "fileB", 1); request.setMaxFilesPerTablet(10); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(2, plan.inputFiles.size()); assertEquals(asStringSet(plan.inputFiles), asSet("fileA,fileB".split(","))); request = createRequest(MajorCompactionReason.NORMAL, "file01", 1500, "file02", 1400, "file03", 1300, "file04", 1200, "file05", 1100, "file06", 1000, "file07", 900, "file08", 800, "file09", 700, "file10", 600, "file11", 500, "file12", 400, "file13", 400, "file14", 300, "file15", 200, "file16", 100, "file17", 9, "file18", 8, "file19", 7, "file20", 6, "file21", 5, "file22", 4, "file23", 3, "file24", 2, "file25", 1); request.setMaxFilesPerTablet(15); s.gatherInformation(request); plan = s.getCompactionPlan(request); assertEquals(10, plan.inputFiles.size()); assertEquals(asStringSet(plan.inputFiles), asSet("file12,file13,file14,file15,file16,file17,file18,file19,file20,file21".split(","))); }
@Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) { CompactionPlan result = new CompactionPlan(); List<StoredTabletFile> toCompact = findMapFilesToCompact(request); if (toCompact == null || toCompact.isEmpty()) return result; result.inputFiles.addAll(toCompact); return result; }
DefaultCompactionStrategy extends CompactionStrategy { @Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) { CompactionPlan result = new CompactionPlan(); List<StoredTabletFile> toCompact = findMapFilesToCompact(request); if (toCompact == null || toCompact.isEmpty()) return result; result.inputFiles.addAll(toCompact); return result; } }
DefaultCompactionStrategy extends CompactionStrategy { @Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) { CompactionPlan result = new CompactionPlan(); List<StoredTabletFile> toCompact = findMapFilesToCompact(request); if (toCompact == null || toCompact.isEmpty()) return result; result.inputFiles.addAll(toCompact); return result; }  }
DefaultCompactionStrategy extends CompactionStrategy { @Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) { CompactionPlan result = new CompactionPlan(); List<StoredTabletFile> toCompact = findMapFilesToCompact(request); if (toCompact == null || toCompact.isEmpty()) return result; result.inputFiles.addAll(toCompact); return result; }  @Override boolean shouldCompact(MajorCompactionRequest request); @Override CompactionPlan getCompactionPlan(MajorCompactionRequest request); }
DefaultCompactionStrategy extends CompactionStrategy { @Override public CompactionPlan getCompactionPlan(MajorCompactionRequest request) { CompactionPlan result = new CompactionPlan(); List<StoredTabletFile> toCompact = findMapFilesToCompact(request); if (toCompact == null || toCompact.isEmpty()) return result; result.inputFiles.addAll(toCompact); return result; }  @Override boolean shouldCompact(MajorCompactionRequest request); @Override CompactionPlan getCompactionPlan(MajorCompactionRequest request);  }