Java Code Examples for org.apache.flink.contrib.streaming.state.RocksIteratorWrapper#isValid()

The following examples show how to use org.apache.flink.contrib.streaming.state.RocksIteratorWrapper#isValid() . 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: RocksStatesPerKeyGroupMergeIterator.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private PriorityQueue<RocksSingleStateIterator> buildIteratorHeap(
	List<Tuple2<RocksIteratorWrapper, Integer>> kvStateIterators) {

	Comparator<RocksSingleStateIterator> iteratorComparator = COMPARATORS.get(keyGroupPrefixByteCount - 1);

	PriorityQueue<RocksSingleStateIterator> iteratorPriorityQueue =
		new PriorityQueue<>(kvStateIterators.size(), iteratorComparator);

	for (Tuple2<RocksIteratorWrapper, Integer> rocksIteratorWithKVStateId : kvStateIterators) {
		final RocksIteratorWrapper rocksIterator = rocksIteratorWithKVStateId.f0;
		rocksIterator.seekToFirst();
		if (rocksIterator.isValid()) {
			iteratorPriorityQueue.offer(
				new RocksSingleStateIterator(rocksIterator, rocksIteratorWithKVStateId.f1));
		} else {
			IOUtils.closeQuietly(rocksIterator);
		}
	}
	return iteratorPriorityQueue;
}
 
Example 2
Source File: RocksStatesPerKeyGroupMergeIterator.java    From flink with Apache License 2.0 6 votes vote down vote up
private PriorityQueue<RocksSingleStateIterator> buildIteratorHeap(
	List<Tuple2<RocksIteratorWrapper, Integer>> kvStateIterators) {

	Comparator<RocksSingleStateIterator> iteratorComparator = COMPARATORS.get(keyGroupPrefixByteCount - 1);

	PriorityQueue<RocksSingleStateIterator> iteratorPriorityQueue =
		new PriorityQueue<>(kvStateIterators.size(), iteratorComparator);

	for (Tuple2<RocksIteratorWrapper, Integer> rocksIteratorWithKVStateId : kvStateIterators) {
		final RocksIteratorWrapper rocksIterator = rocksIteratorWithKVStateId.f0;
		rocksIterator.seekToFirst();
		if (rocksIterator.isValid()) {
			iteratorPriorityQueue.offer(
				new RocksSingleStateIterator(rocksIterator, rocksIteratorWithKVStateId.f1));
		} else {
			IOUtils.closeQuietly(rocksIterator);
		}
	}
	return iteratorPriorityQueue;
}
 
Example 3
Source File: RocksStatesPerKeyGroupMergeIterator.java    From flink with Apache License 2.0 6 votes vote down vote up
private PriorityQueue<RocksSingleStateIterator> buildIteratorHeap(
	List<Tuple2<RocksIteratorWrapper, Integer>> kvStateIterators) {

	Comparator<RocksSingleStateIterator> iteratorComparator = COMPARATORS.get(keyGroupPrefixByteCount - 1);

	PriorityQueue<RocksSingleStateIterator> iteratorPriorityQueue =
		new PriorityQueue<>(kvStateIterators.size(), iteratorComparator);

	for (Tuple2<RocksIteratorWrapper, Integer> rocksIteratorWithKVStateId : kvStateIterators) {
		final RocksIteratorWrapper rocksIterator = rocksIteratorWithKVStateId.f0;
		rocksIterator.seekToFirst();
		if (rocksIterator.isValid()) {
			iteratorPriorityQueue.offer(
				new RocksSingleStateIterator(rocksIterator, rocksIteratorWithKVStateId.f1));
		} else {
			IOUtils.closeQuietly(rocksIterator);
		}
	}
	return iteratorPriorityQueue;
}
 
Example 4
Source File: RocksStatesPerKeyGroupMergeIterator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the iterator. Should only be called if {@link #isValid()} returned true.
 * Valid flag can only change after calling {@link #next()}.
 */
public void next() {
	newKeyGroup = false;
	newKVState = false;

	final RocksIteratorWrapper rocksIterator = currentSubIterator.getIterator();
	rocksIterator.next();

	byte[] oldKey = currentSubIterator.getCurrentKey();
	if (rocksIterator.isValid()) {

		currentSubIterator.setCurrentKey(rocksIterator.key());

		if (isDifferentKeyGroup(oldKey, currentSubIterator.getCurrentKey())) {
			heap.offer(currentSubIterator);
			currentSubIterator = heap.remove();
			newKVState = currentSubIterator.getIterator() != rocksIterator;
			detectNewKeyGroup(oldKey);
		}
	} else {
		IOUtils.closeQuietly(rocksIterator);

		if (heap.isEmpty()) {
			currentSubIterator = null;
			valid = false;
		} else {
			currentSubIterator = heap.remove();
			newKVState = true;
			detectNewKeyGroup(oldKey);
		}
	}
}
 
Example 5
Source File: RocksStatesPerKeyGroupMergeIterator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the iterator. Should only be called if {@link #isValid()} returned true.
 * Valid flag can only change after calling {@link #next()}.
 */
public void next() {
	newKeyGroup = false;
	newKVState = false;

	final RocksIteratorWrapper rocksIterator = currentSubIterator.getIterator();
	rocksIterator.next();

	byte[] oldKey = currentSubIterator.getCurrentKey();
	if (rocksIterator.isValid()) {

		currentSubIterator.setCurrentKey(rocksIterator.key());

		if (isDifferentKeyGroup(oldKey, currentSubIterator.getCurrentKey())) {
			heap.offer(currentSubIterator);
			currentSubIterator = heap.remove();
			newKVState = currentSubIterator.getIterator() != rocksIterator;
			detectNewKeyGroup(oldKey);
		}
	} else {
		IOUtils.closeQuietly(rocksIterator);

		if (heap.isEmpty()) {
			currentSubIterator = null;
			valid = false;
		} else {
			currentSubIterator = heap.remove();
			newKVState = true;
			detectNewKeyGroup(oldKey);
		}
	}
}
 
Example 6
Source File: RocksStatesPerKeyGroupMergeIterator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the iterator. Should only be called if {@link #isValid()} returned true.
 * Valid flag can only change after calling {@link #next()}.
 */
public void next() {
	newKeyGroup = false;
	newKVState = false;

	final RocksIteratorWrapper rocksIterator = currentSubIterator.getIterator();
	rocksIterator.next();

	byte[] oldKey = currentSubIterator.getCurrentKey();
	if (rocksIterator.isValid()) {

		currentSubIterator.setCurrentKey(rocksIterator.key());

		if (isDifferentKeyGroup(oldKey, currentSubIterator.getCurrentKey())) {
			heap.offer(currentSubIterator);
			currentSubIterator = heap.remove();
			newKVState = currentSubIterator.getIterator() != rocksIterator;
			detectNewKeyGroup(oldKey);
		}
	} else {
		IOUtils.closeQuietly(rocksIterator);

		if (heap.isEmpty()) {
			currentSubIterator = null;
			valid = false;
		} else {
			currentSubIterator = heap.remove();
			newKVState = true;
			detectNewKeyGroup(oldKey);
		}
	}
}