redpanda-data / redpanda-data/connect

gcp_cloud_storage(input) lack of randomize Objects List

Open
#1,679 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement gcp inputs ux
Dominant language
Go
Stars
8.8k
Forks
969
Avg merge
1d 13h
Merged PRs (30d)
64

Description

Hi,

I have a pipeline that reads from a GCS bucket using the "gcp_cloud_storage" component and deletes the file after it has been acknowledged. This works well when using one thread/broker/pod, but when multiple threads are used, a race condition issue arises causing only one "worker" to successfully complete the operation while the others trigger an error.
"level=error msg="Failed to read message: storage: object doesn't exist"

The root cause of the issue is the Go package "cloud.google.com/go/storage" which returns objects in a lexicographical order. When multiple workers are used, they both do the listing and only one of them can successfully perform the operation and delete the file while the other receives an error that the file is missing.

I have implemented a cache in my pipeline to prevent duplication, but the input reads the file before it and triggers the error.

Possible solutions:

1)Use a workaround
2)Add a Randomize feature for gcp_cloud_storage component: By adding a preliminary rand.Shuffle for the pending objects list, every "worker" would have a different order. I am (more than) willing to create a pull request for this solution, if this is the right way

My pipeline is as follows:

input:
read_until:
restart_input: true
check: false # tried use errored() to recreate the pod - no go
input:
gcp_cloud_storage:
bucket: "$INPUT_Bucket"
prefix: "$INPUT_Bucket_Prefix"
codec: all-bytes
delete_objects: true

pipeline:
  processors:
  - bloblang: |
      meta file_name = meta("gcs_key").filepath_split().slice(-1).join("")
  - cache:
      resource: main_cache_redis
      operator: add
      key: '${!  meta("file_name") }' 
      value: '${!   meta("gcs_last_modified_unix") }'
  - mapping: root = if errored() { deleted() }

Thanks,
Almog

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the gcp_cloud_storage input and its use of cloud.google.com/go/storage; inspect how pending objects are listed and deleted. Reproduce the multi-worker behavior using the pipeline shown in the issue, with completion defined as workers receiving different object orders without the missing-object error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, google-cloud
Domain
cloud
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.