@Test public void testIncreaseInServers() throws IOException, KeeperException, InterruptedException { MasterBasedDistributedLayoutFactory factory = new MasterBasedDistributedLayoutFactory(_zooKeeper, cluster); List<String> shardList = Lists.newArrayList("shard-0", "shard-1", "shard-2", "shard-3", "shard-4", "shard-5"); List<String> shardServerList = Lists.newArrayList("server-0", "server-1", "server-2", "server-3"); String table = "t1"; DistributedLayout layout1 = factory.createDistributedLayout(table, shardList, shardServerList); Map<String, String> expected1 = map(e("shard-0", "server-0"), e("shard-1", "server-1"), e("shard-2", "server-2"), e("shard-3", "server-3"), e("shard-4", "server-0"), e("shard-5", "server-1")); Map<String, String> actual1 = new TreeMap<String, String>(layout1.getLayout()); assertEquals(expected1, actual1); List<String> newShardServerList = Lists.newArrayList("server-0", "server-1", "server-2", "server-3", "server-4", "server-5"); DistributedLayout layout2 = factory.createDistributedLayout(table, shardList, newShardServerList); Map<String, String> expected2 = map(e("shard-0", "server-4"), e("shard-1", "server-5"), e("shard-2", "server-2"), e("shard-3", "server-3"), e("shard-4", "server-0"), e("shard-5", "server-1")); Map<String, String> actual2 = new TreeMap<String, String>(layout2.getLayout()); assertEquals(expected2, actual2); }
@Override public DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList) { LOG.info("Creating layout for table [{0}]", table); MasterBasedDistributedLayout layout = _cachedLayoutMap.get(table); if (layout == null || layout.isOutOfDate(shardList, onlineShardServerList)) { LOG.info("Layout out of date, recalculating for table [{0}].", table); MasterBasedDistributedLayout newLayout = newLayout(table, shardList, onlineShardServerList); _cachedLayoutMap.put(table, newLayout); return newLayout; } else { LOG.info("Layout for table [{0}] is up to date.", table); return layout; } }
MasterBasedDistributedLayoutFactory implements DistributedLayoutFactory { @Override public DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList) { LOG.info("Creating layout for table [{0}]", table); MasterBasedDistributedLayout layout = _cachedLayoutMap.get(table); if (layout == null || layout.isOutOfDate(shardList, onlineShardServerList)) { LOG.info("Layout out of date, recalculating for table [{0}].", table); MasterBasedDistributedLayout newLayout = newLayout(table, shardList, onlineShardServerList); _cachedLayoutMap.put(table, newLayout); return newLayout; } else { LOG.info("Layout for table [{0}] is up to date.", table); return layout; } } }
MasterBasedDistributedLayoutFactory implements DistributedLayoutFactory { @Override public DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList) { LOG.info("Creating layout for table [{0}]", table); MasterBasedDistributedLayout layout = _cachedLayoutMap.get(table); if (layout == null || layout.isOutOfDate(shardList, onlineShardServerList)) { LOG.info("Layout out of date, recalculating for table [{0}].", table); MasterBasedDistributedLayout newLayout = newLayout(table, shardList, onlineShardServerList); _cachedLayoutMap.put(table, newLayout); return newLayout; } else { LOG.info("Layout for table [{0}] is up to date.", table); return layout; } } MasterBasedDistributedLayoutFactory(ZooKeeper zooKeeper, String cluster); }
MasterBasedDistributedLayoutFactory implements DistributedLayoutFactory { @Override public DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList) { LOG.info("Creating layout for table [{0}]", table); MasterBasedDistributedLayout layout = _cachedLayoutMap.get(table); if (layout == null || layout.isOutOfDate(shardList, onlineShardServerList)) { LOG.info("Layout out of date, recalculating for table [{0}].", table); MasterBasedDistributedLayout newLayout = newLayout(table, shardList, onlineShardServerList); _cachedLayoutMap.put(table, newLayout); return newLayout; } else { LOG.info("Layout for table [{0}] is up to date.", table); return layout; } } MasterBasedDistributedLayoutFactory(ZooKeeper zooKeeper, String cluster); @Override DistributedLayout readCurrentLayout(String table); @Override DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList); @Override Map<String, ?> getLayoutCache(); }
MasterBasedDistributedLayoutFactory implements DistributedLayoutFactory { @Override public DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList) { LOG.info("Creating layout for table [{0}]", table); MasterBasedDistributedLayout layout = _cachedLayoutMap.get(table); if (layout == null || layout.isOutOfDate(shardList, onlineShardServerList)) { LOG.info("Layout out of date, recalculating for table [{0}].", table); MasterBasedDistributedLayout newLayout = newLayout(table, shardList, onlineShardServerList); _cachedLayoutMap.put(table, newLayout); return newLayout; } else { LOG.info("Layout for table [{0}] is up to date.", table); return layout; } } MasterBasedDistributedLayoutFactory(ZooKeeper zooKeeper, String cluster); @Override DistributedLayout readCurrentLayout(String table); @Override DistributedLayout createDistributedLayout(String table, List<String> shardList, List<String> onlineShardServerList); @Override Map<String, ?> getLayoutCache();  }