Search in sources :

Example 41 with ExternalView

use of org.apache.helix.model.ExternalView in project pinot by linkedin.

the class SegmentStatusCheckerTest method missingEVPartitionPushTest.

@Test
public void missingEVPartitionPushTest() throws Exception {
    final String tableName = "myTable_OFFLINE";
    List<String> allTableNames = new ArrayList<String>();
    allTableNames.add(tableName);
    IdealState idealState = new IdealState(tableName);
    idealState.setPartitionState("myTable_0", "pinot1", "ONLINE");
    idealState.setPartitionState("myTable_1", "pinot1", "ONLINE");
    idealState.setPartitionState("myTable_1", "pinot2", "ONLINE");
    idealState.setReplicas("2");
    idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
    ExternalView externalView = new ExternalView(tableName);
    externalView.setState("myTable_1", "pinot1", "ONLINE");
    externalView.setState("myTable_1", "pinot2", "ONLINE");
    HelixAdmin helixAdmin;
    {
        helixAdmin = mock(HelixAdmin.class);
        when(helixAdmin.getResourceIdealState("StatusChecker", "myTable_OFFLINE")).thenReturn(idealState);
        when(helixAdmin.getResourceExternalView("StatusChecker", "myTable_OFFLINE")).thenReturn(externalView);
    }
    ZNRecord znrecord = new ZNRecord("myTable_0");
    znrecord.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, "myTable_0");
    znrecord.setSimpleField(CommonConstants.Segment.TABLE_NAME, "myTable_OFFLINE");
    znrecord.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
    znrecord.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.OFFLINE);
    znrecord.setLongField(CommonConstants.Segment.START_TIME, 1000);
    znrecord.setLongField(CommonConstants.Segment.END_TIME, 2000);
    znrecord.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
    znrecord.setLongField(CommonConstants.Segment.TOTAL_DOCS, 10000);
    znrecord.setLongField(CommonConstants.Segment.CRC, 1234);
    znrecord.setLongField(CommonConstants.Segment.CREATION_TIME, 3000);
    znrecord.setSimpleField(CommonConstants.Segment.Offline.DOWNLOAD_URL, "http://localhost:8000/myTable_0");
    znrecord.setLongField(CommonConstants.Segment.Offline.PUSH_TIME, System.currentTimeMillis());
    znrecord.setLongField(CommonConstants.Segment.Offline.REFRESH_TIME, System.currentTimeMillis());
    ZkHelixPropertyStore<ZNRecord> propertyStore;
    {
        propertyStore = (ZkHelixPropertyStore<ZNRecord>) mock(ZkHelixPropertyStore.class);
        when(propertyStore.get("/SEGMENTS/myTable_OFFLINE/myTable_0", null, AccessOption.PERSISTENT)).thenReturn(znrecord);
    }
    {
        helixResourceManager = mock(PinotHelixResourceManager.class);
        when(helixResourceManager.isLeader()).thenReturn(true);
        when(helixResourceManager.getAllPinotTableNames()).thenReturn(allTableNames);
        when(helixResourceManager.getHelixClusterName()).thenReturn("StatusChecker");
        when(helixResourceManager.getHelixAdmin()).thenReturn(helixAdmin);
        when(helixResourceManager.getPropertyStore()).thenReturn(propertyStore);
    }
    {
        config = mock(ControllerConf.class);
        when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
        when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
    }
    metricsRegistry = new MetricsRegistry();
    controllerMetrics = new ControllerMetrics(metricsRegistry);
    segmentStatusChecker = new SegmentStatusChecker(helixResourceManager, config);
    segmentStatusChecker.setMetricsRegistry(controllerMetrics);
    segmentStatusChecker.runSegmentMetrics();
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.SEGMENTS_IN_ERROR_STATE), 0);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.NUMBER_OF_REPLICAS), 2);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.PERCENT_OF_REPLICAS), 100);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.PERCENT_SEGMENTS_AVAILABLE), 100);
    segmentStatusChecker.stop();
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ZkHelixPropertyStore(org.apache.helix.store.zk.ZkHelixPropertyStore) ArrayList(java.util.ArrayList) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) ZNRecord(org.apache.helix.ZNRecord) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Example 42 with ExternalView

use of org.apache.helix.model.ExternalView in project pinot by linkedin.

the class SegmentDeletionManagerTest method makeHelixAdmin.

HelixAdmin makeHelixAdmin() {
    HelixAdmin admin = mock(HelixAdmin.class);
    ExternalView ev = mock(ExternalView.class);
    IdealState is = mock(IdealState.class);
    when(admin.getResourceExternalView(clusterName, tableName)).thenReturn(ev);
    when(admin.getResourceIdealState(clusterName, tableName)).thenReturn(is);
    List<String> segmentsInIs = segmentsInIdealStateOrExtView();
    Map<String, String> dummy = new HashMap<>(1);
    dummy.put("someHost", "ONLINE");
    for (String segment : segmentsInIs) {
        when(is.getInstanceStateMap(segment)).thenReturn(dummy);
    }
    when(ev.getStateMap(anyString())).thenReturn(null);
    return admin;
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState)

Aggregations

ExternalView (org.apache.helix.model.ExternalView)42 Test (org.testng.annotations.Test)22 IdealState (org.apache.helix.model.IdealState)15 InstanceConfig (org.apache.helix.model.InstanceConfig)14 ArrayList (java.util.ArrayList)12 ServerToSegmentSetMap (com.linkedin.pinot.routing.ServerToSegmentSetMap)7 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ZNRecord (org.apache.helix.ZNRecord)6 BeforeTest (org.testng.annotations.BeforeTest)6 LLCSegmentName (com.linkedin.pinot.common.utils.LLCSegmentName)5 HelixAdmin (org.apache.helix.HelixAdmin)5 AfterTest (org.testng.annotations.AfterTest)5 AbstractTableConfig (com.linkedin.pinot.common.config.AbstractTableConfig)4 RoutingTableBuilder (com.linkedin.pinot.routing.builder.RoutingTableBuilder)4 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)4 PropertyKey (org.apache.helix.PropertyKey)4 OfflineSegmentZKMetadata (com.linkedin.pinot.common.metadata.segment.OfflineSegmentZKMetadata)3 ControllerMetrics (com.linkedin.pinot.common.metrics.ControllerMetrics)3