Java Code Examples for org.apache.helix.model.Message#getPartitionName()
The following examples show how to use
org.apache.helix.model.Message#getPartitionName() .
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: TaskStateModel.java From helix with Apache License 2.0 | 6 votes |
@Transition(to = "STOPPED", from = "RUNNING") public String onBecomeStoppedFromRunning(Message msg, NotificationContext context) { String taskPartition = msg.getPartitionName(); if (_taskRunner == null) { throw new IllegalStateException(String.format( "Invalid state transition. There is no running task for partition %s.", taskPartition)); } _taskRunner.cancel(); TaskResult r = _taskRunner.waitTillDone(); LOG.info(String.format("Task %s completed with result %s.", msg.getPartitionName(), r)); timeout_task.cancel(false); return r.getInfo(); }
Example 2
Source File: SegmentOnlineOfflineStateModelFactory.java From incubator-pinot with Apache License 2.0 | 6 votes |
@Transition(from = "OFFLINE", to = "DROPPED") public void onBecomeDroppedFromOffline(Message message, NotificationContext context) { _logger.info("SegmentOnlineOfflineStateModel.onBecomeDroppedFromOffline() : " + message); String tableNameWithType = message.getResourceName(); String segmentName = message.getPartitionName(); // This method might modify the file on disk. Use segment lock to prevent race condition Lock segmentLock = SegmentLocks.getSegmentLock(tableNameWithType, segmentName); try { segmentLock.lock(); final File segmentDir = new File(_fetcherAndLoader.getSegmentLocalDirectory(tableNameWithType, segmentName)); if (segmentDir.exists()) { FileUtils.deleteQuietly(segmentDir); _logger.info("Deleted segment directory {}", segmentDir); } } catch (final Exception e) { _logger.error("Cannot delete the segment : " + segmentName + " from local directory!\n" + e.getMessage(), e); Utils.rethrowException(e); } finally { segmentLock.unlock(); } }
Example 3
Source File: TaskStateModel.java From helix with Apache License 2.0 | 6 votes |
@Transition(to = "TASK_ERROR", from = "RUNNING") public String onBecomeTaskErrorFromRunning(Message msg, NotificationContext context) { String taskPartition = msg.getPartitionName(); if (_taskRunner == null) { throw new IllegalStateException(String.format( "Invalid state transition. There is no running task for partition %s.", taskPartition)); } TaskResult r = _taskRunner.waitTillDone(); if (r.getStatus() != TaskResult.Status.ERROR && r.getStatus() != TaskResult.Status.FAILED) { throw new IllegalStateException(String.format( "Partition %s received a state transition to %s but the result status code is %s.", msg.getPartitionName(), msg.getToState(), r.getStatus())); } timeout_task.cancel(false); return r.getInfo(); }
Example 4
Source File: TaskStateModel.java From helix with Apache License 2.0 | 6 votes |
@Transition(to = "DROPPED", from = "RUNNING") public void onBecomeDroppedFromRunning(Message msg, NotificationContext context) { String taskPartition = msg.getPartitionName(); if (_taskRunner == null) { if (timeout_task != null) { timeout_task.cancel(true); } LOG.error( "Participant {}'s thread for task partition {} not found while attempting to cancel the task; Manual cleanup may be required.", _manager.getInstanceName(), taskPartition); return; } _taskRunner.cancel(); TaskResult r = _taskRunner.waitTillDone(); LOG.info(String.format("Task partition %s returned result %s.", msg.getPartitionName(), r)); _taskRunner = null; timeout_task.cancel(false); }
Example 5
Source File: BrokerResourceOnlineOfflineStateModelFactory.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Transition(from = "ONLINE", to = "OFFLINE") public void onBecomeOfflineFromOnline(Message message, NotificationContext context) { String tableNameWithType = message.getPartitionName(); LOGGER.info("Processing transition from ONLINE to OFFLINE for table: {}", tableNameWithType); try { _routingManager.removeRouting(tableNameWithType); _queryQuotaManager.dropTableQueryQuota(tableNameWithType); } catch (Exception e) { LOGGER.error("Caught exception while processing transition from ONLINE to OFFLINE for table: {}", tableNameWithType, e); throw e; } }
Example 6
Source File: SegmentOnlineOfflineStateModelFactory.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Transition(from = "CONSUMING", to = "ONLINE") public void onBecomeOnlineFromConsuming(Message message, NotificationContext context) { String realtimeTableName = message.getResourceName(); String segmentNameStr = message.getPartitionName(); LLCSegmentName segmentName = new LLCSegmentName(segmentNameStr); TableDataManager tableDataManager = _instanceDataManager.getTableDataManager(realtimeTableName); Preconditions.checkNotNull(tableDataManager); SegmentDataManager acquiredSegment = tableDataManager.acquireSegment(segmentNameStr); // For this transition to be correct in helix, we should already have a segment that is consuming if (acquiredSegment == null) { throw new RuntimeException("Segment " + segmentNameStr + " + not present "); } try { if (!(acquiredSegment instanceof LLRealtimeSegmentDataManager)) { // We found a LLC segment that is not consuming right now, must be that we already swapped it with a // segment that has been built. Nothing to do for this state transition. _logger .info("Segment {} not an instance of LLRealtimeSegmentDataManager. Reporting success for the transition", acquiredSegment.getSegmentName()); return; } LLRealtimeSegmentDataManager segmentDataManager = (LLRealtimeSegmentDataManager) acquiredSegment; RealtimeSegmentZKMetadata metadata = ZKMetadataProvider .getRealtimeSegmentZKMetadata(_instanceDataManager.getPropertyStore(), segmentName.getTableName(), segmentNameStr); segmentDataManager.goOnlineFromConsuming(metadata); } catch (InterruptedException e) { _logger.warn("State transition interrupted", e); throw new RuntimeException(e); } finally { tableDataManager.releaseSegment(acquiredSegment); } }
Example 7
Source File: BrokerResourceOnlineOfflineStateModelFactory.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Transition(from = "OFFLINE", to = "ONLINE") public void onBecomeOnlineFromOffline(Message message, NotificationContext context) { String tableNameWithType = message.getPartitionName(); LOGGER.info("Processing transition from OFFLINE to ONLINE for table: {}", tableNameWithType); try { _routingManager.buildRouting(tableNameWithType); TableConfig tableConfig = ZKMetadataProvider.getTableConfig(_propertyStore, tableNameWithType); _queryQuotaManager.initTableQueryQuota(tableConfig, _helixDataAccessor.getProperty(_helixDataAccessor.keyBuilder().externalView(BROKER_RESOURCE_INSTANCE))); } catch (Exception e) { LOGGER.error("Caught exception while processing transition from OFFLINE to ONLINE for table: {}", tableNameWithType, e); throw e; } }
Example 8
Source File: StatusUpdateUtil.java From helix with Apache License 2.0 | 5 votes |
private String getRecordIdForMessage(Message message) { if (message.getMsgType().equals(MessageType.STATE_TRANSITION)) { return message.getPartitionName() + " Trans:" + message.getFromState().charAt(0) + "->" + message.getToState().charAt(0) + " " + UUID.randomUUID().toString(); } else { return message.getMsgType() + " " + UUID.randomUUID().toString(); } }
Example 9
Source File: AmbryPartitionStateModel.java From ambry with Apache License 2.0 | 5 votes |
@Transition(to = "INACTIVE", from = "STANDBY") public void onBecomeInactiveFromStandby(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); logger.info("Partition {} in resource {} is becoming INACTIVE from STANDBY", partitionName, message.getResourceName()); if (clusterMapConfig.clustermapEnableStateModelListener) { partitionStateChangeListener.onPartitionBecomeInactiveFromStandby(partitionName); } }
Example 10
Source File: ErrTransition.java From helix with Apache License 2.0 | 5 votes |
@Override public void doTransition(Message message, NotificationContext context) { String fromState = message.getFromState(); String toState = message.getToState(); String partition = message.getPartitionName(); String key = (fromState + "-" + toState).toUpperCase(); if (_errPartitions.containsKey(key) && _errPartitions.get(key).contains(partition)) { String errMsg = "IGNORABLE: test throw exception in msgId: " + message.getId() + " for " + partition + " transit from " + fromState + " to " + toState; throw new RuntimeException(errMsg); } }
Example 11
Source File: DummyProcess.java From helix with Apache License 2.0 | 5 votes |
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) { String db = message.getPartitionName(); String instanceName = context.getManager().getInstanceName(); DummyProcess.sleep(_transDelay); logger.info("DummyStateModel.onBecomeOnlineFromOffline(), instance:" + instanceName + ", db:" + db); }
Example 12
Source File: TestParticipantManager.java From helix with Apache License 2.0 | 5 votes |
@Override public void doTransition(Message message, NotificationContext context) throws InterruptedException { String instance = message.getTgtName(); String partition = message.getPartitionName(); if (instance.equals("localhost_12918") && partition.equals("TestDB0_0") && !_done.getAndSet(true)) { _startCountdown.countDown(); // this await will be interrupted since we cancel the task during handleNewSession _endCountdown.await(); } }
Example 13
Source File: DummyParticipant.java From helix with Apache License 2.0 | 4 votes |
@Transition(to = "DROPPED", from = "OFFLINE") public void onBecomeDroppedFromOffline(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); String instanceName = message.getTgtName(); System.out.println(instanceName + " becomes DROPPED from OFFLINE for " + partitionName); }
Example 14
Source File: OnlineOfflineStateModelFactory.java From ambari-metrics with Apache License 2.0 | 4 votes |
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); LOG.info("Received transition to Online from Offline for partition: " + partitionName); TimelineMetricAggregator.AGGREGATOR_TYPE type = PARTITION_AGGREGATION_TYPES.get(partitionName); taskRunner.setPartitionAggregationFunction(type); }
Example 15
Source File: DummyParticipant.java From helix with Apache License 2.0 | 4 votes |
@Transition(to = "OFFLINE", from = "SLAVE") public void onBecomeOfflineFromSlave(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); String instanceName = message.getTgtName(); System.out.println(instanceName + " becomes OFFLINE from SLAVE for " + partitionName); }
Example 16
Source File: DummyParticipant.java From helix with Apache License 2.0 | 4 votes |
@Transition(to = "SLAVE", from = "MASTER") public void onBecomeSlaveFromMaster(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); String instanceName = message.getTgtName(); System.out.println(instanceName + " becomes SLAVE from MASTER for " + partitionName); }
Example 17
Source File: DummyParticipant.java From helix with Apache License 2.0 | 4 votes |
@Transition(to = "SLAVE", from = "OFFLINE") public void onBecomeSlaveFromOffline(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); String instanceName = message.getTgtName(); System.out.println(instanceName + " becomes SLAVE from OFFLINE for " + partitionName); }
Example 18
Source File: TestMessageThrottle2.java From helix with Apache License 2.0 | 4 votes |
@Transition(to = "OFFLINE", from = "SLAVE") public void onBecomeOfflineFromSlave(Message message, NotificationContext context) { String partitionName = message.getPartitionName(); String instanceName = message.getTgtName(); LOGGER.info(instanceName + " becomes OFFLINE from SLAVE for " + partitionName); }
Example 19
Source File: InstanceMessagesCache.java From helix with Apache License 2.0 | 4 votes |
private void checkTargetHost(String targetHost, Message relayMessage, Map<String, LiveInstance> liveInstanceMap, Map<String, Map<String, Map<String, CurrentState>>> currentStateMap) { long currentTime = System.currentTimeMillis(); String resourceName = relayMessage.getResourceName(); String partitionName = relayMessage.getPartitionName(); String sessionId = relayMessage.getTgtSessionId(); if (!liveInstanceMap.containsKey(targetHost)) { LOG.info("Target host is not alive anymore, expiring relay message {} immediately.", relayMessage.getId()); relayMessage.setExpired(true); return; } String instanceSessionId = liveInstanceMap.get(targetHost).getEphemeralOwner(); // Target host's session has been changed, remove relay message if (!instanceSessionId.equals(sessionId)) { LOG.info("Instance SessionId does not match, expiring relay message {} immediately.", relayMessage.getId()); relayMessage.setExpired(true); return; } Map<String, Map<String, CurrentState>> instanceCurrentStateMap = currentStateMap.get(targetHost); if (instanceCurrentStateMap == null || !instanceCurrentStateMap.containsKey(sessionId)) { // This should happen only when a new session is being established. // We should not do anything here, once new session is established in participant side, // the relay message will be deleted from cache in controller's next pipeline. LOG.warn("CurrentStateMap null for {}, session {}, pending relay message {}", targetHost, sessionId, relayMessage.getId()); return; } Map<String, CurrentState> sessionCurrentStateMap = instanceCurrentStateMap.get(sessionId); CurrentState currentState = sessionCurrentStateMap.get(resourceName); // TODO: we should add transaction id for each state transition, we can immediately delete the relay message once we have transaction id record in each currentState. if (currentState == null) { setMessageRelayTime(relayMessage, currentTime); LOG.warn("CurrentState is null for {} on {}, set relay time {} for message {}", resourceName, targetHost, relayMessage.getRelayTime(), relayMessage.getId()); return; } // if the target partition already completed the state transition, // or the current state on the target partition has been changed, // Do not remove the message immediately to avoid race-condition, // for example, controller may decide to move master to another instance at this time, // if it does not aware of a pending relay message, it may end up with two masters. // so we only set the relay message to be expired. // TODO: we should add transaction id for each state transition, we can immediately delete the relay message once we have transaction id record in each currentState. String partitionCurrentState = currentState.getState(partitionName); String targetState = relayMessage.getToState(); String fromState = relayMessage.getFromState(); if (targetState.equals(partitionCurrentState) || !fromState.equals(partitionCurrentState)) { setMessageRelayTime(relayMessage, currentTime); LOG.debug("{}'s currentState {} on {} has changed, set relay message {} to be expired.", partitionName, partitionCurrentState, targetHost, relayMessage.getId()); } }
Example 20
Source File: InstanceMessagesCache.java From helix with Apache License 2.0 | 4 votes |
private void checkRelayHost(Message relayMessage, Map<String, LiveInstance> liveInstanceMap, Map<String, Map<String, Map<String, CurrentState>>> currentStateMap, Message hostedMessage) { long currentTime = System.currentTimeMillis(); String sessionId = hostedMessage.getTgtSessionId(); String relayInstance = hostedMessage.getTgtName(); String resourceName = hostedMessage.getResourceName(); String partitionName = hostedMessage.getPartitionName(); if (!liveInstanceMap.containsKey(relayInstance)) { // If the p2p forwarding host is no longer live, we should not remove the relay message immediately // since we do not know whether the relay message was forwarded before the instance went offline. setMessageRelayTime(relayMessage, currentTime); return; } String instanceSessionId = liveInstanceMap.get(relayInstance).getEphemeralOwner(); if (!instanceSessionId.equals(sessionId)) { LOG.info("Relay instance sessionId {} does not match sessionId {} in hosted message {}, " + "set relay message {} to be expired.", instanceSessionId, sessionId, relayMessage.getId(), hostedMessage.getMsgId()); setMessageRelayTime(relayMessage, currentTime); return; } Map<String, Map<String, CurrentState>> instanceCurrentStateMap = currentStateMap.get(relayInstance); if (instanceCurrentStateMap == null || !instanceCurrentStateMap.containsKey(sessionId)) { LOG.warn( "CurrentStateMap null for {}, session {}, set relay messages {} to be expired. Hosted message {}.", relayInstance, sessionId, relayMessage.getId(), hostedMessage.getId()); setMessageRelayTime(relayMessage, currentTime); return; } Map<String, CurrentState> sessionCurrentStateMap = instanceCurrentStateMap.get(sessionId); CurrentState currentState = sessionCurrentStateMap.get(resourceName); if (currentState == null) { LOG.info("No currentState found for {} on {}, set relay message {} to be expired.", resourceName, relayInstance, relayMessage.getId()); setMessageRelayTime(relayMessage, currentTime); return; } String partitionState = currentState.getState(partitionName); String targetState = hostedMessage.getToState(); String fromState = hostedMessage.getFromState(); // The relay host partition state has been changed after relay message was created. if (!fromState.equals(partitionState)) { // If the partition on the relay host turned to ERROR while transited from top state, // we can remove the cached relay message right away since participant won't forward the relay message anyway. if (HelixDefinedState.ERROR.name().equals(partitionState) && fromState .equals(currentState.getPreviousState(partitionName))) { LOG.info("Partition {} got to ERROR from the top state, " + "expiring relay message {} immediately. Hosted message {}.", partitionName, relayMessage.getId(), hostedMessage.getId()); relayMessage.setExpired(true); return; } // If the partition completed the transition, set the relay time to be the actual time when state transition completed. if (targetState.equals(partitionState) && fromState .equals(currentState.getPreviousState(partitionName))) { // The relay host already completed the state transition. long completeTime = currentState.getEndTime(partitionName); if (completeTime > relayMessage.getCreateTimeStamp()) { setMessageRelayTime(relayMessage, completeTime); LOG.error("Target state for partition {} matches the hosted message's target state, " + "set relay message {} to be expired.", partitionName, relayMessage.getId()); return; } } // For all other situations, set relay time to be current time. setMessageRelayTime(relayMessage, currentTime); // the state has been changed after it completed the required state transition (maybe another state-transition happened). LOG.info("Current state {} for partition {} does not match hosted message's from state, " + "set relay message {} to be expired.", partitionState, partitionName, relayMessage.getId()); } }