Search in sources :

Example 1 with Criteria

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

the class PinotHelixResourceManager method sendSegmentRefreshMessage.

/**
   * 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.
   *
   * @param segmentZKMetadata is the metadata of the newly arrived segment.
   * @return true if message has been sent to at least one instance of the server hosting the segment.
   */
private void sendSegmentRefreshMessage(OfflineSegmentZKMetadata segmentZKMetadata) {
    final String segmentName = segmentZKMetadata.getSegmentName();
    final String rawTableName = segmentZKMetadata.getTableName();
    final String tableName = TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(rawTableName);
    // Infinite timeout on the recipient.
    final int timeoutMs = -1;
    SegmentRefreshMessage refreshMessage = new SegmentRefreshMessage(tableName, segmentName, segmentZKMetadata.getCrc());
    Criteria recipientCriteria = new Criteria();
    recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
    recipientCriteria.setInstanceName("%");
    recipientCriteria.setResource(tableName);
    recipientCriteria.setPartition(segmentName);
    recipientCriteria.setSessionSpecific(true);
    ClusterMessagingService messagingService = _helixZkManager.getMessagingService();
    LOGGER.info("Sending refresh message for segment {} of table {}:{} to recipients {}", segmentName, rawTableName, refreshMessage, recipientCriteria);
    // Helix sets the timeoutMs argument specified in 'send' call as the processing timeout of the message.
    int nMsgsSent = messagingService.send(recipientCriteria, refreshMessage, null, timeoutMs);
    if (nMsgsSent > 0) {
        // TODO Would be nice if we can get the name of the instances to which messages were sent.
        LOGGER.info("Sent {} msgs to refresh segment {} of table {}", nMsgsSent, segmentName, rawTableName);
    } 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("Unable to send segment refresh message for {} of table {}, nMsgs={}", segmentName, tableName, nMsgsSent);
    }
}
Also used : SegmentRefreshMessage(com.linkedin.pinot.common.messages.SegmentRefreshMessage) Criteria(org.apache.helix.Criteria) ClusterMessagingService(org.apache.helix.ClusterMessagingService)

Example 2 with Criteria

use of org.apache.helix.Criteria in project incubator-gobblin by apache.

the class GobblinYarnAppLauncher method sendShutdownRequest.

@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()));
    }
}
Also used : Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with Criteria

use of org.apache.helix.Criteria in project helix by apache.

the class TestDefaultMessagingService method TestMessageSend.

@Test()
public void TestMessageSend() {
    HelixManager manager = new MockHelixManager();
    DefaultMessagingService svc = new DefaultMessagingService(manager);
    TestMessageHandlerFactory factory = new TestMessageHandlerFactory();
    svc.registerMessageHandlerFactory(factory.getMessageType(), factory);
    Criteria recipientCriteria = new Criteria();
    recipientCriteria.setInstanceName("localhost_12919");
    recipientCriteria.setRecipientInstanceType(InstanceType.PARTICIPANT);
    recipientCriteria.setSelfExcluded(true);
    Message template = new Message(factory.getMessageType(), UUID.randomUUID().toString());
    AssertJUnit.assertEquals(0, svc.send(recipientCriteria, template));
    recipientCriteria.setSelfExcluded(false);
    AssertJUnit.assertEquals(1, svc.send(recipientCriteria, template));
    // all instances, all partitions
    recipientCriteria.setSelfExcluded(false);
    recipientCriteria.setInstanceName("%");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(200, svc.send(recipientCriteria, template));
    // all instances, all partitions, use * instead of %
    recipientCriteria.setSelfExcluded(false);
    recipientCriteria.setInstanceName("*");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("*");
    AssertJUnit.assertEquals(200, svc.send(recipientCriteria, template));
    // tail pattern
    recipientCriteria.setSelfExcluded(false);
    recipientCriteria.setInstanceName("localhost%");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(200, svc.send(recipientCriteria, template));
    // exclude this instance, send to all others for all partitions
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("%");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(159, svc.send(recipientCriteria, template));
    // single instance, all partitions
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("localhost_12920");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(39, svc.send(recipientCriteria, template));
    // single character wildcards
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("l_calhost_12_20");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(39, svc.send(recipientCriteria, template));
    // head pattern
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("%12920");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(39, svc.send(recipientCriteria, template));
    // middle pattern
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("l%_12920");
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(39, svc.send(recipientCriteria, template));
    // send to a controller
    recipientCriteria.setSelfExcluded(true);
    recipientCriteria.setInstanceName("localhost_12920");
    recipientCriteria.setRecipientInstanceType(InstanceType.CONTROLLER);
    recipientCriteria.setResource("DB");
    recipientCriteria.setPartition("%");
    AssertJUnit.assertEquals(1, svc.send(recipientCriteria, template));
}
Also used : HelixManager(org.apache.helix.HelixManager) Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) Test(org.testng.annotations.Test)

Example 4 with Criteria

use of org.apache.helix.Criteria in project helix by apache.

the class HelixTaskExecutor method syncSessionToController.

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();
        }
    }
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) Message(org.apache.helix.model.Message) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder) Criteria(org.apache.helix.Criteria) PropertyKey(org.apache.helix.PropertyKey)

Example 5 with Criteria

use of org.apache.helix.Criteria in project helix by apache.

the class TestMessagingService method TestMessageSimpleSendReceiveAsync.

@Test()
public void TestMessageSimpleSendReceiveAsync() throws Exception {
    String hostSrc = "localhost_" + START_PORT;
    String hostDest = "localhost_" + (START_PORT + 1);
    TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
    _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageTypes(), factory);
    _participants[0].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);
    TestAsyncCallback callback = new TestAsyncCallback(60000);
    _participants[0].getMessagingService().send(cr, msg, callback, 60000);
    Thread.sleep(2000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(TestAsyncCallback._replyedMessageContents.contains("TestReplyMessage"));
    AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
    TestAsyncCallback callback2 = new TestAsyncCallback(500);
    _participants[0].getMessagingService().send(cr, msg, callback2, 500);
    Thread.sleep(3000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(callback2.isTimedOut());
    cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setDataSource(DataSource.IDEALSTATES);
    callback = new TestAsyncCallback(60000);
    _participants[0].getMessagingService().send(cr, msg, callback, 60000);
    Thread.sleep(2000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(TestAsyncCallback._replyedMessageContents.contains("TestReplyMessage"));
    AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
    callback2 = new TestAsyncCallback(500);
    _participants[0].getMessagingService().send(cr, msg, callback2, 500);
    Thread.sleep(3000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(callback2.isTimedOut());
}
Also used : Message(org.apache.helix.model.Message) Criteria(org.apache.helix.Criteria) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

Criteria (org.apache.helix.Criteria)22 Message (org.apache.helix.model.Message)21 Test (org.testng.annotations.Test)15 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 HelixManager (org.apache.helix.HelixManager)8 PropertyKey (org.apache.helix.PropertyKey)8 StringWriter (java.io.StringWriter)7 ZNRecord (org.apache.helix.ZNRecord)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)7 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)7 UUID (java.util.UUID)6 Builder (org.apache.helix.PropertyKey.Builder)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)4 AsyncCallback (org.apache.helix.messaging.AsyncCallback)4 TreeMap (java.util.TreeMap)2 ConstraintItem (org.apache.helix.model.ConstraintItem)2 SegmentRefreshMessage (com.linkedin.pinot.common.messages.SegmentRefreshMessage)1 ArrayList (java.util.ArrayList)1 GobblinHelixMessagingService (org.apache.gobblin.cluster.GobblinHelixMessagingService)1