Search in sources :

Example 1 with Verifier

use of org.apache.helix.tools.ClusterStateVerifier.Verifier in project pinot by linkedin.

the class PerfBenchmarkDriver method waitForExternalViewUpdate.

public static void waitForExternalViewUpdate(String zkAddress, final String clusterName, long timeoutInMilliseconds) {
    final ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkAddress);
    Verifier customVerifier = new Verifier() {

        @Override
        public boolean verify() {
            List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);
            LOGGER.info("Waiting for the cluster to be set up and indexes to be loaded on the servers" + new Timestamp(System.currentTimeMillis()));
            for (String resourceName : resourcesInCluster) {
                IdealState idealState = helixAdmin.getResourceIdealState(clusterName, resourceName);
                ExternalView externalView = helixAdmin.getResourceExternalView(clusterName, resourceName);
                if (idealState == null || externalView == null) {
                    return false;
                }
                Set<String> partitionSet = idealState.getPartitionSet();
                for (String partition : partitionSet) {
                    Map<String, String> instanceStateMapIS = idealState.getInstanceStateMap(partition);
                    Map<String, String> instanceStateMapEV = externalView.getStateMap(partition);
                    if (instanceStateMapIS == null || instanceStateMapEV == null) {
                        return false;
                    }
                    if (!instanceStateMapIS.equals(instanceStateMapEV)) {
                        return false;
                    }
                }
            }
            LOGGER.info("Cluster is ready to serve queries");
            return true;
        }
    };
    ClusterStateVerifier.verifyByPolling(customVerifier, timeoutInMilliseconds);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Verifier(org.apache.helix.tools.ClusterStateVerifier.Verifier) Timestamp(java.sql.Timestamp) IdealState(org.apache.helix.model.IdealState)

Aggregations

Timestamp (java.sql.Timestamp)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ExternalView (org.apache.helix.model.ExternalView)1 IdealState (org.apache.helix.model.IdealState)1 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)1 Verifier (org.apache.helix.tools.ClusterStateVerifier.Verifier)1