org.apache.flink.runtime.state.internal.InternalKvState.StateIncrementalVisitor Java Examples

The following examples show how to use org.apache.flink.runtime.state.internal.InternalKvState.StateIncrementalVisitor. 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: CopyOnWriteStateTableTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Test operations specific for StateIncrementalVisitor in {@code testRandomModificationsAndCopyOnWriteIsolation()}.
 *
 * <p>Check next, update and remove during global iteration of StateIncrementalVisitor.
 */
private static void testStateIteratorWithUpdate(
	StateIncrementalVisitor<Integer, Integer, ArrayList<Integer>> updatingIterator,
	CopyOnWriteStateTable<Integer, Integer, ArrayList<Integer>> stateTable,
	HashMap<Tuple2<Integer, Integer>, ArrayList<Integer>> referenceMap,
	boolean update, boolean remove) {

	for (StateEntry<Integer, Integer, ArrayList<Integer>> stateEntry : updatingIterator.nextEntries()) {
		Integer key = stateEntry.getKey();
		Integer namespace = stateEntry.getNamespace();
		Tuple2<Integer, Integer> compositeKey = new Tuple2<>(key, namespace);
		Assert.assertEquals(referenceMap.get(compositeKey), stateEntry.getState());

		if (update) {
			ArrayList<Integer> newState = new ArrayList<>(stateEntry.getState());
			if (!newState.isEmpty()) {
				newState.remove(0);
			}
			updatingIterator.update(stateEntry, newState);
			referenceMap.put(compositeKey, new ArrayList<>(newState));
			Assert.assertEquals(newState, stateTable.get(key, namespace));
		}

		if (remove) {
			updatingIterator.remove(stateEntry);
			referenceMap.remove(compositeKey);
		}
	}
}
 
Example #2
Source File: StateTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private void next() {
	while (keyGroupIndex < keyGroupedStateMaps.length) {
		StateMap<K, N, S> stateMap = keyGroupedStateMaps[keyGroupIndex++];
		StateIncrementalVisitor<K, N, S> visitor =
			stateMap.getStateIncrementalVisitor(recommendedMaxNumberOfReturnedRecords);
		if (visitor.hasNext()) {
			stateIncrementalVisitor = visitor;
			return;
		}
	}
}
 
Example #3
Source File: StateTable.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
	while (stateIncrementalVisitor == null || !stateIncrementalVisitor.hasNext()) {
		if (keyGroupIndex == keyGroupedStateMaps.length) {
			return false;
		}
		StateIncrementalVisitor<K, N, S> visitor =
			keyGroupedStateMaps[keyGroupIndex++].getStateIncrementalVisitor(recommendedMaxNumberOfReturnedRecords);
		if (visitor.hasNext()) {
			stateIncrementalVisitor = visitor;
			break;
		}
	}
	return true;
}
 
Example #4
Source File: CopyOnWriteStateMapTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Test operations specific for StateIncrementalVisitor in {@code testRandomModificationsAndCopyOnWriteIsolation()}.
 *
 * <p>Check next, update and remove during global iteration of StateIncrementalVisitor.
 */
private static void testStateIteratorWithUpdate(
	StateIncrementalVisitor<Integer, Integer, ArrayList<Integer>> updatingIterator,
	CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap,
	HashMap<Tuple2<Integer, Integer>, ArrayList<Integer>> referenceMap,
	boolean update, boolean remove) {

	for (StateEntry<Integer, Integer, ArrayList<Integer>> stateEntry : updatingIterator.nextEntries()) {
		Integer key = stateEntry.getKey();
		Integer namespace = stateEntry.getNamespace();
		Tuple2<Integer, Integer> compositeKey = new Tuple2<>(key, namespace);
		Assert.assertEquals(referenceMap.get(compositeKey), stateEntry.getState());

		if (update) {
			ArrayList<Integer> newState = new ArrayList<>(stateEntry.getState());
			if (!newState.isEmpty()) {
				newState.remove(0);
			}
			updatingIterator.update(stateEntry, newState);
			referenceMap.put(compositeKey, new ArrayList<>(newState));
			Assert.assertEquals(newState, stateMap.get(key, namespace));
		}

		if (remove) {
			updatingIterator.remove(stateEntry);
			referenceMap.remove(compositeKey);
		}
	}
}
 
