Search in sources :

Example 6 with HelixManager

use of org.apache.helix.HelixManager in project pinot by linkedin.

the class BaseClusterIntegrationTest method setupSegmentCountCountDownLatch.

protected CountDownLatch setupSegmentCountCountDownLatch(final String tableName, final int expectedSegmentCount) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    HelixManager manager = HelixManagerFactory.getZKHelixManager(getHelixClusterName(), "test_instance", InstanceType.SPECTATOR, ZkStarter.DEFAULT_ZK_STR);
    manager.connect();
    manager.addExternalViewChangeListener(new ExternalViewChangeListener() {

        private boolean _hasBeenTriggered = false;

        @Override
        public void onExternalViewChange(List<ExternalView> externalViewList, NotificationContext changeContext) {
            // Nothing to do?
            if (_hasBeenTriggered) {
                return;
            }
            for (ExternalView externalView : externalViewList) {
                if (externalView.getId().contains(tableName)) {
                    Set<String> partitionSet = externalView.getPartitionSet();
                    if (partitionSet.size() == expectedSegmentCount) {
                        int onlinePartitionCount = 0;
                        for (String partitionId : partitionSet) {
                            Map<String, String> partitionStateMap = externalView.getStateMap(partitionId);
                            if (partitionStateMap.containsValue("ONLINE")) {
                                onlinePartitionCount++;
                            }
                        }
                        if (onlinePartitionCount == expectedSegmentCount) {
                            //                System.out.println("Got " + expectedSegmentCount + " online tables, unlatching the main thread");
                            latch.countDown();
                            _hasBeenTriggered = true;
                        }
                    }
                }
            }
        }
    });
    return latch;
}
Also used : ExternalView(org.apache.helix.model.ExternalView) NotificationContext(org.apache.helix.NotificationContext) HelixManager(org.apache.helix.HelixManager) ResultSet(java.sql.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) ExternalViewChangeListener(org.apache.helix.ExternalViewChangeListener) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HelixManager (org.apache.helix.HelixManager)6 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExternalViewChangeListener (org.apache.helix.ExternalViewChangeListener)2 NotificationContext (org.apache.helix.NotificationContext)2 ExternalView (org.apache.helix.model.ExternalView)2 StateMachineEngine (org.apache.helix.participant.StateMachineEngine)2 File (java.io.File)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 HelixConfigScope (org.apache.helix.model.HelixConfigScope)1 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)1 BeforeClass (org.testng.annotations.BeforeClass)1