Java Code Examples for org.apache.helix.HelixDataAccessor#getBaseDataAccessor()

The following examples show how to use org.apache.helix.HelixDataAccessor#getBaseDataAccessor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZKPathDataDumpTask.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  // For each record in status update and error node
  // TODO: for now the status updates are dumped to cluster manager log4j log.
  // We need to think if we should create per-instance log files that contains
  // per-instance statusUpdates
  // and errors
  LOG.info("Scan statusUpdates and errors for cluster: " + _manager.getClusterName()
      + ", by controller: " + _manager);
  HelixDataAccessor accessor = _manager.getHelixDataAccessor();
  Builder keyBuilder = accessor.keyBuilder();
  BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();

  List<String> instances = accessor.getChildNames(keyBuilder.instanceConfigs());
  for (String instance : instances) {
    // dump participant status updates
    String statusUpdatePath = PropertyPathBuilder.instanceStatusUpdate(_manager.getClusterName(), instance);
    dump(baseAccessor, statusUpdatePath, _thresholdNoChangeMsForStatusUpdates, _maxLeafCount);

    // dump participant errors
    String errorPath = PropertyPathBuilder.instanceError(_manager.getClusterName(), instance);
    dump(baseAccessor, errorPath, _thresholdNoChangeMsForErrors, _maxLeafCount);
  }
  // dump controller status updates
  String controllerStatusUpdatePath = PropertyPathBuilder.controllerStatusUpdate(_manager.getClusterName());
  dump(baseAccessor, controllerStatusUpdatePath, _thresholdNoChangeMsForStatusUpdates, _maxLeafCount);

  // dump controller errors
  String controllerErrorPath = PropertyPathBuilder.controllerError(_manager.getClusterName());
  dump(baseAccessor, controllerErrorPath, _thresholdNoChangeMsForErrors, _maxLeafCount);
}
 
Example 2
Source File: HelixTask.java    From helix with Apache License 2.0 5 votes vote down vote up
private HelixDataAccessor getSrcClusterDataAccessor(final Message message) {
  HelixDataAccessor helixDataAccessor = _manager.getHelixDataAccessor();
  String clusterName = message.getSrcClusterName();
  if (clusterName != null && !clusterName.equals(_manager.getClusterName())) {
    // for cross cluster message, create different HelixDataAccessor for replying message.
    /*
      TODO On frequent cross clsuter messaging request, keeping construct data accessor may cause
      performance issue. We should consider adding cache in this class or HelixManager. --JJ
     */
    helixDataAccessor = new ZKHelixDataAccessor(clusterName, helixDataAccessor.getBaseDataAccessor());
  }
  return helixDataAccessor;
}
 
Example 3
Source File: DefaultMessagingService.java    From helix with Apache License 2.0 5 votes vote down vote up
private HelixDataAccessor getRecipientDataAccessor(final Criteria recipientCriteria) {
  HelixDataAccessor dataAccessor = _manager.getHelixDataAccessor();
  String clusterName = recipientCriteria.getClusterName();
  if (clusterName != null && !clusterName.equals(_manager.getClusterName())) {
    // for cross cluster message, create new DataAccessor for sending message.
    /*
      TODO On frequent cross clsuter messaging request, keeping construct data accessor may cause
      performance issue. We should consider adding cache in this service or HelixManager. --JJ
     */
    dataAccessor = new ZKHelixDataAccessor(clusterName, dataAccessor.getBaseDataAccessor());
  }
  return dataAccessor;
}
 
Example 4
Source File: RoutingManager.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public void init(HelixManager helixManager) {
  HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor();
  _zkDataAccessor = helixDataAccessor.getBaseDataAccessor();
  _externalViewPathPrefix = helixDataAccessor.keyBuilder().externalViews().getPath() + "/";
  _idealStatePathPrefix = helixDataAccessor.keyBuilder().idealStates().getPath() + "/";
  _instanceConfigsPath = helixDataAccessor.keyBuilder().instanceConfigs().getPath();
  _propertyStore = helixManager.getHelixPropertyStore();
}
 
