org.apache.helix.ClusterMessagingService Java Examples

The following examples show how to use org.apache.helix.ClusterMessagingService. 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: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public int reloadAllSegments(String tableNameWithType) {
  LOGGER.info("Sending reload message for table: {}", tableNameWithType);

  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setInstanceName("%");
  recipientCriteria.setResource(tableNameWithType);
  recipientCriteria.setSessionSpecific(true);
  SegmentReloadMessage segmentReloadMessage = new SegmentReloadMessage(tableNameWithType, null);
  ClusterMessagingService messagingService = _helixZkManager.getMessagingService();

  // Infinite timeout on the recipient
  int timeoutMs = -1;
  int numMessagesSent = messagingService.send(recipientCriteria, segmentReloadMessage, null, timeoutMs);
  if (numMessagesSent > 0) {
    LOGGER.info("Sent {} reload messages for table: {}", numMessagesSent, tableNameWithType);
  } else {
    LOGGER.warn("No reload message sent for table: {}", tableNameWithType);
  }

  return numMessagesSent;
}
 
Example #2
Source File: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public int reloadSegment(String tableNameWithType, String segmentName) {
  LOGGER.info("Sending reload message for segment: {} in table: {}", segmentName, tableNameWithType);

  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setInstanceName("%");
  recipientCriteria.setResource(tableNameWithType);
  recipientCriteria.setPartition(segmentName);
  recipientCriteria.setSessionSpecific(true);
  SegmentReloadMessage segmentReloadMessage = new SegmentReloadMessage(tableNameWithType, segmentName);
  ClusterMessagingService messagingService = _helixZkManager.getMessagingService();

  // Infinite timeout on the recipient
  int timeoutMs = -1;
  int numMessagesSent = messagingService.send(recipientCriteria, segmentReloadMessage, null, timeoutMs);
  if (numMessagesSent > 0) {
    LOGGER.info("Sent {} reload messages for segment: {} in table: {}", numMessagesSent, segmentName,
        tableNameWithType);
  } else {
    LOGGER.warn("No reload message sent for segment: {} in table: {}", segmentName, tableNameWithType);
  }
  return numMessagesSent;
}
 
Example #3
Source File: BootstrapHandler.java    From helix with Apache License 2.0 5 votes vote down vote up
@Transition(from = "OFFLINE", to = "SLAVE")
public void offlineToSlave(Message message, NotificationContext context) {
  System.out.println("BootstrapProcess.BootstrapStateModel.offlineToSlave()");
  HelixManager manager = context.getManager();
  ClusterMessagingService messagingService = manager.getMessagingService();
  Message requestBackupUriRequest =
      new Message(MessageType.USER_DEFINE_MSG, UUID.randomUUID().toString());
  requestBackupUriRequest.setMsgSubType(BootstrapProcess.REQUEST_BOOTSTRAP_URL);
  requestBackupUriRequest.setMsgState(MessageState.NEW);
  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setInstanceName("*");
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setResource(message.getResourceName());
  recipientCriteria.setPartition(message.getPartitionName());
  recipientCriteria.setSessionSpecific(true);
  // wait for 30 seconds
  int timeout = 30000;
  BootstrapReplyHandler responseHandler = new BootstrapReplyHandler();

  int sentMessageCount =
      messagingService.sendAndWait(recipientCriteria, requestBackupUriRequest, responseHandler,
          timeout);
  if (sentMessageCount == 0) {
    // could not find any other node hosting the partition
  } else if (responseHandler.getBootstrapUrl() != null) {
    System.out.println("Got bootstrap url:" + responseHandler.getBootstrapUrl());
    System.out.println("Got backup time:" + responseHandler.getBootstrapTime());
    // Got the url fetch it
  } else {
    // Either go to error state
    // throw new Exception("Cant find backup/bootstrap data");
    // Request some node to start backup process
  }
}
 
Example #4
Source File: PinotHelixResourceManager.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Attempt to send a message to refresh the new segment. We do not wait for any acknowledgements.
 * The message is sent as session-specific, so if a new zk session is created (e.g. server restarts)
 * it will not get the message.
 */
private void sendSegmentRefreshMessage(String offlineTableName, String segmentName) {
  SegmentRefreshMessage segmentRefreshMessage = new SegmentRefreshMessage(offlineTableName, segmentName);

  // Send segment refresh message to servers
  Criteria recipientCriteria = new Criteria();
  recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
  recipientCriteria.setInstanceName("%");
  recipientCriteria.setResource(offlineTableName);
  recipientCriteria.setPartition(segmentName);
  recipientCriteria.setSessionSpecific(true);
  ClusterMessagingService messagingService = _helixZkManager.getMessagingService();
  // Send message with no callback and infinite timeout on the recipient
  int numMessagesSent = messagingService.send(recipientCriteria, segmentRefreshMessage, null, -1);
  if (numMessagesSent > 0) {
    // TODO: Would be nice if we can get the name of the instances to which messages were sent
    LOGGER.info("Sent {} segment refresh messages to servers for segment: {} of table: {}", numMessagesSent,
        segmentName, offlineTableName);
  } else {
    // May be the case when none of the servers are up yet. That is OK, because when they come up they will get the
    // new version of the segment.
    LOGGER.warn("No segment refresh message sent to servers for segment: {} of table: {}", segmentName,
        offlineTableName);
  }

  // Send segment refresh message to brokers
  recipientCriteria.setResource(Helix.BROKER_RESOURCE_INSTANCE);
  recipientCriteria.setPartition(offlineTableName);
  numMessagesSent = messagingService.send(recipientCriteria, segmentRefreshMessage, null, -1);
  if (numMessagesSent > 0) {
    // TODO: Would be nice if we can get the name of the instances to which messages were sent
    LOGGER.info("Sent {} segment refresh messages to brokers for segment: {} of table: {}", numMessagesSent,
        segmentName, offlineTableName);
  } else {
    LOGGER.warn("No segment refresh message sent to brokers for segment: {} of table: {}", segmentName,
        offlineTableName);
  }
}
 
Example #5
Source File: ZKHelixManager.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  // The caller can register message handler factories on messaging service before the
  // helix manager is connected. Thus we do not do connected check here.
  return _messagingService;
}
 
Example #6
Source File: TestP2PNoDuplicatedMessage.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  // The caller can register message handler factories on messaging service before the
  // helix manager is connected. Thus we do not do connected check here.
  return _messagingService;
}
 
Example #7
Source File: MockManager.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  // TODO Auto-generated method stub
  return _msgSvc;
}
 
Example #8
Source File: DummyClusterManager.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  // TODO Auto-generated method stub
  return null;
}
 
Example #9
Source File: MockZKHelixManager.java    From helix with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  return new DefaultMessagingService(this);
}
 
Example #10
Source File: MockHelixManager.java    From ambry with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  throw new IllegalStateException("Not implemented");
}
 
Example #11
Source File: MockHelixManagerFactory.java    From ambry with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterMessagingService getMessagingService() {
  throw new IllegalStateException("Not implemented");
}