Example #5
Source File: StateTable.java    From flink with Apache License 2.0 5 votes vote down vote up
private void next() {
	while (keyGroupIndex < keyGroupedStateMaps.length) {
		StateMap<K, N, S> stateMap = keyGroupedStateMaps[keyGroupIndex++];
		StateIncrementalVisitor<K, N, S> visitor =
			stateMap.getStateIncrementalVisitor(recommendedMaxNumberOfReturnedRecords);
		if (visitor.hasNext()) {
			stateIncrementalVisitor = visitor;
			return;
		}
	}
}
 
Example #6
Source File: StateTable.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public boolean hasNext() {
	while (stateIncrementalVisitor == null || !stateIncrementalVisitor.hasNext()) {
		if (keyGroupIndex == keyGroupedStateMaps.length) {
			return false;
		}
		StateIncrementalVisitor<K, N, S> visitor =
			keyGroupedStateMaps[keyGroupIndex++].getStateIncrementalVisitor(recommendedMaxNumberOfReturnedRecords);
		if (visitor.hasNext()) {
			stateIncrementalVisitor = visitor;
			break;
		}
	}
	return true;
}
 
Example #7
Source File: CopyOnWriteStateMapTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Test operations specific for StateIncrementalVisitor in {@code testRandomModificationsAndCopyOnWriteIsolation()}.
 *
 * <p>Check next, update and remove during global iteration of StateIncrementalVisitor.
 */
private static void testStateIteratorWithUpdate(
	StateIncrementalVisitor<Integer, Integer, ArrayList<Integer>> updatingIterator,
	CopyOnWriteStateMap<Integer, Integer, ArrayList<Integer>> stateMap,
	HashMap<Tuple2<Integer, Integer>, ArrayList<Integer>> referenceMap,
	boolean update, boolean remove) {

	for (StateEntry<Integer, Integer, ArrayList<Integer>> stateEntry : updatingIterator.nextEntries()) {
		Integer key = stateEntry.getKey();
		Integer namespace = stateEntry.getNamespace();
		Tuple2<Integer, Integer> compositeKey = new Tuple2<>(key, namespace);
		Assert.assertEquals(referenceMap.get(compositeKey), stateEntry.getState());

		if (update) {
			ArrayList<Integer> newState = new ArrayList<>(stateEntry.getState());
			if (!newState.isEmpty()) {
				newState.remove(0);
			}
			updatingIterator.update(stateEntry, newState);
			referenceMap.put(compositeKey, new ArrayList<>(newState));
			Assert.assertEquals(newState, stateMap.get(key, namespace));
		}

		if (remove) {
			updatingIterator.remove(stateEntry);
			referenceMap.remove(compositeKey);
		}
	}
}
 
Example #8
Source File: NestedMapsStateTable.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) {
	return new StateEntryIterator();
}
 
Example #9
Source File: CopyOnWriteStateTable.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) {
	return new StateIncrementalVisitorImpl(recommendedMaxNumberOfReturnedRecords);
}
 
Example #10
Source File: StateTable.java    From flink with Apache License 2.0 4 votes vote down vote up
public StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) {
	return new StateEntryIterator(recommendedMaxNumberOfReturnedRecords);
}
 
Example #11
Source File: StateTable.java    From flink with Apache License 2.0 4 votes vote down vote up
public StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords) {
	return new StateEntryIterator(recommendedMaxNumberOfReturnedRecords);
}
 
Example #12
Source File: StateTable.java    From Flink-CEPplus with Apache License 2.0 votes vote down vote up
public abstract StateIncrementalVisitor<K, N, S> getStateIncrementalVisitor(int recommendedMaxNumberOfReturnedRecords);