You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by di...@apache.org on 2022/04/07 11:03:49 UTC

[flink] branch release-1.14 updated: [FLINK-27108][python] Fix the state cache clean up logic

This is an automated email from the ASF dual-hosted git repository.

dianfu pushed a commit to branch release-1.14
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.14 by this push:
     new c372ddd3ea1 [FLINK-27108][python] Fix the state cache clean up logic
c372ddd3ea1 is described below

commit c372ddd3ea1d0239a9177cade2207bf9ba2b24a2
Author: Dian Fu <di...@apache.org>
AuthorDate: Thu Apr 7 15:29:02 2022 +0800

    [FLINK-27108][python] Fix the state cache clean up logic
    
    This closes #19386.
---
 flink-python/pyflink/fn_execution/state_impl.py              |  3 +++
 .../api/runners/python/beam/BeamPythonFunctionRunner.java    | 12 +++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/flink-python/pyflink/fn_execution/state_impl.py b/flink-python/pyflink/fn_execution/state_impl.py
index 459102c8886..9660ed60a61 100644
--- a/flink-python/pyflink/fn_execution/state_impl.py
+++ b/flink-python/pyflink/fn_execution/state_impl.py
@@ -87,6 +87,9 @@ class LRUCache(object):
     def __iter__(self):
         return iter(self._cache.values())
 
+    def __contains__(self, key):
+        return key in self._cache
+
 
 class SynchronousKvRuntimeState(InternalKvState, ABC):
     """
diff --git a/flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java b/flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java
index 59816877874..dfdfa90744b 100644
--- a/flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java
+++ b/flink-python/src/main/java/org/apache/flink/streaming/api/runners/python/beam/BeamPythonFunctionRunner.java
@@ -216,15 +216,17 @@ public abstract class BeamPythonFunctionRunner implements PythonFunctionRunner {
         PortablePipelineOptions portableOptions =
                 PipelineOptionsFactory.as(PortablePipelineOptions.class);
 
-        if (jobOptions.containsKey(PythonOptions.STATE_CACHE_SIZE.key())) {
+        int stateCacheSize =
+                Integer.parseInt(
+                        jobOptions.getOrDefault(
+                                PythonOptions.STATE_CACHE_SIZE.key(),
+                                PythonOptions.STATE_CACHE_SIZE.defaultValue().toString()));
+        if (stateCacheSize > 0) {
             portableOptions
                     .as(ExperimentalOptions.class)
                     .setExperiments(
                             Collections.singletonList(
-                                    ExperimentalOptions.STATE_CACHE_SIZE
-                                            + "="
-                                            + jobOptions.get(
-                                                    PythonOptions.STATE_CACHE_SIZE.key())));
+                                    ExperimentalOptions.STATE_CACHE_SIZE + "=" + stateCacheSize));
         }
 
         Struct pipelineOptions = PipelineOptionsTranslation.toProto(portableOptions);