public void processWatermark(Watermark mark) throws Exception { if (timeServiceManager != null) { timeServiceManager.advanceWatermark(mark); } output.emitWatermark(mark); }
protected <K> InternalTimeServiceManager<K> internalTimeServiceManager( AbstractKeyedStateBackend<K> keyedStatedBackend, KeyContext keyContext, //the operator Iterable<KeyGroupStatePartitionStreamProvider> rawKeyedStates) throws Exception { if (keyedStatedBackend == null) { return null; } final KeyGroupRange keyGroupRange = keyedStatedBackend.getKeyGroupRange(); final InternalTimeServiceManager<K> timeServiceManager = new InternalTimeServiceManager<>( keyGroupRange, keyContext, keyedStatedBackend, processingTimeService, keyedStatedBackend.requiresLegacySynchronousTimerSnapshots()); // and then initialize the timer services for (KeyGroupStatePartitionStreamProvider streamProvider : rawKeyedStates) { int keyGroupIdx = streamProvider.getKeyGroupId(); Preconditions.checkArgument(keyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); timeServiceManager.restoreStateForKeyGroup( streamProvider.getStream(), keyGroupIdx, environment.getUserClassLoader()); } return timeServiceManager; }
InternalTimeServiceManager<K> keyedTimeServiceHandler = (InternalTimeServiceManager<K>) timeServiceManager; TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer); return keyedTimeServiceHandler.getInternalTimerService(name, timerSerializer, triggerable);
@VisibleForTesting public int numEventTimeTimers() { return timeServiceManager == null ? 0 : timeServiceManager.numEventTimeTimers(); } }
@VisibleForTesting public int numProcessingTimeTimers() { return timeServiceManager == null ? 0 : timeServiceManager.numProcessingTimeTimers(); }
out.startNewKeyGroup(keyGroupIdx); timeServiceManager.snapshotStateForKeyGroup( new DataOutputViewStreamWrapper(out), keyGroupIdx);
@SuppressWarnings("unchecked") public <N> InternalTimerService<N> getInternalTimerService( String name, TimerSerializer<K, N> timerSerializer, Triggerable<K, N> triggerable) { InternalTimerServiceImpl<K, N> timerService = registerOrGetTimerService(name, timerSerializer); timerService.startTimerService( timerSerializer.getKeySerializer(), timerSerializer.getNamespaceSerializer(), triggerable); return timerService; }
/** * Stream operators with state which can be restored need to override this hook method. * * @param context context that allows to register different states. */ public void initializeState(StateInitializationContext context) throws Exception { if (getKeyedStateBackend() != null) { KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange(); // and then initialize the timer services for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) { int keyGroupIdx = streamProvider.getKeyGroupId(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); timeServiceManager.restoreStateForKeyGroup( new DataInputViewStreamWrapper(streamProvider.getStream()), keyGroupIdx, getUserCodeClassloader()); } } }
timeServiceManager = new InternalTimeServiceManager<>( getKeyedStateBackend().getNumberOfKeyGroups(), getKeyedStateBackend().getKeyGroupRange(),
@SuppressWarnings("unchecked") <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService(String name, TimerSerializer<K, N> timerSerializer) { InternalTimerServiceImpl<K, N> timerService = (InternalTimerServiceImpl<K, N>) timerServices.get(name); if (timerService == null) { timerService = new InternalTimerServiceImpl<>( localKeyGroupRange, keyContext, processingTimeService, createTimerPriorityQueue(PROCESSING_TIMER_PREFIX + name, timerSerializer), createTimerPriorityQueue(EVENT_TIMER_PREFIX + name, timerSerializer)); timerServices.put(name, timerService); } return timerService; }
@Override public void write(DataOutputView out) throws IOException { super.write(out); final Map<String, InternalTimerServiceImpl<K, ?>> registeredTimerServices = timerServicesManager.getRegisteredTimerServices(); out.writeInt(registeredTimerServices.size()); for (Map.Entry<String, InternalTimerServiceImpl<K, ?>> entry : registeredTimerServices.entrySet()) { String serviceName = entry.getKey(); InternalTimerServiceImpl<K, ?> timerService = entry.getValue(); out.writeUTF(serviceName); InternalTimersSnapshotReaderWriters .getWriterForVersion(VERSION, timerService.snapshotTimersForKeyGroup(keyGroupIdx)) .writeTimersSnapshot(out); } }
@VisibleForTesting public int numEventTimeTimers() { return timeServiceManager == null ? 0 : timeServiceManager.numEventTimeTimers(); } }
@VisibleForTesting public int numProcessingTimeTimers() { return timeServiceManager == null ? 0 : timeServiceManager.numProcessingTimeTimers(); }
out.startNewKeyGroup(keyGroupIdx); timeServiceManager.snapshotStateForKeyGroup( new DataOutputViewStreamWrapper(out), keyGroupIdx);
@SuppressWarnings("unchecked") private <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService( String serviceName, InternalTimersSnapshot<?, ?> restoredTimersSnapshot) { final TypeSerializer<K> keySerializer = (TypeSerializer<K>) restoredTimersSnapshot.getKeySerializer(); final TypeSerializer<N> namespaceSerializer = (TypeSerializer<N>) restoredTimersSnapshot.getNamespaceSerializer(); TimerSerializer<K, N> timerSerializer = new TimerSerializer<>(keySerializer, namespaceSerializer); return timerServicesManager.registerOrGetTimerService(serviceName, timerSerializer); } }
@SuppressWarnings("unchecked") <N> InternalTimerServiceImpl<K, N> registerOrGetTimerService(String name, TimerSerializer<K, N> timerSerializer) { InternalTimerServiceImpl<K, N> timerService = (InternalTimerServiceImpl<K, N>) timerServices.get(name); if (timerService == null) { timerService = new InternalTimerServiceImpl<>( localKeyGroupRange, keyContext, processingTimeService, createTimerPriorityQueue(PROCESSING_TIMER_PREFIX + name, timerSerializer), createTimerPriorityQueue(EVENT_TIMER_PREFIX + name, timerSerializer)); timerServices.put(name, timerService); } return timerService; }
@Override public void write(DataOutputView out) throws IOException { super.write(out); final Map<String, InternalTimerServiceImpl<K, ?>> registeredTimerServices = timerServicesManager.getRegisteredTimerServices(); out.writeInt(registeredTimerServices.size()); for (Map.Entry<String, InternalTimerServiceImpl<K, ?>> entry : registeredTimerServices.entrySet()) { String serviceName = entry.getKey(); InternalTimerServiceImpl<K, ?> timerService = entry.getValue(); out.writeUTF(serviceName); InternalTimersSnapshotReaderWriters .getWriterForVersion(VERSION, timerService.snapshotTimersForKeyGroup(keyGroupIdx)) .writeTimersSnapshot(out); } }
public void processWatermark(Watermark mark) throws Exception { if (timeServiceManager != null) { timeServiceManager.advanceWatermark(mark); } output.emitWatermark(mark); }
protected <K> InternalTimeServiceManager<K> internalTimeServiceManager( AbstractKeyedStateBackend<K> keyedStatedBackend, KeyContext keyContext, //the operator Iterable<KeyGroupStatePartitionStreamProvider> rawKeyedStates) throws Exception { if (keyedStatedBackend == null) { return null; } final KeyGroupRange keyGroupRange = keyedStatedBackend.getKeyGroupRange(); final InternalTimeServiceManager<K> timeServiceManager = new InternalTimeServiceManager<>( keyGroupRange, keyContext, keyedStatedBackend, processingTimeService, keyedStatedBackend.requiresLegacySynchronousTimerSnapshots()); // and then initialize the timer services for (KeyGroupStatePartitionStreamProvider streamProvider : rawKeyedStates) { int keyGroupIdx = streamProvider.getKeyGroupId(); Preconditions.checkArgument(keyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); timeServiceManager.restoreStateForKeyGroup( streamProvider.getStream(), keyGroupIdx, environment.getUserClassLoader()); } return timeServiceManager; }
@VisibleForTesting public int numEventTimeTimers() { return timeServiceManager == null ? 0 : timeServiceManager.numEventTimeTimers(); } }