当前位置: 首页>>代码示例>>Java>>正文


Java SpillingResettableMutableObjectIterator类代码示例

本文整理汇总了Java中org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator的典型用法代码示例。如果您正苦于以下问题:Java SpillingResettableMutableObjectIterator类的具体用法?Java SpillingResettableMutableObjectIterator怎么用?Java SpillingResettableMutableObjectIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SpillingResettableMutableObjectIterator类属于org.apache.flink.runtime.operators.resettable包,在下文中一共展示了SpillingResettableMutableObjectIterator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runStreamedOuterFirst

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
private void runStreamedOuterFirst() throws Exception {
	if (LOG.isDebugEnabled())  {
		LOG.debug(this.taskContext.formatLogString("Running Cross with Nested-Loops: " +
				"First input is outer side, second input is inner (spilling) side."));
	}
	
	final MutableObjectIterator<T1> in1 = this.taskContext.getInput(0);
	final MutableObjectIterator<T2> in2 = this.taskContext.getInput(1);
	
	final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
	final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
	
	final SpillingResettableMutableObjectIterator<T2> spillVals = new SpillingResettableMutableObjectIterator<T2>(
			in2, serializer2, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide,
			this.taskContext.getOwningNepheleTask());
	this.spillIter = spillVals;
	
	T1 val1;
	final T1 val1Reuse = serializer1.createInstance();
	T1 val1Copy = serializer1.createInstance();
	T2 val2;
	final T2 val2Reuse = serializer2.createInstance();

	final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
	final Collector<OT> collector = this.taskContext.getOutputCollector();
	
	// for all blocks
	while (this.running && ((val1 = in1.next(val1Reuse)) != null)) {
		// for all values from the spilling side
		while (this.running && ((val2 = spillVals.next(val2Reuse)) != null)) {
			val1Copy = serializer1.copy(val1, val1Copy);
			collector.collect(crosser.cross(val1Copy, val2));
			//crosser.cross(val1Copy, val2, collector);
		}
		spillVals.reset();
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:38,代码来源:CrossDriver.java

示例2: runStreamedOuterSecond

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
private void runStreamedOuterSecond() throws Exception {
	if (LOG.isDebugEnabled())  {
		LOG.debug(this.taskContext.formatLogString("Running Cross with Nested-Loops: " +
				"First input is inner (spilling) side, second input is outer side."));
	}
	final MutableObjectIterator<T1> in1 = this.taskContext.getInput(0);
	final MutableObjectIterator<T2> in2 = this.taskContext.getInput(1);
	
	final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
	final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
	
	final SpillingResettableMutableObjectIterator<T1> spillVals = new SpillingResettableMutableObjectIterator<T1>(
			in1, serializer1, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide,
			this.taskContext.getOwningNepheleTask());
	this.spillIter = spillVals;
	
	T1 val1;
	final T1 val1Reuse = serializer1.createInstance();
	T2 val2;
	final T2 val2Reuse = serializer2.createInstance();
	T2 val2Copy = serializer2.createInstance();
	
	final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
	final Collector<OT> collector = this.taskContext.getOutputCollector();
	
	// for all blocks
	while (this.running && (val2 = in2.next(val2Reuse)) != null) {
		// for all values from the spilling side
		while (this.running && (val1 = spillVals.next(val1Reuse)) != null) {
			val2Copy = serializer2.copy(val2, val2Copy);
			collector.collect(crosser.cross(val1, val2Copy));
			//crosser.cross(val1, val2Copy, collector);
		}
		spillVals.reset();
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:37,代码来源:CrossDriver.java

示例3: initLocalStrategies

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
/**
 *
 * NOTE: This method must be invoked after the invocation of {@code #initInputReaders()} and
 * {@code #initInputSerializersAndComparators(int)}!
 */
protected void initLocalStrategies(int numInputs) throws Exception {

	final MemoryManager memMan = getMemoryManager();
	final IOManager ioMan = getIOManager();

	this.localStrategies = new CloseableInputProvider<?>[numInputs];
	this.inputs = new MutableObjectIterator<?>[numInputs];
	this.excludeFromReset = new boolean[numInputs];
	this.inputIsCached = new boolean[numInputs];
	this.inputIsAsyncMaterialized = new boolean[numInputs];
	this.materializationMemory = new int[numInputs];

	// set up the local strategies first, such that the can work before any temp barrier is created
	for (int i = 0; i < numInputs; i++) {
		initInputLocalStrategy(i);
	}

	// we do another loop over the inputs, because we want to instantiate all
	// sorters, etc before requesting the first input (as this call may block)

	// we have two types of materialized inputs, and both are replayable (can act as a cache)
	// The first variant materializes in a different thread and hence
	// acts as a pipeline breaker. this one should only be there, if a pipeline breaker is needed.
	// the second variant spills to the side and will not read unless the result is also consumed
	// in a pipelined fashion.
	this.resettableInputs = new SpillingResettableMutableObjectIterator<?>[numInputs];
	this.tempBarriers = new TempBarrier<?>[numInputs];

	for (int i = 0; i < numInputs; i++) {
		final int memoryPages;
		final boolean async = this.config.isInputAsynchronouslyMaterialized(i);
		final boolean cached =  this.config.isInputCached(i);

		this.inputIsAsyncMaterialized[i] = async;
		this.inputIsCached[i] = cached;

		if (async || cached) {
			memoryPages = memMan.computeNumberOfPages(this.config.getRelativeInputMaterializationMemory(i));
			if (memoryPages <= 0) {
				throw new Exception("Input marked as materialized/cached, but no memory for materialization provided.");
			}
			this.materializationMemory[i] = memoryPages;
		} else {
			memoryPages = 0;
		}

		if (async) {
			@SuppressWarnings({ "unchecked", "rawtypes" })
			TempBarrier<?> barrier = new TempBarrier(this, getInput(i), this.inputSerializers[i], memMan, ioMan, memoryPages);
			barrier.startReading();
			this.tempBarriers[i] = barrier;
			this.inputs[i] = null;
		} else if (cached) {
			@SuppressWarnings({ "unchecked", "rawtypes" })
			SpillingResettableMutableObjectIterator<?> iter = new SpillingResettableMutableObjectIterator(
				getInput(i), this.inputSerializers[i].getSerializer(), getMemoryManager(), getIOManager(), memoryPages, this);
			this.resettableInputs[i] = iter;
			this.inputs[i] = iter;
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:67,代码来源:BatchTask.java

示例4: initLocalStrategies

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
/**
 *
 * NOTE: This method must be invoked after the invocation of {@code #initInputReaders()} and
 * {@code #initInputSerializersAndComparators(int)}!
 *
 * @param numInputs
 */
protected void initLocalStrategies(int numInputs) throws Exception {

	final MemoryManager memMan = getMemoryManager();
	final IOManager ioMan = getIOManager();

	this.localStrategies = new CloseableInputProvider[numInputs];
	this.inputs = new MutableObjectIterator[numInputs];
	this.excludeFromReset = new boolean[numInputs];
	this.inputIsCached = new boolean[numInputs];
	this.inputIsAsyncMaterialized = new boolean[numInputs];
	this.materializationMemory = new int[numInputs];

	// set up the local strategies first, such that the can work before any temp barrier is created
	for (int i = 0; i < numInputs; i++) {
		initInputLocalStrategy(i);
	}

	// we do another loop over the inputs, because we want to instantiate all
	// sorters, etc before requesting the first input (as this call may block)

	// we have two types of materialized inputs, and both are replayable (can act as a cache)
	// The first variant materializes in a different thread and hence
	// acts as a pipeline breaker. this one should only be there, if a pipeline breaker is needed.
	// the second variant spills to the side and will not read unless the result is also consumed
	// in a pipelined fashion.
	this.resettableInputs = new SpillingResettableMutableObjectIterator[numInputs];
	this.tempBarriers = new TempBarrier[numInputs];

	for (int i = 0; i < numInputs; i++) {
		final int memoryPages;
		final boolean async = this.config.isInputAsynchronouslyMaterialized(i);
		final boolean cached =  this.config.isInputCached(i);

		this.inputIsAsyncMaterialized[i] = async;
		this.inputIsCached[i] = cached;

		if (async || cached) {
			memoryPages = memMan.computeNumberOfPages(this.config.getRelativeInputMaterializationMemory(i));
			if (memoryPages <= 0) {
				throw new Exception("Input marked as materialized/cached, but no memory for materialization provided.");
			}
			this.materializationMemory[i] = memoryPages;
		} else {
			memoryPages = 0;
		}

		if (async) {
			@SuppressWarnings({ "unchecked", "rawtypes" })
			TempBarrier<?> barrier = new TempBarrier(this, getInput(i), this.inputSerializers[i], memMan, ioMan, memoryPages);
			barrier.startReading();
			this.tempBarriers[i] = barrier;
			this.inputs[i] = null;
		} else if (cached) {
			@SuppressWarnings({ "unchecked", "rawtypes" })
			SpillingResettableMutableObjectIterator<?> iter = new SpillingResettableMutableObjectIterator(
				getInput(i), this.inputSerializers[i].getSerializer(), getMemoryManager(), getIOManager(), memoryPages, this);
			this.resettableInputs[i] = iter;
			this.inputs[i] = iter;
		}
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:69,代码来源:RegularPactTask.java

示例5: runBlockedOuterFirst

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
private void runBlockedOuterFirst() throws Exception {
	if (LOG.isDebugEnabled())  {
		LOG.debug(this.taskContext.formatLogString("Running Cross with Block-Nested-Loops: " +
				"First input is outer (blocking) side, second input is inner (spilling) side."));
	}
		
	final MutableObjectIterator<T1> in1 = this.taskContext.getInput(0);
	final MutableObjectIterator<T2> in2 = this.taskContext.getInput(1);
	
	final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
	final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
	
	final BlockResettableMutableObjectIterator<T1> blockVals = 
			new BlockResettableMutableObjectIterator<T1>(this.memManager, in1, serializer1, this.memPagesForBlockSide,
						this.taskContext.getOwningNepheleTask());
	this.blockIter = blockVals;
	
	final SpillingResettableMutableObjectIterator<T2> spillVals = new SpillingResettableMutableObjectIterator<T2>(
			in2, serializer2, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide,
			this.taskContext.getOwningNepheleTask());
	this.spillIter = spillVals;
	
	T1 val1;
	final T1 val1Reuse = serializer1.createInstance();
	T2 val2;
	final T2 val2Reuse = serializer2.createInstance();
	T2 val2Copy = serializer2.createInstance();
	
	final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
	final Collector<OT> collector = this.taskContext.getOutputCollector();
	
	// for all blocks
	do {
		// for all values from the spilling side
		while (this.running && ((val2 = spillVals.next(val2Reuse)) != null)) {
			// for all values in the block
			while ((val1 = blockVals.next(val1Reuse)) != null) {
				val2Copy = serializer2.copy(val2, val2Copy);
				collector.collect(crosser.cross(val1,val2Copy));
				//crosser.cross(val1, val2Copy, collector);
			}
			blockVals.reset();
		}
		spillVals.reset();
	}
	while (this.running && blockVals.nextBlock());
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:48,代码来源:CrossDriver.java

示例6: runBlockedOuterSecond

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
private void runBlockedOuterSecond() throws Exception {
	if (LOG.isDebugEnabled())  {
		LOG.debug(this.taskContext.formatLogString("Running Cross with Block-Nested-Loops: " +
				"First input is inner (spilling) side, second input is outer (blocking) side."));
	}
	
	final MutableObjectIterator<T1> in1 = this.taskContext.getInput(0);
	final MutableObjectIterator<T2> in2 = this.taskContext.getInput(1);
	
	final TypeSerializer<T1> serializer1 = this.taskContext.<T1>getInputSerializer(0).getSerializer();
	final TypeSerializer<T2> serializer2 = this.taskContext.<T2>getInputSerializer(1).getSerializer();
	
	final SpillingResettableMutableObjectIterator<T1> spillVals = new SpillingResettableMutableObjectIterator<T1>(
			in1, serializer1, this.memManager, this.taskContext.getIOManager(), this.memPagesForSpillingSide,
			this.taskContext.getOwningNepheleTask());
	this.spillIter = spillVals;
	
	final BlockResettableMutableObjectIterator<T2> blockVals = 
			new BlockResettableMutableObjectIterator<T2>(this.memManager, in2, serializer2, this.memPagesForBlockSide,
					this.taskContext.getOwningNepheleTask());
	this.blockIter = blockVals;
	
	T1 val1;
	final T1 val1Reuse = serializer1.createInstance();
	T1 val1Copy = serializer1.createInstance();
	T2 val2;
	final T2 val2Reuse = serializer2.createInstance();

	final CrossFunction<T1, T2, OT> crosser = this.taskContext.getStub();
	final Collector<OT> collector = this.taskContext.getOutputCollector();
	
	// for all blocks
	do {
		// for all values from the spilling side
		while (this.running && ((val1 = spillVals.next(val1Reuse)) != null)) {
			// for all values in the block
			while (this.running && ((val2 = blockVals.next(val2Reuse)) != null)) {
				val1Copy = serializer1.copy(val1, val1Copy);
				collector.collect(crosser.cross(val1Copy, val2));
				//crosser.cross(val1Copy, val2, collector);
			}
			blockVals.reset();
		}
		spillVals.reset();
	}
	while (this.running && blockVals.nextBlock());
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:48,代码来源:CrossDriver.java

示例7: testResettableIterator

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
/**
 * Tests the resettable iterator with too little memory, so that the data
 * has to be written to disk.
 */
@Test
public void testResettableIterator() {
	try {
		final AbstractInvokable memOwner = new DummyInvokable();

		// create the resettable Iterator
		SpillingResettableMutableObjectIterator<Record> iterator = new SpillingResettableMutableObjectIterator<Record>(
			this.reader, this.serializer, this.memman, this.ioman, 2, memOwner);

		// open the iterator
		iterator.open();
		
		// now test walking through the iterator
		int count = 0;
		Record target = new Record();
		while ((target = iterator.next(target)) != null) {
			Assert.assertEquals("In initial run, element " + count + " does not match expected value!", count++,
				target.getField(0, IntValue.class).getValue());
		}
		Assert.assertEquals("Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
		// test resetting the iterator a few times
		for (int j = 0; j < 10; ++j) {
			count = 0;
			iterator.reset();
			target = new Record();
			// now we should get the same results
			while ((target = iterator.next(target)) != null) {
				Assert.assertEquals("After reset nr. " + j + 1 + " element " + count
					+ " does not match expected value!", count++, target.getField(0, IntValue.class).getValue());
			}
			Assert.assertEquals("Too few elements were deserialzied after reset nr. " + j + 1 + "!", NUM_TESTRECORDS,
				count);
		}
		// close the iterator
		iterator.close();
	} catch (Exception ex)  {
		ex.printStackTrace();
		Assert.fail("Test encountered an exception.");
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:45,代码来源:SpillingResettableMutableObjectIteratorTest.java

示例8: testResettableIteratorInMemory

import org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator; //导入依赖的package包/类
/**
 * Tests the resettable iterator with enough memory so that all data is kept locally in memory.
 */
@Test
public void testResettableIteratorInMemory() {
	try {
		final AbstractInvokable memOwner = new DummyInvokable();

		// create the resettable Iterator
		SpillingResettableMutableObjectIterator<Record> iterator = new SpillingResettableMutableObjectIterator<Record>(
			this.reader, this.serializer, this.memman, this.ioman, 20, memOwner);
		
		// open the iterator
		iterator.open();

		// now test walking through the iterator
		int count = 0;
		Record target = new Record();
		while ((target = iterator.next(target)) != null) {
			Assert.assertEquals("In initial run, element " + count + " does not match expected value!", count++,
				target.getField(0, IntValue.class).getValue());
		}
		Assert.assertEquals("Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
		// test resetting the iterator a few times
		for (int j = 0; j < 10; ++j) {
			count = 0;
			iterator.reset();
			target = new Record();
			// now we should get the same results
			while ((target = iterator.next(target)) != null) {
				Assert.assertEquals("After reset nr. " + j + 1 + " element " + count
					+ " does not match expected value!", count++, target.getField(0, IntValue.class).getValue());
			}
			Assert.assertEquals("Too few elements were deserialzied after reset nr. " + j + 1 + "!", NUM_TESTRECORDS,
				count);
		}
		// close the iterator
		iterator.close();
	} catch (Exception ex)  {
		ex.printStackTrace();
		Assert.fail("Test encountered an exception.");
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:44,代码来源:SpillingResettableMutableObjectIteratorTest.java


注:本文中的org.apache.flink.runtime.operators.resettable.SpillingResettableMutableObjectIterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。