Esempio n. 1
0
  @Test
  public void testBaseMetaChange() throws Exception {
    startEngine();

    m_curator
        .setData()
        .forPath(ZKPathUtils.getBaseMetaVersionZkPath(), ZKSerializeUtils.serialize(100L));

    int retries = 50;
    int i = 0;
    while (m_baseMetaChangeCount.get() != 1 && i++ < retries) {
      TimeUnit.MILLISECONDS.sleep(100);
    }
    assertEquals(1, m_baseMetaChangeCount.get());

    m_curator
        .setData()
        .forPath(ZKPathUtils.getBaseMetaVersionZkPath(), ZKSerializeUtils.serialize(200L));

    i = 0;
    while (m_baseMetaChangeCount.get() != 2 && i++ < retries) {
      TimeUnit.MILLISECONDS.sleep(100);
    }
    assertEquals(2, m_baseMetaChangeCount.get());
  }
Esempio n. 2
0
 private void setMetaServers(List<Pair<String, HostPort>> servers) throws Exception {
   deleteChildren(ZKPathUtils.getMetaServersZkPath(), false);
   for (Pair<String, HostPort> pair : servers) {
     String path = ZKPaths.makePath(ZKPathUtils.getMetaServersZkPath(), pair.getKey());
     ensurePath(path);
     m_curator.setData().forPath(path, ZKSerializeUtils.serialize(pair.getValue()));
   }
 }
Esempio n. 3
0
  @Override
  protected void doSetUp() throws Exception {
    m_baseMetaChangeCount.set(0);
    defineComponent(
        EventHandler.class, "BaseMetaChangedEventHandler", TestBaseMetaChangedEventHandler.class);
    defineComponent(
        EventHandler.class,
        "MetaServerListChangedEventHandler",
        TestMetaServerListChangedEventHandler.class);

    LeaderInitEventHandler leaderInitEventHandler =
        (LeaderInitEventHandler) lookup(EventHandler.class, "LeaderInitEventHandler");
    leaderInitEventHandler.setMetaService(m_metaService);
    leaderInitEventHandler.setMetaServerAssignmentHolder(m_metaServerAssignmentHolder);
    leaderInitEventHandler.setMetaHolder(m_metaHolder);
    leaderInitEventHandler.setBrokerAssignmentHolder(m_brokerAssignmentHolder);

    when(m_metaService.getMetaEntity()).thenReturn(TestHelper.loadLocalMeta(this));

    m_curator
        .setData()
        .forPath(ZKPathUtils.getBaseMetaVersionZkPath(), ZKSerializeUtils.serialize(1L));

    leaderInitEventHandler.initialize();
    m_eventBus = lookup(EventBus.class);
  }
Esempio n. 4
0
  public Map<String, Map<String, ClientLeaseInfo>> loadAndWatchTopicExistingLeases(String topic)
      throws Exception {
    Map<String, Map<String, ClientLeaseInfo>> topicExistingLeases = new HashMap<>();

    CuratorFramework client = m_zkClient.get();
    String topicPath = ZKPaths.makePath(ZKPathUtils.getBrokerLeaseRootZkPath(), topic);

    client.getData().usingWatcher(m_brokerLeaseChangedWatcher).forPath(topicPath);
    m_brokerLeaseChangedWatcher.addWatchedPath(topicPath);
    addWatchedTopic(topic);

    List<String> partitions = client.getChildren().forPath(topicPath);

    if (partitions != null && !partitions.isEmpty()) {
      for (String partition : partitions) {
        String partitionPath = ZKPaths.makePath(topicPath, partition);
        byte[] data = client.getData().forPath(partitionPath);
        Map<String, ClientLeaseInfo> existingLeases = deserializeExistingLeases(data);
        if (existingLeases != null) {
          topicExistingLeases.put(partitionPath, existingLeases);
        }
      }
    }

    return topicExistingLeases;
  }
Esempio n. 5
0
  @Override
  protected Map<String, Map<String, ClientLeaseInfo>> loadExistingLeases() throws Exception {
    CuratorFramework client = m_zkClient.get();

    Map<String, Map<String, ClientLeaseInfo>> existingLeases = new HashMap<>();

    List<String> topics =
        client
            .getChildren() //
            .usingWatcher(m_brokerLeaseAddedWatcher) //
            .forPath(ZKPathUtils.getBrokerLeaseRootZkPath());
    m_brokerLeaseAddedWatcher.addWatchedPath(ZKPathUtils.getBrokerLeaseRootZkPath());

    if (topics != null && !topics.isEmpty()) {
      for (String topic : topics) {
        Map<String, Map<String, ClientLeaseInfo>> topicExistingLeases =
            loadAndWatchTopicExistingLeases(topic);
        existingLeases.putAll(topicExistingLeases);
      }
    }

    return existingLeases;
  }
Esempio n. 6
0
 @Override
 protected void initZkData() throws Exception {
   ensurePath("/brokers");
   ensurePath(ZKPathUtils.getMetaInfoZkPath());
   ensurePath(ZKPathUtils.getMetaServersZkPath());
   ensurePath(ZKPathUtils.getMetaServerAssignmentRootZkPath());
   ensurePath(ZKPathUtils.getBaseMetaVersionZkPath());
   ensurePath(ZKPathUtils.getBrokerLeaseRootZkPath());
   ensurePath(ZKPathUtils.getConsumerLeaseRootZkPath());
 }
Esempio n. 7
0
 private void addMetaServer(String server, String host, int port) throws Exception {
   String path = ZKPaths.makePath(ZKPathUtils.getMetaServersZkPath(), server);
   ensurePath(path);
   m_curator.setData().forPath(path, ZKSerializeUtils.serialize(new HostPort(host, port)));
 }
Esempio n. 8
0
 private void delMetaServer(String server) throws Exception {
   String path = ZKPaths.makePath(ZKPathUtils.getMetaServersZkPath(), server);
   m_curator.delete().forPath(path);
 }
Esempio n. 9
0
 @Override
 protected Pair<String, Integer> convertZkPathToKey(String path) {
   return ZKPathUtils.parseBrokerLeaseZkPath(path);
 }
Esempio n. 10
0
 @Override
 protected String[] getZkPersistTouchPaths(Pair<String, Integer> topicPartition) {
   return new String[] {ZKPathUtils.getBrokerLeaseTopicParentZkPath(topicPartition.getKey())};
 }
Esempio n. 11
0
 @Override
 protected String convertKeyToZkPath(Pair<String, Integer> topicPartition) {
   return ZKPathUtils.getBrokerLeaseZkPath(topicPartition.getKey(), topicPartition.getValue());
 }