|
90 | 90 | import org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType;
|
91 | 91 | import org.apache.accumulo.core.metadata.schema.TabletsMetadata;
|
92 | 92 | import org.apache.accumulo.core.security.Authorizations;
|
| 93 | +import org.apache.accumulo.core.spi.compaction.DefaultCompactionPlanner; |
| 94 | +import org.apache.accumulo.core.spi.compaction.SimpleCompactionDispatcher; |
93 | 95 | import org.apache.accumulo.harness.AccumuloClusterHarness;
|
94 | 96 | import org.apache.accumulo.minicluster.ServerType;
|
95 | 97 | import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl;
|
@@ -897,6 +899,92 @@ private Map<String,Long> getFileSizeMap(AccumuloClient client, String tableName)
|
897 | 899 | }
|
898 | 900 | }
|
899 | 901 |
|
| 902 | + @Test |
| 903 | + public void testDeleteCompactionService() throws Exception { |
| 904 | + try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) { |
| 905 | + var uniqueNames = getUniqueNames(2); |
| 906 | + String table1 = uniqueNames[0]; |
| 907 | + String table2 = uniqueNames[1]; |
| 908 | + |
| 909 | + // create a compaction service named deleteme |
| 910 | + c.instanceOperations().setProperty( |
| 911 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "deleteme.planner", |
| 912 | + DefaultCompactionPlanner.class.getName()); |
| 913 | + c.instanceOperations().setProperty( |
| 914 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "deleteme.planner.opts.executors", |
| 915 | + "[{'name':'all','type':'internal','numThreads':1}]".replaceAll("'", "\"")); |
| 916 | + |
| 917 | + // create a compaction service named keepme |
| 918 | + c.instanceOperations().setProperty( |
| 919 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "keepme.planner", |
| 920 | + DefaultCompactionPlanner.class.getName()); |
| 921 | + c.instanceOperations().setProperty( |
| 922 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "keepme.planner.opts.executors", |
| 923 | + "[{'name':'all','type':'internal','numThreads':1}]".replaceAll("'", "\"")); |
| 924 | + |
| 925 | + // create a table that uses the compaction service deleteme |
| 926 | + Map<String,String> props = new HashMap<>(); |
| 927 | + props.put(Property.TABLE_COMPACTION_DISPATCHER.getKey(), |
| 928 | + SimpleCompactionDispatcher.class.getName()); |
| 929 | + props.put(Property.TABLE_COMPACTION_DISPATCHER_OPTS.getKey() + "service", "deleteme"); |
| 930 | + c.tableOperations().create(table1, new NewTableConfiguration().setProperties(props)); |
| 931 | + |
| 932 | + // create a table that uses the compaction service keepme |
| 933 | + props.clear(); |
| 934 | + props.put(Property.TABLE_COMPACTION_DISPATCHER.getKey(), |
| 935 | + SimpleCompactionDispatcher.class.getName()); |
| 936 | + props.put(Property.TABLE_COMPACTION_DISPATCHER_OPTS.getKey() + "service", "keepme"); |
| 937 | + c.tableOperations().create(table2, new NewTableConfiguration().setProperties(props)); |
| 938 | + |
| 939 | + try (var writer1 = c.createBatchWriter(table1); var writer2 = c.createBatchWriter(table2)) { |
| 940 | + for (int i = 0; i < 10; i++) { |
| 941 | + Mutation m = new Mutation("" + i); |
| 942 | + m.put("f", "q", "" + i); |
| 943 | + writer1.addMutation(m); |
| 944 | + writer2.addMutation(m); |
| 945 | + } |
| 946 | + } |
| 947 | + |
| 948 | + c.tableOperations().compact(table1, new CompactionConfig().setWait(true)); |
| 949 | + c.tableOperations().compact(table2, new CompactionConfig().setWait(true)); |
| 950 | + |
| 951 | + // delete the compaction service deleteme |
| 952 | + c.instanceOperations() |
| 953 | + .removeProperty(Property.COMPACTION_SERVICE_PREFIX.getKey() + "deleteme.planner"); |
| 954 | + c.instanceOperations().removeProperty( |
| 955 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "deleteme.planner.opts.executors"); |
| 956 | + |
| 957 | + // add a new compaction service named newcs |
| 958 | + c.instanceOperations().setProperty( |
| 959 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "newcs.planner", |
| 960 | + DefaultCompactionPlanner.class.getName()); |
| 961 | + c.instanceOperations().setProperty( |
| 962 | + Property.COMPACTION_SERVICE_PREFIX.getKey() + "newcs.planner.opts.executors", |
| 963 | + "[{'name':'all','type':'internal','numThreads':1}]".replaceAll("'", "\"")); |
| 964 | + |
| 965 | + // set table 1 to a compaction service newcs |
| 966 | + c.tableOperations().setProperty(table1, |
| 967 | + Property.TABLE_COMPACTION_DISPATCHER_OPTS.getKey() + "service", "newcs"); |
| 968 | + |
| 969 | + // ensure tables can still compact and are not impacted by the deleted compaction service |
| 970 | + for (int i = 0; i < 10; i++) { |
| 971 | + c.tableOperations().compact(table1, new CompactionConfig().setWait(true)); |
| 972 | + c.tableOperations().compact(table2, new CompactionConfig().setWait(true)); |
| 973 | + |
| 974 | + try (var scanner = c.createScanner(table1)) { |
| 975 | + assertEquals(9 * 10 / 2, scanner.stream().map(Entry::getValue) |
| 976 | + .mapToInt(v -> Integer.parseInt(v.toString())).sum()); |
| 977 | + } |
| 978 | + try (var scanner = c.createScanner(table2)) { |
| 979 | + assertEquals(9 * 10 / 2, scanner.stream().map(Entry::getValue) |
| 980 | + .mapToInt(v -> Integer.parseInt(v.toString())).sum()); |
| 981 | + } |
| 982 | + |
| 983 | + Thread.sleep(100); |
| 984 | + } |
| 985 | + } |
| 986 | + } |
| 987 | + |
900 | 988 | private int countFiles(AccumuloClient c) throws Exception {
|
901 | 989 | try (Scanner s = c.createScanner(AccumuloTable.METADATA.tableName(), Authorizations.EMPTY)) {
|
902 | 990 | s.fetchColumnFamily(new Text(TabletColumnFamily.NAME));
|
|
0 commit comments