Ejemplo n.º 1
0
  private HostPort fetcheLeaderInfoFromZk() {
    try {
      Participant leader = m_leaderLatch.getLeader();
      return JSON.parseObject(leader.getId(), HostPort.class);
    } catch (Exception e) {
      log.error("Failed to fetch leader info from zk.", e);
    }

    return null;
  }
Ejemplo n.º 2
0
  public String getCurrentLeader() {
    try {
      final LeaderLatch latch = leaderLatch.get();

      if (latch == null) {
        return null;
      }

      Participant participant = latch.getLeader();
      if (participant.isLeader()) {
        return participant.getId();
      }

      return null;
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
Ejemplo n.º 3
0
    @Override
    public void run() {
      try {
        synchronized (lock) {
          final LeaderLatch latch = leaderLatch.get();
          if (latch == null || !latch.hasLeadership()) {
            log.info(
                "LEGGO MY EGGO. [%s] is leader.", latch == null ? null : latch.getLeader().getId());
            stopBeingLeader();
            return;
          }
        }

        List<Boolean> allStarted =
            Arrays.asList(databaseSegmentManager.isStarted(), serverInventoryView.isStarted());
        for (Boolean aBoolean : allStarted) {
          if (!aBoolean) {
            log.error("InventoryManagers not started[%s]", allStarted);
            stopBeingLeader();
            return;
          }
        }

        // Do coordinator stuff.
        DruidCoordinatorRuntimeParams params =
            DruidCoordinatorRuntimeParams.newBuilder()
                .withStartTime(startTime)
                .withDatasources(databaseSegmentManager.getInventory())
                .withDynamicConfigs(dynamicConfigs.get())
                .withEmitter(emitter)
                .build();

        for (DruidCoordinatorHelper helper : helpers) {
          params = helper.run(params);
        }
      } catch (Exception e) {
        log.makeAlert(e, "Caught exception, ignoring so that schedule keeps going.").emit();
      }
    }