public void snapshotStateForKeyGroup(DataOutputViewStreamWrapper stream, int keyGroupIdx) throws Exception { stream.writeInt(timerServices.size()); for (Map.Entry<String, HeapInternalTimerService<K, N>> entry : timerServices.entrySet()) { String serviceName = entry.getKey(); HeapInternalTimerService<?, ?> timerService = entry.getValue(); stream.writeUTF(serviceName); timerService.snapshotTimersForKeyGroup(stream, keyGroupIdx); } }
/** * Snapshots the timers (both processing and event time ones) for a given {@code keyGroupIdx}. * @param stream the stream to write to. * @param keyGroupIdx the id of the key-group to be put in the snapshot. */ public void snapshotTimersForKeyGroup(DataOutputViewStreamWrapper stream, int keyGroupIdx) throws Exception { InstantiationUtil.serializeObject(stream, keySerializer); InstantiationUtil.serializeObject(stream, namespaceSerializer); // write the event time timers Set<InternalTimer<K, N>> eventTimers = getEventTimeTimerSetForKeyGroup(keyGroupIdx); if (eventTimers != null) { stream.writeInt(eventTimers.size()); for (InternalTimer<K, N> timer : eventTimers) { this.timerSerializer.serialize(timer, stream); } } else { stream.writeInt(0); } // write the processing time timers Set<InternalTimer<K, N>> processingTimers = getProcessingTimeTimerSetForKeyGroup(keyGroupIdx); if (processingTimers != null) { stream.writeInt(processingTimers.size()); for (InternalTimer<K, N> timer : processingTimers) { this.timerSerializer.serialize(timer, stream); } } else { stream.writeInt(0); } }
private int writeGroupStates( CheckpointStreamFactory.CheckpointStateOutputStream localStream, StateTableSnapshot stateTableSnapshot, int stateId, int group) throws IOException { int numEntries = 0; try (OutputStream kgCompressionOut = keyGroupCompressionDecorator.decorateWithCompression(localStream)) { DataOutputViewStreamWrapper kgCompressionView = new DataOutputViewStreamWrapper(kgCompressionOut); kgCompressionView.writeInt(stateId); numEntries += stateTableSnapshot.writeMappingsInKeyGroup(kgCompressionView, group); } return numEntries; }
@Override public KeyGroupsStateHandle performOperation() throws Exception { long asyncStartTime = System.currentTimeMillis(); CheckpointStreamFactory.CheckpointStateOutputStream stream = getIoHandle(); DataOutputViewStreamWrapper outView = new DataOutputViewStreamWrapper(stream); serializationProxy.write(outView); long[] keyGroupRangeOffsets = new long[keyGroupRange.getNumberOfKeyGroups()]; for (int keyGroupPos = 0; keyGroupPos < keyGroupRange.getNumberOfKeyGroups(); ++keyGroupPos) { int keyGroupId = keyGroupRange.getKeyGroupId(keyGroupPos); keyGroupRangeOffsets[keyGroupPos] = stream.getPos(); outView.writeInt(keyGroupId); for (Map.Entry<String, StateTable<K, ?, ?>> kvState : stateTables.entrySet()) { outView.writeShort(kVStateToId.get(kvState.getKey())); cowStateStableSnapshots.get(kvState.getValue()).writeMappingsInKeyGroup(outView, keyGroupId); } } final StreamStateHandle streamStateHandle = closeStreamAndGetStateHandle(); if (asynchronousSnapshots) { LOG.info("Heap backend snapshot ({}, asynchronous part) in thread {} took {} ms.", streamFactory, Thread.currentThread(), (System.currentTimeMillis() - asyncStartTime)); } if (streamStateHandle == null) { return null; } KeyGroupRangeOffsets offsets = new KeyGroupRangeOffsets(keyGroupRange, keyGroupRangeOffsets); final KeyGroupsStateHandle keyGroupsStateHandle = new KeyGroupsStateHandle(offsets, streamStateHandle); return keyGroupsStateHandle; } };
int numEntries = 0; outView.writeInt(group);