/** * Creates a snapshot of this {@link CopyOnWriteStateTable}, to be written in checkpointing. The snapshot integrity * is protected through copy-on-write from the {@link CopyOnWriteStateTable}. Users should call * {@link #releaseSnapshot(CopyOnWriteStateTableSnapshot)} after using the returned object. * * @return a snapshot from this {@link CopyOnWriteStateTable}, for checkpointing. */ @Override public CopyOnWriteStateTableSnapshot<K, N, S> createSnapshot() { return new CopyOnWriteStateTableSnapshot<>(this); }
/** * Releases a snapshot for this {@link CopyOnWriteStateTable}. This method should be called once a snapshot is no more needed, * so that the {@link CopyOnWriteStateTable} can stop considering this snapshot for copy-on-write, thus avoiding unnecessary * object creation. * * @param snapshotToRelease the snapshot to release, which was previously created by this state table. */ void releaseSnapshot(CopyOnWriteStateTableSnapshot<K, N, S> snapshotToRelease) { Preconditions.checkArgument(snapshotToRelease.isOwner(this), "Cannot release snapshot which is owned by a different state table."); releaseSnapshot(snapshotToRelease.getSnapshotVersion()); }
@Override public void writeMappingsInKeyGroup(DataOutputView dov, int keyGroupId) throws IOException { if (null == keyGroupOffsets) { partitionEntriesByKeyGroup(); } final CopyOnWriteStateTable.StateTableEntry<K, N, S>[] groupedOut = snapshotData; KeyGroupRange keyGroupRange = owningStateTable.keyContext.getKeyGroupRange(); int keyGroupOffsetIdx = keyGroupId - keyGroupRange.getStartKeyGroup() - 1; int startOffset = keyGroupOffsetIdx < 0 ? 0 : keyGroupOffsets[keyGroupOffsetIdx]; int endOffset = keyGroupOffsets[keyGroupOffsetIdx + 1]; // write number of mappings in key-group dov.writeInt(endOffset - startOffset); // write mappings for (int i = startOffset; i < endOffset; ++i) { CopyOnWriteStateTable.StateTableEntry<K, N, S> toWrite = groupedOut[i]; groupedOut[i] = null; // free asap for GC localNamespaceSerializer.serialize(toWrite.namespace, dov); localKeySerializer.serialize(toWrite.key, dov); localStateSerializer.serialize(toWrite.state, dov); } }
/** * Releases a snapshot for this {@link CopyOnWriteStateTable}. This method should be called once a snapshot is no more needed, * so that the {@link CopyOnWriteStateTable} can stop considering this snapshot for copy-on-write, thus avoiding unnecessary * object creation. * * @param snapshotToRelease the snapshot to release, which was previously created by this state table. */ void releaseSnapshot(CopyOnWriteStateTableSnapshot<K, N, S> snapshotToRelease) { Preconditions.checkArgument(snapshotToRelease.isOwner(this), "Cannot release snapshot which is owned by a different state table."); releaseSnapshot(snapshotToRelease.getSnapshotVersion()); }
@Override public void writeMappingsInKeyGroup(DataOutputView dov, int keyGroupId) throws IOException { if (null == keyGroupOffsets) { partitionEntriesByKeyGroup(); } final CopyOnWriteStateTable.StateTableEntry<K, N, S>[] groupedOut = snapshotData; KeyGroupRange keyGroupRange = owningStateTable.keyContext.getKeyGroupRange(); int keyGroupOffsetIdx = keyGroupId - keyGroupRange.getStartKeyGroup() - 1; int startOffset = keyGroupOffsetIdx < 0 ? 0 : keyGroupOffsets[keyGroupOffsetIdx]; int endOffset = keyGroupOffsets[keyGroupOffsetIdx + 1]; // write number of mappings in key-group dov.writeInt(endOffset - startOffset); // write mappings for (int i = startOffset; i < endOffset; ++i) { CopyOnWriteStateTable.StateTableEntry<K, N, S> toWrite = groupedOut[i]; groupedOut[i] = null; // free asap for GC localNamespaceSerializer.serialize(toWrite.namespace, dov); localKeySerializer.serialize(toWrite.key, dov); localStateSerializer.serialize(toWrite.state, dov); } }
/** * Releases a snapshot for this {@link CopyOnWriteStateTable}. This method should be called once a snapshot is no more needed, * so that the {@link CopyOnWriteStateTable} can stop considering this snapshot for copy-on-write, thus avoiding unnecessary * object creation. * * @param snapshotToRelease the snapshot to release, which was previously created by this state table. */ void releaseSnapshot(CopyOnWriteStateTableSnapshot<K, N, S> snapshotToRelease) { Preconditions.checkArgument(snapshotToRelease.isOwner(this), "Cannot release snapshot which is owned by a different state table."); releaseSnapshot(snapshotToRelease.getSnapshotVersion()); }
/** * Creates a snapshot of this {@link CopyOnWriteStateTable}, to be written in checkpointing. The snapshot integrity * is protected through copy-on-write from the {@link CopyOnWriteStateTable}. Users should call * {@link #releaseSnapshot(CopyOnWriteStateTableSnapshot)} after using the returned object. * * @return a snapshot from this {@link CopyOnWriteStateTable}, for checkpointing. */ @Override public CopyOnWriteStateTableSnapshot<K, N, S> createSnapshot() { return new CopyOnWriteStateTableSnapshot<>(this); }
/** * Releases a snapshot for this {@link CopyOnWriteStateTable}. This method should be called once a snapshot is no more needed, * so that the {@link CopyOnWriteStateTable} can stop considering this snapshot for copy-on-write, thus avoiding unnecessary * object creation. * * @param snapshotToRelease the snapshot to release, which was previously created by this state table. */ void releaseSnapshot(CopyOnWriteStateTableSnapshot<K, N, S> snapshotToRelease) { Preconditions.checkArgument(snapshotToRelease.isOwner(this), "Cannot release snapshot which is owned by a different state table."); releaseSnapshot(snapshotToRelease.getSnapshotVersion()); }
/** * Creates a snapshot of this {@link CopyOnWriteStateTable}, to be written in checkpointing. The snapshot integrity * is protected through copy-on-write from the {@link CopyOnWriteStateTable}. Users should call * {@link #releaseSnapshot(CopyOnWriteStateTableSnapshot)} after using the returned object. * * @return a snapshot from this {@link CopyOnWriteStateTable}, for checkpointing. */ @Nonnull @Override public CopyOnWriteStateTableSnapshot<K, N, S> stateSnapshot() { return new CopyOnWriteStateTableSnapshot<>(this); }
/** * Creates a snapshot of this {@link CopyOnWriteStateTable}, to be written in checkpointing. The snapshot integrity * is protected through copy-on-write from the {@link CopyOnWriteStateTable}. Users should call * {@link #releaseSnapshot(CopyOnWriteStateTableSnapshot)} after using the returned object. * * @return a snapshot from this {@link CopyOnWriteStateTable}, for checkpointing. */ @Nonnull @Override public CopyOnWriteStateTableSnapshot<K, N, S> stateSnapshot() { return new CopyOnWriteStateTableSnapshot<>(this); }