Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

Clear Flink state with window closing

Here's my code. My question is as follows

  • Is it correct to clear state in this way?

  • Is this the correct way to use keyBy ?

    //There are 1000,000 + storeId

     orderStream.keyBy(Order::getStoreId)
         .window(TumblingEventTimeWindows.of(Time.days(1), Time.hours(16)))
         .trigger(ContinuousEventTimeTrigger.of(Time.seconds(1)))
         .evictor(TimeEvictor.of(Time.seconds(0), true))
         .process(new ProcessWindowFunction<Order, Object, Long, TimeWindow>() {
             MapState<Long, Long> storeCountState;
             @Override
             public void process(Long storeId, Context context, Iterable<Order> elements, Collector<Object> out) throws Exception {
                 long sum = 0L;
                 for (Order element : elements) {
                     sum++;
                 }
                 storeCountState.put(storeId, storeCountState.get(storeId) + sum);
             }
    
             @Override
             public void open(Configuration parameters) throws Exception {
                 super.open(parameters);
                 MapStateDescriptor<Long, Long> mapStateDescriptor = new MapStateDescriptor();
                 storeCountState = getRuntimeContext().getMapState(mapStateDescriptor);
             }
    
             @Override
             public void close() throws Exception {
                 super.close();
                 // I clear state when each window close 
                 storeCountState.clear();
             }
         })
         .addSink(new PrintSinkFunction<>());
    
question from:https://stackoverflow.com/questions/65626414/clear-flink-state-with-window-closing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...