lincoln-lil commented on a change in pull request #17570:
URL: https://github.com/apache/flink/pull/17570#discussion_r737186362



##########
File path: 
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/rank/RetractableTopNFunction.java
##########
@@ -455,9 +464,18 @@ private boolean retractRecordWithoutRowNumber(
                     // sends the record if there is a record recently upgrades 
to Top-N
                     int index = Long.valueOf(rankEnd - nextRank).intValue();
                     List<RowData> inputs = dataState.get(key);
-                    RowData toAdd = inputs.get(index);
-                    collectInsert(out, toAdd);
-                    break;
+                    if (inputs == null) {
+                        // Skip the data if it's state is cleared because of 
state ttl.
+                        if (lenient) {
+                            LOG.warn(STATE_CLEARED_WARN_MSG);

Review comment:
       Good catch!SortedMap should sync with dataState when sortKey expired in 
dataState, can reduce some useless code path.
   
   Q: "Or shall we put treeMap and dataState in an atomic state object to avoid 
this problem once and for all."
   A: to my understanding,the treeMap valueState was introduced for the 
performance consideration(to avoid some state access which maybe costly). Of 
course, the inconsistenty problem will absolutely gone if merge the two state 
into one(cost is some performance regression). I tend to discuss this change 
separately, what do you think?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to