operatorStateMetadata.put(DefaultOperatorStateBackend.DEFAULT_OPERATOR_STATE_NAME, metaInfo); KeyGroupRangeOffsets keyGroupRangeOffsets = new KeyGroupRangeOffsets(new KeyGroupRange(0, 0));
DataOutputView dov = new DataOutputViewStreamWrapper(out); KeyGroupRangeOffsets offsets = new KeyGroupRangeOffsets(i == 9 ? KeyGroupRange.EMPTY_KEY_GROUP_RANGE : new KeyGroupRange(prev, end)); prev = end + 1; for (int kg : offsets.getKeyGroupRange()) { offsets.setKeyGroupOffset(kg, out.getPosition()); dov.writeInt(kg); ++writtenKeyGroups;
@Override public boolean hasNext() { if (null != currentStateHandle && currentOffsetsIterator.hasNext()) { return true; } closeCurrentStream(); while (stateHandleIterator.hasNext()) { currentStateHandle = stateHandleIterator.next(); if (currentStateHandle.getKeyGroupRange().getNumberOfKeyGroups() > 0) { currentOffsetsIterator = currentStateHandle.getGroupRangeOffsets().iterator(); return true; } } return false; }
/** * Returns a key-group range with offsets which is the intersection of the internal key-group range with the given * key-group range. * * @param keyGroupRange Key-group range to intersect with the internal key-group range. * @return The key-group range with offsets for the intersection of the internal key-group range with the given * key-group range. */ public KeyGroupRangeOffsets getIntersection(KeyGroupRange keyGroupRange) { Preconditions.checkNotNull(keyGroupRange); KeyGroupRange intersection = this.keyGroupRange.getIntersection(keyGroupRange); long[] subOffsets = new long[intersection.getNumberOfKeyGroups()]; if(subOffsets.length > 0) { System.arraycopy( offsets, computeKeyGroupIndex(intersection.getStartKeyGroup()), subOffsets, 0, subOffsets.length); } return new KeyGroupRangeOffsets(intersection, subOffsets); }
/** * User code can call this method to signal that it begins to write a new key group with the given key group id. * This id must be within the {@link KeyGroupsList} provided by the stream. Each key-group can only be started once * and is considered final/immutable as soon as this method is called again. */ public void startNewKeyGroup(int keyGroupId) throws IOException { if (isKeyGroupAlreadyStarted(keyGroupId)) { throw new IOException("Key group " + keyGroupId + " already registered!"); } keyGroupRangeOffsets.setKeyGroupOffset(keyGroupId, delegate.getPos()); currentKeyGroup = keyGroupId; }
/** * Returns a list of all key-groups which can be written to this stream. */ public KeyGroupsList getKeyGroupList() { return keyGroupRangeOffsets.getKeyGroupRange(); }
keyGroupRangeOffsets = new KeyGroupRangeOffsets( KeyGroupRangeAssignment.computeKeyGroupRangeForOperatorIndex(maxParallelism, parallelism, opIndex)); keyGroupRangeOffsets.setKeyGroupOffset( previousKeyGroup, checkpointFileStream.getPos()); keyGroupRangeOffsets.setKeyGroupOffset( nextRow.getKeyGroup(maxParallelism), checkpointFileStream.getPos());
/** * Returns true, if the key group with the given id was already started. The key group might not yet be finished, * if it's id is equal to the return value of {@link #getCurrentKeyGroup()}. */ public boolean isKeyGroupAlreadyStarted(int keyGroupId) { return NO_OFFSET_SET != keyGroupRangeOffsets.getKeyGroupOffset(keyGroupId); }
/** * Returns the offset for the given key-group. The key-group must be contained in the range. * * @param keyGroup Key-group for which we query the offset. Key-group must be contained in the range. * @return The offset for the given key-group which must be contained in the range. */ public long getKeyGroupOffset(int keyGroup) { return offsets[computeKeyGroupIndex(keyGroup)]; }
/** * * @param keyGroupRange a key group range to intersect. * @return key-group state over a range that is the intersection between this handle's key-group range and the * provided key-group range. */ public KeyGroupsStateHandle getIntersection(KeyGroupRange keyGroupRange) { return new KeyGroupsStateHandle(groupRangeOffsets.getIntersection(keyGroupRange), stateHandle); }
@Override public int hashCode() { int result = groupRangeOffsets.hashCode(); result = 31 * result + stateHandle.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof KeyGroupsStateHandle)) { return false; } KeyGroupsStateHandle that = (KeyGroupsStateHandle) o; if (!groupRangeOffsets.equals(that.groupRangeOffsets)) { return false; } return stateHandle.equals(that.stateHandle); }
/** * Returns a key-group range with offsets which is the intersection of the internal key-group range with the given * key-group range. * * @param keyGroupRange Key-group range to intersect with the internal key-group range. * @return The key-group range with offsets for the intersection of the internal key-group range with the given * key-group range. */ public KeyGroupRangeOffsets getIntersection(KeyGroupRange keyGroupRange) { Preconditions.checkNotNull(keyGroupRange); KeyGroupRange intersection = this.keyGroupRange.getIntersection(keyGroupRange); long[] subOffsets = new long[intersection.getNumberOfKeyGroups()]; if(subOffsets.length > 0) { System.arraycopy( offsets, computeKeyGroupIndex(intersection.getStartKeyGroup()), subOffsets, 0, subOffsets.length); } return new KeyGroupRangeOffsets(intersection, subOffsets); }
/** * User code can call this method to signal that it begins to write a new key group with the given key group id. * This id must be within the {@link KeyGroupsList} provided by the stream. Each key-group can only be started once * and is considered final/immutable as soon as this method is called again. */ public void startNewKeyGroup(int keyGroupId) throws IOException { if (isKeyGroupAlreadyStarted(keyGroupId)) { throw new IOException("Key group " + keyGroupId + " already registered!"); } keyGroupRangeOffsets.setKeyGroupOffset(keyGroupId, delegate.getPos()); currentKeyGroup = keyGroupId; }
/** * Returns a list of all key-groups which can be written to this stream. */ public KeyGroupsList getKeyGroupList() { return keyGroupRangeOffsets.getKeyGroupRange(); }
/** * Returns true, if the key group with the given id was already started. The key group might not yet be finished, * if it's id is equal to the return value of {@link #getCurrentKeyGroup()}. */ public boolean isKeyGroupAlreadyStarted(int keyGroupId) { return NO_OFFSET_SET != keyGroupRangeOffsets.getKeyGroupOffset(keyGroupId); }
/** * Sets the offset for the given key-group. The key-group must be contained in the range. * * @param keyGroup Key-group for which we set the offset. Must be contained in the range. * @param offset Offset for the key-group. */ public void setKeyGroupOffset(int keyGroup, long offset) { offsets[computeKeyGroupIndex(keyGroup)] = offset; }
/** * * @param keyGroupRange a key group range to intersect. * @return key-group state over a range that is the intersection between this handle's key-group range and the * provided key-group range. */ public KeyGroupsStateHandle getIntersection(KeyGroupRange keyGroupRange) { return new KeyGroupsStateHandle(groupRangeOffsets.getIntersection(keyGroupRange), stateHandle); }
@Override public int hashCode() { int result = groupRangeOffsets.hashCode(); result = 31 * result + stateHandle.hashCode(); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof KeyGroupsStateHandle)) { return false; } KeyGroupsStateHandle that = (KeyGroupsStateHandle) o; if (!groupRangeOffsets.equals(that.groupRangeOffsets)) { return false; } return stateHandle.equals(that.stateHandle); }