Example 5
Source File: TestZKPathDataDumpTask.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  int n = 1;

  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
      "localhost", // participant name prefix
      "TestDB", // resource name prefix
      1, // resources
      2, // partitions per resource
      n, // number of nodes
      1, // replicas
      "MasterSlave", true); // do rebalance

  HelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();

  HelixManager manager = mock(HelixManager.class);
  when(manager.getHelixDataAccessor()).thenReturn(accessor);
  when(manager.getClusterName()).thenReturn(clusterName);

  // run dump task without statusUpdates and errors, should not remove any existing
  // statusUpdate/error paths
  ZKPathDataDumpTask task = new ZKPathDataDumpTask(manager, 0L, 0L, Integer.MAX_VALUE);
  task.run();
  PropertyKey controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
  Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  PropertyKey controllerErrorKey = keyBuilder.controllerTaskErrors();
  Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  PropertyKey statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
  Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  PropertyKey errorKey = keyBuilder.stateTransitionErrors("localhost_12918");

  // add participant status updates and errors
  statusUpdateKey =
      keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
  accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
  errorKey =
      keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
  accessor.setProperty(errorKey, new Error(new ZNRecord("error")));

  // add controller status updates and errors
  controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB");
  accessor.setProperty(controllerStatusUpdateKey,
      new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
  controllerErrorKey = keyBuilder.controllerTaskError("TestDB_error");
  accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));

  // run dump task, should remove existing statusUpdate/error paths
  task.run();
  Assert.assertFalse(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(errorKey.getPath(), 0));

  controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
  Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  controllerErrorKey = keyBuilder.controllerTaskErrors();
  Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
  Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  errorKey = keyBuilder.stateTransitionErrors("localhost_12918");

  deleteCluster(clusterName);
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
 
Example 6
Source File: TestZKPathDataDumpTask.java    From helix with Apache License 2.0 4 votes vote down vote up
@Test
public void testCapacityReached() throws Exception {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;
  int n = 1;

  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
      "localhost", // participant name prefix
      "TestDB", // resource name prefix
      1, // resources
      2, // partitions per resource
      n, // number of nodes
      1, // replicas
      "MasterSlave", true); // do rebalance

  HelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
  PropertyKey.Builder keyBuilder = accessor.keyBuilder();
  BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();

  HelixManager manager = mock(HelixManager.class);
  when(manager.getHelixDataAccessor()).thenReturn(accessor);
  when(manager.getClusterName()).thenReturn(clusterName);

  // run dump task without statusUpdates and errors, should not remove any existing
  // statusUpdate/error paths
  ZKPathDataDumpTask task = new ZKPathDataDumpTask(manager, Long.MAX_VALUE, Long.MAX_VALUE, 1);
  task.run();
  PropertyKey controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
  Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  PropertyKey controllerErrorKey = keyBuilder.controllerTaskErrors();
  Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  PropertyKey statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
  Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  PropertyKey errorKey = keyBuilder.stateTransitionErrors("localhost_12918");
  Assert.assertTrue(baseAccessor.exists(errorKey.getPath(), 0));

  // add participant status updates and errors
  statusUpdateKey =
      keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
  accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
  errorKey =
      keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
  accessor.setProperty(errorKey, new Error(new ZNRecord("error")));

  // add controller status updates and errors (one of each, should not trigger anything)
  controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB");
  accessor.setProperty(controllerStatusUpdateKey,
      new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
  controllerErrorKey = keyBuilder.controllerTaskError("TestDB_error");
  accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));

  // run dump task, should not remove anything because the threshold is not exceeded
  task.run();
  Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  Assert.assertTrue(baseAccessor.exists(errorKey.getPath(), 0));

  // add a second set of all status updates and errors
  statusUpdateKey =
      keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_1");
  accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
  errorKey =
      keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_1");
  accessor.setProperty(errorKey, new Error(new ZNRecord("error")));
  controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB1");
  accessor.setProperty(controllerStatusUpdateKey,
      new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
  controllerErrorKey = keyBuilder.controllerTaskError("TestDB1_error");
  accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));

  // run dump task, should remove everything since capacities are exceeded
  task.run();
  Assert.assertFalse(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(controllerErrorKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(statusUpdateKey.getPath(), 0));
  Assert.assertFalse(baseAccessor.exists(errorKey.getPath(), 0));
  deleteCluster(clusterName);
}