问题
Apache flink - job simple windowing problem - java.lang.RuntimeException: segment has been freed
Hi,
I am a flink newbee and in my job, I am trying to use windowing to simply aggregate elements to enable delayed processing:
src = src.timeWindowAll(Time.milliseconds(1000)).process(new BaseDelayingProcessAllWindowFunctionImpl());
processwindow function simply collects input elements:
public class BaseDelayingProcessAllWindowFunction<IN> extends ProcessAllWindowFunction<IN, IN, TimeWindow> {
private static final long serialVersionUID = 1L;
protected Logger logger;
public BaseDelayingProcessAllWindowFunction() {
logger = LoggerFactory.getLogger(getClass());
}
@Override
public void process(ProcessAllWindowFunction<IN, IN, TimeWindow>.Context context, Iterable<IN> elements, Collector<IN> out) throws Exception {
for (IN in : elements) {
out.collect(in);
}
}
}
The problem is, I am having below error in my local debug process (starting the job from eclipse) :
[2019-01-18 14:38:18,753] INFO Running job on local embedded Flink mini cluster (org.apache.flink.streaming.api.environment.LocalStreamEnvironment:114)
[2019-01-18 14:38:30,825] INFO Source: dataSource -> Flat Map (1/1) (3677b50300c3c432e862af413796ee5d) switched from RUNNING to FAILED. (org.apache.flink.runtime.taskmanager.Task:940)
TimerException{org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator}
at org.apache.flink.streaming.runtime.tasks.SystemProcessingTimeService$TriggerTask.run(SystemProcessingTimeService.java:288)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator
at org.apache.flink.streaming.runtime.tasks.OperatorChain$ChainingOutput.emitWatermark(OperatorChain.java:483)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.emitWatermark(AbstractStreamOperator.java:691)
at org.apache.flink.streaming.api.operators.StreamSourceContexts$AutomaticWatermarkContext$WatermarkEmittingTask.onProcessingTime(StreamSourceContexts.java:264)
at org.apache.flink.streaming.runtime.tasks.SystemProcessingTimeService$TriggerTask.run(SystemProcessingTimeService.java:285)
... 7 more
Caused by: java.lang.RuntimeException: segment has been freed
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.emitWatermark(RecordWriterOutput.java:123)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator$CountingOutput.emitWatermark(AbstractStreamOperator.java:691)
at org.apache.flink.streaming.api.operators.AbstractStreamOperator.processWatermark(AbstractStreamOperator.java:759)
at org.apache.flink.streaming.runtime.tasks.OperatorChain$ChainingOutput.emitWatermark(OperatorChain.java:479)
... 10 more
Caused by: java.lang.IllegalStateException: segment has been freed
at org.apache.flink.core.memory.HybridMemorySegment.put(HybridMemorySegment.java:228)
at org.apache.flink.core.memory.HybridMemorySegment.put(HybridMemorySegment.java:381)
at org.apache.flink.runtime.io.network.buffer.BufferBuilder.append(BufferBuilder.java:85)
at org.apache.flink.runtime.io.network.api.serialization.SpanningRecordSerializer.addRecord(SpanningRecordSerializer.java:97)
at org.apache.flink.runtime.io.network.api.writer.RecordWriter.sendToTarget(RecordWriter.java:131)
at org.apache.flink.runtime.io.network.api.writer.RecordWriter.broadcastEmit(RecordWriter.java:117)
at org.apache.flink.streaming.runtime.io.StreamRecordWriter.broadcastEmit(StreamRecordWriter.java:87)
at org.apache.flink.streaming.runtime.io.RecordWriterOutput.emitWatermark(RecordWriterOutput.java:121)
... 13 more
Google search made me think that this error relates to OOM errros so I tried the following (all failed):
I have tried changing defaultLocalParallelism from 8 to 1 by hack:
private static int defaultLocalParallelism = Runtime.getRuntime().availableProcessors();
public static LocalStreamEnvironment createLocalEnvironment() {
return createLocalEnvironment(defaultLocalParallelism);
}
also tried increasing memory (-Xms4096m -Xmx4096m -Xmn512m) and also tried reducing window size to 10 ms but none of the above helped..
Please advise
UPDATE
After comments, in order to narrow down the problem, I simplified the complex job to a single print statement as below but still having the same error:
DataStream<String> dataStream = getSource(KAFKA_DATA_SOURCE_NAME).getDataStream();
SingleOutputStreamOperator<String> out2 = dataStream.timeWindowAll(Time.milliseconds(10)).process(new StringDelayingProcessAllWindowFunction());
out2.print();
statement as below but still having the same error.
There is no implementation in process all window function sub class.
public class StringDelayingProcessAllWindowFunction extends BaseDelayingProcessAllWindowFunction<String> {
private static final long serialVersionUID = 1L;
}
Is there any special setting for mini cluster or any other setting for windowing?
UPDATE 2
I confirmed that, this ugly problem occurs only in mini cluster environment:
Running job on local embedded Flink mini cluster (org.apache.flink.streaming.api.environment.LocalStreamEnvironment:114)
When I submitted the same job on test cluster this simple job did not receive error. So the question is how can I run windowing in mini cluster. Trying with 32 bit jdk did not help either..
来源:https://stackoverflow.com/questions/54255101/apache-flink-job-simple-windowing-problem-java-lang-runtimeexception-segmen