|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.accumulo.test; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | + |
| 23 | +import java.util.Map; |
| 24 | +import java.util.SortedSet; |
| 25 | +import java.util.TreeSet; |
| 26 | + |
| 27 | +import org.apache.accumulo.core.client.Accumulo; |
| 28 | +import org.apache.accumulo.core.client.AccumuloClient; |
| 29 | +import org.apache.accumulo.core.client.admin.NewTableConfiguration; |
| 30 | +import org.apache.accumulo.core.conf.Property; |
| 31 | +import org.apache.accumulo.core.data.TableId; |
| 32 | +import org.apache.accumulo.core.spi.balancer.BalancerEnvironment; |
| 33 | +import org.apache.accumulo.core.spi.balancer.SimpleLoadBalancer; |
| 34 | +import org.apache.accumulo.core.spi.balancer.TableLoadBalancer; |
| 35 | +import org.apache.accumulo.core.util.UtilWaitThread; |
| 36 | +import org.apache.accumulo.minicluster.ServerType; |
| 37 | +import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; |
| 38 | +import org.apache.accumulo.test.functional.ConfigurableMacBase; |
| 39 | +import org.apache.accumulo.test.util.Wait; |
| 40 | +import org.apache.hadoop.conf.Configuration; |
| 41 | +import org.apache.hadoop.io.Text; |
| 42 | +import org.junit.jupiter.api.Test; |
| 43 | +import org.slf4j.Logger; |
| 44 | +import org.slf4j.LoggerFactory; |
| 45 | + |
| 46 | +public class BrokenBalancerIT extends ConfigurableMacBase { |
| 47 | + |
| 48 | + private static final Logger log = LoggerFactory.getLogger(BrokenBalancerIT.class); |
| 49 | + |
| 50 | + public static class BrokenBalancer extends SimpleLoadBalancer { |
| 51 | + public BrokenBalancer() { |
| 52 | + super(); |
| 53 | + } |
| 54 | + |
| 55 | + public BrokenBalancer(TableId tableId) { |
| 56 | + super(tableId); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public void init(BalancerEnvironment balancerEnvironment) { |
| 61 | + throw new IllegalStateException(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) { |
| 67 | + Map<String,String> siteConfig = cfg.getSiteConfig(); |
| 68 | + siteConfig.put(Property.TSERV_MAXMEM.getKey(), "10K"); |
| 69 | + siteConfig.put(Property.TSERV_MAJC_DELAY.getKey(), "50ms"); |
| 70 | + siteConfig.put(Property.MANAGER_TABLET_GROUP_WATCHER_INTERVAL.getKey(), "3s"); |
| 71 | + cfg.setSiteConfig(siteConfig); |
| 72 | + // ensure we have two tservers |
| 73 | + if (cfg.getNumTservers() != 2) { |
| 74 | + cfg.setNumTservers(2); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testBalancerException() throws Exception { |
| 80 | + String tableName = getUniqueNames(1)[0]; |
| 81 | + testBadBalancer(BrokenBalancer.class.getName(), tableName); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testBalancerNotFound() throws Exception { |
| 86 | + String tableName = getUniqueNames(1)[0]; |
| 87 | + testBadBalancer("org.apache.accumulo.abc.NonExistentBalancer", tableName); |
| 88 | + } |
| 89 | + |
| 90 | + private void testBadBalancer(String balancerClass, String tableName) throws Exception { |
| 91 | + try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) { |
| 92 | + SortedSet<Text> splits = new TreeSet<>(); |
| 93 | + for (int i = 0; i < 10; i++) { |
| 94 | + splits.add(new Text("" + i)); |
| 95 | + } |
| 96 | + var props = Map.of(Property.TABLE_LOAD_BALANCER.getKey(), balancerClass); |
| 97 | + NewTableConfiguration ntc = |
| 98 | + new NewTableConfiguration().withSplits(splits).setProperties(props); |
| 99 | + c.tableOperations().create(tableName, ntc); |
| 100 | + |
| 101 | + assertEquals(Map.of(" none", 11), BalanceIT.countLocations(c, tableName)); |
| 102 | + UtilWaitThread.sleep(5000); |
| 103 | + // scan should not be able to complete because the tablet should not be assigned |
| 104 | + assertEquals(Map.of(" none", 11), BalanceIT.countLocations(c, tableName)); |
| 105 | + |
| 106 | + // fix the balancer config |
| 107 | + log.info("fixing per tablet balancer"); |
| 108 | + c.tableOperations().setProperty(tableName, Property.TABLE_LOAD_BALANCER.getKey(), |
| 109 | + SimpleLoadBalancer.class.getName()); |
| 110 | + |
| 111 | + Wait.waitFor(() -> 2 == BalanceIT.countLocations(c, tableName).size()); |
| 112 | + |
| 113 | + // break the balancer at the system level |
| 114 | + log.info("breaking manager balancer"); |
| 115 | + c.instanceOperations().setProperty(Property.MANAGER_TABLET_BALANCER.getKey(), balancerClass); |
| 116 | + |
| 117 | + // add some tablet servers |
| 118 | + assertEquals(2, getCluster().getConfig().getNumTservers()); |
| 119 | + getCluster().getConfig().setNumTservers(5); |
| 120 | + getCluster().getClusterControl().start(ServerType.TABLET_SERVER); |
| 121 | + |
| 122 | + UtilWaitThread.sleep(5000); |
| 123 | + |
| 124 | + // should not have balanced across the two new tservers |
| 125 | + assertEquals(2, BalanceIT.countLocations(c, tableName).size()); |
| 126 | + |
| 127 | + // fix the system level balancer |
| 128 | + log.info("fixing manager balancer"); |
| 129 | + c.instanceOperations().setProperty(Property.MANAGER_TABLET_BALANCER.getKey(), |
| 130 | + TableLoadBalancer.class.getName()); |
| 131 | + |
| 132 | + // should eventually balance across all 5 tabletsevers |
| 133 | + Wait.waitFor(() -> 5 == BalanceIT.countLocations(c, tableName).size()); |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments