@Test public void testSplitCurrentByRegexUsingOverlappingPools() { ServerContext context = createMockContext(); replay(context); initFactory(new TestServerConfigurationFactory(context) { @Override public synchronized AccumuloConfiguration getSystemConfiguration() { HashMap<String,String> props = new HashMap<>(DEFAULT_TABLE_PROPERTIES); props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + FOO.getTableName(), "r.*"); props.put(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*|r02.*"); return new ConfigurationCopy(props); } }); Map<String,SortedMap<TServerInstance,TabletServerStatus>> groups = this.splitCurrentByRegex(createCurrent(15)); assertEquals(3, groups.size()); assertTrue(groups.containsKey(FOO.getTableName())); assertTrue(groups.containsKey(DEFAULT_POOL)); for (String pool : new String[] {FOO.getTableName(), DEFAULT_POOL}) { SortedMap<TServerInstance,TabletServerStatus> fooHosts = groups.get(pool); assertEquals(15, fooHosts.size()); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.11:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.12:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.13:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.14:9997", 1))); assertTrue(fooHosts.containsKey(new TServerInstance("192.168.0.15:9997", 1))); } assertTrue(groups.containsKey(BAR.getTableName())); SortedMap<TServerInstance,TabletServerStatus> barHosts = groups.get(BAR.getTableName()); assertEquals(10, barHosts.size()); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.1:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.2:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.3:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.4:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.5:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.6:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.7:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.8:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.9:9997", 1))); assertTrue(barHosts.containsKey(new TServerInstance("192.168.0.10:9997", 1))); }
protected synchronized Map<String,SortedMap<TServerInstance,TabletServerStatus>> splitCurrentByRegex(SortedMap<TServerInstance,TabletServerStatus> current) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool); if (np == null) { np = new TreeMap<>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } if (newPools.get(DEFAULT_POOL) == null) { LOG.warn("Default pool is empty; assigning all tablet servers to the default pool"); SortedMap<TServerInstance,TabletServerStatus> dp = new TreeMap<>(current.comparator()); dp.putAll(current); newPools.put(DEFAULT_POOL, dp); } pools = newPools; LOG.trace("Pool to TabletServer mapping:"); if (LOG.isTraceEnabled()) { for (Entry<String,SortedMap<TServerInstance,TabletServerStatus>> e : pools.entrySet()) { LOG.trace("\tpool: {} -> tservers: {}", e.getKey(), e.getValue().keySet()); } } return pools; }
HostRegexTableLoadBalancer extends TableLoadBalancer { protected synchronized Map<String,SortedMap<TServerInstance,TabletServerStatus>> splitCurrentByRegex(SortedMap<TServerInstance,TabletServerStatus> current) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool); if (np == null) { np = new TreeMap<>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } if (newPools.get(DEFAULT_POOL) == null) { LOG.warn("Default pool is empty; assigning all tablet servers to the default pool"); SortedMap<TServerInstance,TabletServerStatus> dp = new TreeMap<>(current.comparator()); dp.putAll(current); newPools.put(DEFAULT_POOL, dp); } pools = newPools; LOG.trace("Pool to TabletServer mapping:"); if (LOG.isTraceEnabled()) { for (Entry<String,SortedMap<TServerInstance,TabletServerStatus>> e : pools.entrySet()) { LOG.trace("\tpool: {} -> tservers: {}", e.getKey(), e.getValue().keySet()); } } return pools; } }
HostRegexTableLoadBalancer extends TableLoadBalancer { protected synchronized Map<String,SortedMap<TServerInstance,TabletServerStatus>> splitCurrentByRegex(SortedMap<TServerInstance,TabletServerStatus> current) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool); if (np == null) { np = new TreeMap<>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } if (newPools.get(DEFAULT_POOL) == null) { LOG.warn("Default pool is empty; assigning all tablet servers to the default pool"); SortedMap<TServerInstance,TabletServerStatus> dp = new TreeMap<>(current.comparator()); dp.putAll(current); newPools.put(DEFAULT_POOL, dp); } pools = newPools; LOG.trace("Pool to TabletServer mapping:"); if (LOG.isTraceEnabled()) { for (Entry<String,SortedMap<TServerInstance,TabletServerStatus>> e : pools.entrySet()) { LOG.trace("\tpool: {} -> tservers: {}", e.getKey(), e.getValue().keySet()); } } return pools; }  }
HostRegexTableLoadBalancer extends TableLoadBalancer { protected synchronized Map<String,SortedMap<TServerInstance,TabletServerStatus>> splitCurrentByRegex(SortedMap<TServerInstance,TabletServerStatus> current) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool); if (np == null) { np = new TreeMap<>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } if (newPools.get(DEFAULT_POOL) == null) { LOG.warn("Default pool is empty; assigning all tablet servers to the default pool"); SortedMap<TServerInstance,TabletServerStatus> dp = new TreeMap<>(current.comparator()); dp.putAll(current); newPools.put(DEFAULT_POOL, dp); } pools = newPools; LOG.trace("Pool to TabletServer mapping:"); if (LOG.isTraceEnabled()) { for (Entry<String,SortedMap<TServerInstance,TabletServerStatus>> e : pools.entrySet()) { LOG.trace("\tpool: {} -> tservers: {}", e.getKey(), e.getValue().keySet()); } } return pools; }  @Override String toString(); Map<String,Pattern> getPoolNameToRegexPattern(); int getMaxMigrations(); int getMaxOutstandingMigrations(); long getOobCheckMillis(); boolean isIpBasedRegex(); @Override void init(ServerContext context); @Override void getAssignments(SortedMap<TServerInstance,TabletServerStatus> current,
      Map<KeyExtent,TServerInstance> unassigned, Map<KeyExtent,TServerInstance> assignments); @Override long balance(SortedMap<TServerInstance,TabletServerStatus> current,
      Set<KeyExtent> migrations, List<TabletMigration> migrationsOut); }
HostRegexTableLoadBalancer extends TableLoadBalancer { protected synchronized Map<String,SortedMap<TServerInstance,TabletServerStatus>> splitCurrentByRegex(SortedMap<TServerInstance,TabletServerStatus> current) { LOG.debug("Performing pool recheck - regrouping tablet servers based on regular expressions"); Map<String,SortedMap<TServerInstance,TabletServerStatus>> newPools = new HashMap<>(); for (Entry<TServerInstance,TabletServerStatus> e : current.entrySet()) { List<String> poolNames = getPoolNamesForHost(e.getKey().host()); for (String pool : poolNames) { SortedMap<TServerInstance,TabletServerStatus> np = newPools.get(pool); if (np == null) { np = new TreeMap<>(current.comparator()); newPools.put(pool, np); } np.put(e.getKey(), e.getValue()); } } if (newPools.get(DEFAULT_POOL) == null) { LOG.warn("Default pool is empty; assigning all tablet servers to the default pool"); SortedMap<TServerInstance,TabletServerStatus> dp = new TreeMap<>(current.comparator()); dp.putAll(current); newPools.put(DEFAULT_POOL, dp); } pools = newPools; LOG.trace("Pool to TabletServer mapping:"); if (LOG.isTraceEnabled()) { for (Entry<String,SortedMap<TServerInstance,TabletServerStatus>> e : pools.entrySet()) { LOG.trace("\tpool: {} -> tservers: {}", e.getKey(), e.getValue().keySet()); } } return pools; }  @Override String toString(); Map<String,Pattern> getPoolNameToRegexPattern(); int getMaxMigrations(); int getMaxOutstandingMigrations(); long getOobCheckMillis(); boolean isIpBasedRegex(); @Override void init(ServerContext context); @Override void getAssignments(SortedMap<TServerInstance,TabletServerStatus> current,
      Map<KeyExtent,TServerInstance> unassigned, Map<KeyExtent,TServerInstance> assignments); @Override long balance(SortedMap<TServerInstance,TabletServerStatus> current,
      Set<KeyExtent> migrations, List<TabletMigration> migrationsOut); static final String HOST_BALANCER_PREFIX; static final String HOST_BALANCER_OOB_CHECK_KEY; static final String HOST_BALANCER_REGEX_USING_IPS_KEY; static final String HOST_BALANCER_REGEX_MAX_MIGRATIONS_KEY; static final String HOST_BALANCER_OUTSTANDING_MIGRATIONS_KEY; }