bpattarkine commented on issue #1431:
URL: https://github.com/apache/flink-agents/issues/1431#issuecomment-7358708168
**PyFlink checkpoint and restore passed on #1503** at `2d77ecc4`. I rebuilt
the Agents common and Flink 2.3 thin JARs from that revision and ran the test
in a local Flink 2.3.0 MiniCluster with Python 3.12.16 and Corretto 17.0.12 on
macOS arm64. Generic types were enabled. The job used PyFlink’s default
pickle-backed keys and a typed `(STRING, LONG)` output.
- Flink completed checkpoints with a Python action held on key `a` and a
second input queued for the same key. Key `b` continued to produce output
during that time.
- An injected failure restarted the job. Flink restored checkpoint 5, and
the REST API reported exactly one restore. The held action re-entered before
the test released it, and the queued action stayed blocked until then.
- Both keys produced the expected running counts `1, 2, 3`. The source
delivered the held and queued records once each, and the output fixture rejects
duplicate results. Flink also completed a new checkpoint after recovery.
Pytest reported **1 passed**. This verifies same-version recovery on the
PyFlink path at parallelism one. The Java operator tests in #1503 cover legacy
state migration and rescaling.
<details>
<summary>Reproduction with the existing checkpoint fixture</summary>
Build from the root of revision `2d77ecc4`. Use JDK 17, a Python 3.12
environment with `./python[test]` and `apache-flink==2.3.0`, and the
repository's `setuptools<82` build constraint for Apache Beam when building
from source.
```sh
mvn -B --no-transfer-progress -DskipTests -Dspotless.skip=true \
-pl dist/common,dist/flink-2.3 -am package
mkdir -p python/flink_agents/lib/common python/flink_agents/lib/flink-2.3
cp dist/common/target/flink-agents-dist-common-1.0-SNAPSHOT.jar \
python/flink_agents/lib/common/
cp dist/flink-2.3/target/flink-agents-dist-flink-2.3-1.0-SNAPSHOT-thin.jar \
python/flink_agents/lib/flink-2.3/
```
Apply the patch below from the repository root, then run the adapted test.
```sh
export PYTHONPATH=$(python -c 'import sysconfig;
print(sysconfig.get_paths()["purelib"])')
cd python
python -m pytest -s -vv \
flink_agents/e2e_tests/e2e_tests_integration/checkpoint_test.py::test_processing_keys_restore_after_failure
```
```diff
--- python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_test.py
+++ python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_test.py
@@ -25,12 +25,13 @@
import json
import socket
+import sys
import time
from pathlib import Path
from typing import Callable
from urllib.request import urlopen
-from pyflink.common import Configuration, Duration, WatermarkStrategy
+from pyflink.common import Configuration, Duration, Types, WatermarkStrategy
from pyflink.datastream import RuntimeExecutionMode,
StreamExecutionEnvironment
from pyflink.datastream.connectors.file_system import FileSource,
StreamFormat
from pyflink.java_gateway import get_gateway
@@ -50,7 +51,7 @@
time.sleep(0.1)
-def test_checkpoint_progress_while_idle_and_across_busy_keys(tmp_path:
Path) -> None:
+def test_processing_keys_restore_after_failure(tmp_path: Path) -> None:
"""Checkpoint suspended calls and queued inputs while another key
progresses."""
# The local web UI exposes actual completed-checkpoint metadata. An
empty
# source lets us establish a baseline before admitting the gated input.
@@ -63,12 +64,18 @@
config.set_string("execution.checkpointing.interval", "1s")
config.set_string("execution.checkpointing.timeout", "5s")
config.set_string("execution.checkpointing.dir", (tmp_path /
"cp").as_uri())
- config.set_string("restart-strategy.type", "none")
+ config.set_string("restart-strategy.type", "fixed-delay")
+ config.set_integer("restart-strategy.fixed-delay.attempts", 1)
+ config.set_string("restart-strategy.fixed-delay.delay", "100 ms")
+ config.set_string("jobmanager.execution.failover-strategy", "full")
+ config.set_boolean("pipeline.generic-types", True)
+ config.set_integer("python.fn-execution.bundle.size", 1)
config.set_string("state.backend.type", "hashmap")
j_env =
get_gateway().jvm.org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
env = StreamExecutionEnvironment(
j_env.createLocalEnvironmentWithWebUI(config._j_configuration)
)
+ env.set_python_executable(sys.executable)
env.set_runtime_mode(RuntimeExecutionMode.STREAMING)
env.set_parallelism(1)
env.get_checkpoint_config().set_tolerable_checkpoint_failure_number(10)
@@ -81,10 +88,20 @@
.monitor_continuously(Duration.of_millis(100))
.build()
)
- # Agents' Python input boundary expects pickle, whereas FileSource emits
- # native Java strings. Use the default Python map output serializer.
- inputs = env.from_source(source, WatermarkStrategy.no_watermarks(),
"trigger").map(
- mark_submitted
+ # Use the default pickle-backed Python output type at the Agents
boundary.
+ def trigger(value: str):
+ if value != "FAIL":
+ with (Path(value) / "source-deliveries").open("a",
encoding="utf-8") as log:
+ log.write("delivered\n")
+ yield mark_submitted(value)
+ return
+ marker = tmp_path / "injected-failure"
+ if not marker.exists():
+ marker.touch()
+ raise RuntimeError("Injected failure after checkpoint")
+
+ inputs = env.from_source(source, WatermarkStrategy.no_watermarks(),
"trigger").flat_map(
+ trigger
)
agents = AgentsExecutionEnvironment.get_execution_environment(env=env)
(
@@ -92,8 +109,8 @@
inputs, key_selector=lambda value: Path(value).parent.name
)
.apply(CheckpointAgent())
- .to_datastream()
- .map(record_output)
+ .to_datastream(Types.TUPLE([Types.STRING(), Types.LONG()]))
+ .map(record_output, output_type=Types.STRING())
.print()
)
job = env.execute_async("python-checkpoint-e2e")
@@ -128,10 +145,13 @@
await_condition(lambda: (record / "output").exists(), "output not
received")
assert (record / "output").read_text(encoding="utf-8") == str(count)
- def completed_after(timestamp: int) -> list[dict]:
+ def checkpoint_stats() -> dict:
check_job()
with urlopen(url, timeout=5) as response:
- stats = json.load(response)
+ return json.load(response)
+
+ def completed_after(timestamp: int) -> list[dict]:
+ stats = checkpoint_stats()
return [
cp
for cp in stats["history"]
@@ -140,6 +160,7 @@
try:
_await(lambda: bool(completed_after(0)), "baseline checkpoint did
not complete")
+ expect_output(send("a", "seed"), 1)
held = send("a", "held", blocked=True)
await_condition(lambda: (held / "entered").exists(), "async call
did not start")
queued = send("a", "queued")
@@ -152,9 +173,23 @@
)
assert not (held / "output").exists()
assert not (queued / "entered").exists()
+ (held / "entered").unlink()
+ (input_dir / "fail").write_text("FAIL\n", encoding="utf-8")
+ await_condition(lambda: (tmp_path / "injected-failure").exists(),
"failure was not injected")
+ await_condition(
+ lambda: checkpoint_stats()["counts"]["restored"] == 1,
+ "checkpoint was not restored",
+ )
+ await_condition(lambda: (held / "entered").exists(), "held action
did not resume")
+ assert not (held / "output").exists()
+ assert not (queued / "entered").exists()
(held / "release").touch()
- expect_output(held, 1)
- expect_output(queued, 2)
+ expect_output(held, 2)
+ expect_output(queued, 3)
+ expect_output(send("b", "after-restore"), 3)
+ for record in (held, queued):
+ assert (record / "source-deliveries").read_text() ==
"delivered\n"
+ print("Checkpoint restores: 1; key a counts: 1, 2, 3; key b counts:
1, 2, 3")
finished_at = time.time_ns() // 1_000_000
_await(
lambda: bool(completed_after(finished_at)),
diff --git
a/python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_agent.py
b/python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_agent.py
index 2bbe942e..cc12bfce 100644
--- a/python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_agent.py
+++ b/python/flink_agents/e2e_tests/e2e_tests_integration/checkpoint_agent.py
@@ -30,9 +30,15 @@ from flink_agents.api.runner_context import RunnerContext
def wait_for_release(directory: str) -> int:
"""Simulate slow external I/O until the test explicitly releases the
call."""
gate = Path(directory)
+ failure_marker = gate.parents[2] / "injected-failure"
+ restored_attempt = failure_marker.exists()
(gate / "entered").touch()
deadline = time.monotonic() + 90
while not (gate / "release").exists():
+ if not restored_attempt and failure_marker.exists():
+ # A running native thread-pool call must exit before teardown
can finish.
+ # Only the new attempt waits for the release marker after
failover.
+ raise RuntimeError("End the original attempt during failover")
if time.monotonic() >= deadline:
msg = "Checkpoint E2E did not release the async call"
raise TimeoutError(msg)
```
</details>
--
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]