Skip to content

Stream has been finalized and cannot be appended during Flink job recovery after task manager restart #235

Description

@lpvcpp

Description

When running a Flink streaming job using the BigQuery Sink with DeliveryGuarantee.EXACTLY_ONCE, the job fails during recovery if a task manager (pod) shuts down and restarts. The connector attempts to append to a BigQuery stream that has already been finalized, resulting in an INVALID_ARGUMENT exception. This leads to repeated job failures after restarts.

This issue occurs in a distributed setup (e.g., 4 task managers), where Flink restores state from checkpoints, but the stored stream ID is no longer appendable. The connector does not automatically create a new stream during recovery, causing the commit to fail.

Steps to Reproduce

  1. Set up a Flink job with the BigQuery Sink:
    • Use BigQuerySinkConfig with DeliveryGuarantee.EXACTLY_ONCE.
    • Parallelism >1 (e.g., 4 task managers).
    • Sink writes to a partitioned table (e.g., on "etl_date" field).
    • Example config snippet:
      DeliveryGuarantee deliveryGuarantee = DeliveryGuarantee.EXACTLY_ONCE;
      BigQuerySinkConfig<GenericRecord> sinkConfig = BigQuerySinkConfig.<GenericRecord>newBuilder()
          .connectOptions(BigQueryConnectOptions.builder()
              .project("xxx")
              .dataset("xxx")
              .table("xxx")
              .build())
          .deliveryGuarantee(deliveryGuarantee)
          .serializer(new AvroToProtoSerializer())
          .enableTableCreation(true)
          .partitionField("etl_date")
          .partitionExpirationMillis(45L * 24L * 60L * 60L * 1000L)
          .build();
  2. Run the job in a cluster (e.g., Google Cloud Dataproc or Kubernetes) processing unbounded data (e.g., from Kafka).
  3. Simulate a failure: Shut down one task manager pod (e.g., kill pod in K8s).
  4. Flink attempts to recover from checkpoint, but the commit fails with the error.

Environment

  • Flink version: 1.19.1
  • Connector version: 1.11
  • Java version: 17
  • Deployment: Kubernetes
  • BigQuery details: Writing to table (time-partitioned on "etl_date" as string "yyyy-MM-dd").
  • Checkpoint interval: [e.g., 1 minute]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions