Skip to content

Fix/ingest df pool timeout - #385

Open
omirandadev wants to merge 4 commits into
masterfrom
fix/ingest-df-pool-timeout
Open

omirandadev wants to merge 4 commits into
masterfrom
fix/ingest-df-pool-timeout

Conversation

@omirandadev

Copy link
Copy Markdown
Collaborator

Streaming ingestion to Cassandra could stall with no error: foreachBatch
never returned. Two waits had no bound. ingest_df forked
SPARK_DRIVER_CORES - 1 workers (when cores > 2) and waited on
Pool.starmap() without a timeout, and the Cassandra store waited on write
callbacks without a deadline. Separately, sorted feature views wrote the
per-row TTL into the insert text, so almost every row prepared a new
statement.

This change:

  • Writes in-process with one writer by default. FEAST_INGEST_WORKERS > 1
    uses spawned workers bounded by FEAST_INGEST_POOL_TIMEOUT_SECONDS
    (default 600); on expiry the batch fails with IngestWorkerHungError.
  • Gives each Cassandra online_write_batch call a total deadline,
    write_timeout_seconds (default 120), after which it raises
    CassandraWriteTimeoutError. Writes already submitted may still land.
  • Keeps the driver's 10s request timeout when load_balancing is set and
    request_timeout is not (it was disabled), and applies request_timeout
    without load_balancing too.
  • Binds the TTL (USING TTL ?) so the sorted-view insert is prepared once.
    On Cassandra 4.1.4, 300 sorted rows with distinct event ages added 600
    prepared statements before and 2 after.
  • Makes the prepared-statement cache per instance and rejects a session
    reused from another process.
  • Treats both new errors as non-transient in the Spark Kafka processor, so
    the query fails instead of retrying inside the batch.

Behavior changes:

  • For every online store, ingest_df no longer forks based on
    SPARK_DRIVER_CORES. Jobs that relied on that parallelism should set
    FEAST_INGEST_WORKERS; spawned workers need an import-safe entry script.
  • The 120s write deadline also applies to batch materialization. Raise it if
    a healthy call can take longer.
  • request_timeout and write_timeout_seconds must be finite and positive.

Supersedes #379, which raises its write deadline to at least
request_timeout; here the deadline is a separate setting.

Testing: new unit tests for the ingest workers, the provider, Cassandra
write deadlines and logging, TTL binding, and the Spark processor.

🤖 Generated with Claude Code

…rker count

PassthroughProvider.ingest_df forks SPARK_DRIVER_CORES - 1 worker processes
per call and waited on Pool.starmap() with no timeout, so a worker that never
returns hung the caller forever with no error. In Spark streaming that is a
silent zombie: the foreachBatch never returns, the stream stops making
progress, and nothing is logged.

- Wait on the pool with starmap_async(...).get(timeout); on expiry terminate
  the pool and raise IngestWorkerHungError. Default 600s, overridable via
  FEAST_INGEST_POOL_TIMEOUT_SECONDS (<= 0 disables).
- Add FEAST_INGEST_WORKERS to set the worker count explicitly; 1 or 0 writes
  in-process with no fork. Unset keeps the legacy SPARK_DRIVER_CORES sizing.
  NUM_PROCESSES is still exported on every path for the Redis/Valkey stores.
- Name the new error so spark_kafka_processor._is_transient_error does not
  retry it; worker exceptions propagate unchanged.
The insert templates formatted the TTL into the statement text. Sorted
feature views compute the TTL per row (feature view TTL minus event age),
so nearly every row produced a new statement string. _get_cql_statement
caches prepared statements by text, so each one was a synchronous
session.prepare() round trip, a new entry in an unbounded client cache,
and a new prepared statement stored by Cassandra. On a busy cluster
this showed up as many stored statements that differ only in the TTL
literal (e.g. "USING TTL 7775991"), alongside heap and GC pressure.

- Use a bind marker (USING TTL ?) in both insert templates and bind the
  TTL as the last value. Bound 0 means no TTL, as the literal did.
- Prepare the sorted-view insert once per write call instead of per row.

On Cassandra 4.1.4, writing 300 sorted rows with distinct event ages
added 600 rows to system.prepared_statements before this change and 2
after. The stored TTLs are unchanged.
online_write_batch raises only the first write failure. Log every failed
write from the driver callback, with the table name and traceback, as the
previous callback did, so later failures are not lost.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants