public int reloadAllSegments(@Nonnull 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; }
public int reloadSegment(@Nonnull String tableNameWithType, @Nonnull 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; }
@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.CONTROLLER); criteria.setSessionSpecific(true); Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); shutdownRequest.setTgtSessionId("*"); int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
criteria.setSessionSpecific(true);
@VisibleForTesting void sendShutdownRequest() { final Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.CONTROLLER); criteria.setSessionSpecific(true); final Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); shutdownRequest.setTgtSessionId("*"); // Wait for 5 minutes final int timeout = 300000; // Send shutdown request to Cluster master, which will send shutdown request to workers // Upon receiving shutdown response from workers, master will shut itself down and call back shutdownASG() final int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest, shutdownASG(),timeout); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.PARTICIPANT); // #HELIX-0.6.7-WORKAROUND // Add this back when messaging to instances is ported to 0.6 branch //criteria.setDataSource(Criteria.DataSource.LIVEINSTANCES); criteria.setSessionSpecific(true); Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); // Wait for 5 minutes final int timeout = 300000; // #HELIX-0.6.7-WORKAROUND // Temporarily bypass the default messaging service to allow upgrade to 0.6.7 which is missing support // for messaging to instances //int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest, // new NoopReplyHandler(), timeout); GobblinHelixMessagingService messagingService = new GobblinHelixMessagingService(this.multiManager.getJobClusterHelixManager()); int messagesSent = messagingService.send(criteria, shutdownRequest, new NoopReplyHandler(), timeout); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the participants", shutdownRequest.getMsgSubType())); } }
recipientCriteria.setSessionSpecific(true); recipientCriteria.setResource(CommonConstants.Helix.BROKER_RESOURCE_INSTANCE); recipientCriteria.setDataSource(Criteria.DataSource.EXTERNALVIEW);
recipientCriteria.setResource(offlineTableName); recipientCriteria.setPartition(segmentName); recipientCriteria.setSessionSpecific(true);
@VisibleForTesting public static void sendUserDefinedMessage(String messageSubType, String messageVal, String messageId, InstanceType instanceType, HelixManager helixManager, Logger logger) { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(instanceType); criteria.setSessionSpecific(true); Message message = new Message(Message.MessageType.USER_DEFINE_MSG.toString(), messageId); message.setMsgSubType(messageSubType); message.setAttribute(Message.Attributes.INNER_MESSAGE, messageVal); message.setMsgState(Message.MessageState.NEW); message.setTgtSessionId("*"); int messagesSent = helixManager.getMessagingService().send(criteria, message); if (messagesSent == 0) { logger.error(String.format("Failed to send the %s message to the participants", message)); } } }
@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.CONTROLLER); criteria.setSessionSpecific(true); Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); shutdownRequest.setTgtSessionId("*"); int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
@VisibleForTesting void sendShutdownRequest() { final Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.CONTROLLER); criteria.setSessionSpecific(true); final Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); shutdownRequest.setTgtSessionId("*"); // Wait for 5 minutes final int timeout = 300000; // Send shutdown request to Cluster master, which will send shutdown request to workers // Upon receiving shutdown response from workers, master will shut itself down and call back shutdownASG() final int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest, shutdownASG(),timeout); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
@VisibleForTesting void sendShutdownRequest() { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.PARTICIPANT); // #HELIX-0.6.7-WORKAROUND // Add this back when messaging to instances is ported to 0.6 branch //criteria.setDataSource(Criteria.DataSource.LIVEINSTANCES); criteria.setSessionSpecific(true); Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.WORK_UNIT_RUNNER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); // Wait for 5 minutes final int timeout = 300000; // #HELIX-0.6.7-WORKAROUND // Temporarily bypass the default messaging service to allow upgrade to 0.6.7 which is missing support // for messaging to instances //int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest, // new NoopReplyHandler(), timeout); GobblinHelixMessagingService messagingService = new GobblinHelixMessagingService(this.helixManager); int messagesSent = messagingService.send(criteria, shutdownRequest, new NoopReplyHandler(), timeout); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the participants", shutdownRequest.getMsgSubType())); } }
@VisibleForTesting void sendShutdownRequest() { final Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(InstanceType.CONTROLLER); criteria.setSessionSpecific(true); final Message shutdownRequest = new Message(GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString().toLowerCase() + UUID.randomUUID().toString()); shutdownRequest.setMsgSubType(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); shutdownRequest.setMsgState(Message.MessageState.NEW); shutdownRequest.setTgtSessionId("*"); // Wait for 5 minutes final int timeout = 300000; // Send shutdown request to Cluster master, which will send shutdown request to workers // Upon receiving shutdown response from workers, master will shut itself down and call back shutdownASG() final int messagesSent = this.helixManager.getMessagingService().send(criteria, shutdownRequest, shutdownASG(),timeout); if (messagesSent == 0) { LOGGER.error(String.format("Failed to send the %s message to the controller", shutdownRequest.getMsgSubType())); } }
private void syncSessionToController(HelixManager manager) { if (_lastSessionSyncTime == null || System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync HelixDataAccessor accessor = manager.getHelixDataAccessor(); PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC); if (accessor.getProperty(key) == null) { LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName())); Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC); msg.setSrcName(manager.getInstanceName()); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); msg.setMsgId(SESSION_SYNC); Criteria cr = new Criteria(); cr.setRecipientInstanceType(InstanceType.CONTROLLER); cr.setSessionSpecific(false); manager.getMessagingService().send(cr, msg); _lastSessionSyncTime = System.currentTimeMillis(); } } }
private void syncSessionToController(HelixManager manager) { if (_lastSessionSyncTime == null || System.currentTimeMillis() - _lastSessionSyncTime > SESSION_SYNC_INTERVAL) { // > delay since last sync HelixDataAccessor accessor = manager.getHelixDataAccessor(); PropertyKey key = new Builder(manager.getClusterName()).controllerMessage(SESSION_SYNC); if (accessor.getProperty(key) == null) { LOG.info(String.format("Participant %s syncs session with controller", manager.getInstanceName())); Message msg = new Message(MessageType.PARTICIPANT_SESSION_CHANGE, SESSION_SYNC); msg.setSrcName(manager.getInstanceName()); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); msg.setMsgId(SESSION_SYNC); Criteria cr = new Criteria(); cr.setRecipientInstanceType(InstanceType.CONTROLLER); cr.setSessionSpecific(false); manager.getMessagingService().send(cr, msg); _lastSessionSyncTime = System.currentTimeMillis(); } } }
@VisibleForTesting public static void sendUserDefinedMessage(String messageSubType, String messageVal, String messageId, InstanceType instanceType, HelixManager helixManager, Logger logger) { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(instanceType); criteria.setSessionSpecific(true); Message message = new Message(Message.MessageType.USER_DEFINE_MSG.toString(), messageId); message.setMsgSubType(messageSubType); message.setAttribute(Message.Attributes.INNER_MESSAGE, messageVal); message.setMsgState(Message.MessageState.NEW); message.setTgtSessionId("*"); int messagesSent = helixManager.getMessagingService().send(criteria, message); if (messagesSent == 0) { logger.error(String.format("Failed to send the %s message to the participants", message)); } } }
@VisibleForTesting public static void sendUserDefinedMessage(String messageSubType, String messageVal, String messageId, InstanceType instanceType, HelixManager helixManager, Logger logger) { Criteria criteria = new Criteria(); criteria.setInstanceName("%"); criteria.setResource("%"); criteria.setPartition("%"); criteria.setPartitionState("%"); criteria.setRecipientInstanceType(instanceType); criteria.setSessionSpecific(true); Message message = new Message(Message.MessageType.USER_DEFINE_MSG.toString(), messageId); message.setMsgSubType(messageSubType); message.setAttribute(Message.Attributes.INNER_MESSAGE, messageVal); message.setMsgState(Message.MessageState.NEW); message.setTgtSessionId("*"); int messagesSent = helixManager.getMessagingService().send(criteria, message); if (messagesSent == 0) { logger.error(String.format("Failed to send the %s message to the participants", message)); } } }
@Test() public void sendSelfMsg() { String hostSrc = "localhost_" + START_PORT; for (int i = 0; i < NODE_NR; i++) { TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory(); String hostDest = "localhost_" + (START_PORT + i); _participants[i].getMessagingService().registerMessageHandlerFactory( factory.getMessageTypes(), factory); } String msgId = new UUID(123, 456).toString(); Message msg = new Message(new TestMessagingHandlerFactory().getMessageTypes().get(0), msgId); msg.setMsgId(msgId); msg.setSrcName(hostSrc); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); String para = "Testing messaging para"; msg.getRecord().setSimpleField("TestMessagingPara", para); Criteria cr = new Criteria(); cr.setInstanceName("%"); cr.setRecipientInstanceType(InstanceType.PARTICIPANT); cr.setSessionSpecific(false); cr.setSelfExcluded(false); AsyncCallback callback1 = new MockAsyncCallback(); int messageSent1 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000); AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR); AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord() .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage") .equals("TestReplyMessage")); }
@Test() public void TestBlockingSendReceive() throws Exception { String hostSrc = "localhost_" + START_PORT; String hostDest = "localhost_" + (START_PORT + 1); TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory(); _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory); String msgId = new UUID(123, 456).toString(); Message msg = new Message(factory.getMessageTypes().get(0), msgId); msg.setMsgId(msgId); msg.setSrcName(hostSrc); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); String para = "Testing messaging para"; msg.getRecord().setSimpleField("TestMessagingPara", para); Criteria cr = new Criteria(); cr.setInstanceName(hostDest); cr.setRecipientInstanceType(InstanceType.PARTICIPANT); cr.setSessionSpecific(false); AsyncCallback asyncCallback = new MockAsyncCallback(); int messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000); AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord() .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage") .equals("TestReplyMessage")); AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1); AsyncCallback asyncCallback2 = new MockAsyncCallback(); messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500); AssertJUnit.assertTrue(asyncCallback2.isTimedOut()); }
@Test() public void TestBlockingSendReceive() { String hostDest = "localhost_" + (START_PORT + 1); TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory(); _participants[1].getMessagingService() .registerMessageHandlerFactory(factory.getMessageTypes(), factory); String msgId = new UUID(123, 456).toString(); Message msg = new Message(factory.getMessageTypes().get(0), msgId); msg.setMsgId(msgId); msg.setSrcName(_hostSrc); msg.setTgtSessionId("*"); msg.setMsgState(MessageState.NEW); String para = "Testing messaging para"; msg.getRecord().setSimpleField("TestMessagingPara", para); Criteria cr = new Criteria(); cr.setInstanceName(hostDest); cr.setRecipientInstanceType(InstanceType.PARTICIPANT); cr.setSessionSpecific(false); cr.setClusterName(CLUSTER_NAME); AsyncCallback asyncCallback = new MockAsyncCallback(); int messagesSent = _adminController.getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000); AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord() .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage") .equals("TestReplyMessage")); AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1); AsyncCallback asyncCallback2 = new MockAsyncCallback(); messagesSent = _adminController.getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500); AssertJUnit.assertTrue(asyncCallback2.isTimedOut()); }