Apache NiFi跨GCS桶传输文件时出现丢失问题:是否由竞态条件导致?
Great question—let’s break this down step by step, starting with how NiFi’s ListGCSBucket processor behaves by default, since that’s the core of your concern.
Default Behavior of ListGCSBucket
By default, ListGCSBucket uses a bookmarking mechanism (or timestamp-based state) to track which files it’s already processed. Here’s the play-by-play:
- When the processor starts a run, it first captures a "cutoff timestamp" (the exact moment the run begins).
- It scans BucketA for all files where the
last modifiedtime falls before this cutoff timestamp and hasn’t been processed in prior runs. - After the run completes successfully, it updates its bookmark to this cutoff timestamp—so the next scheduled run will only target files modified after that time.
Your Race Condition Scenario: Will It Cause Permanent Loss?
The short answer: No, not with default configuration. Here’s why:
If a file is uploaded to BucketA while ListGCSBucket is mid-scan, its last modified time will be later than the current run’s cutoff timestamp. That means it won’t be picked up in this scan—but it will absolutely be included in the next scheduled run (since the next run’s cutoff will be after the file was uploaded). The bookmark system ensures no files are permanently missed as long as the processor runs consistently.
So Why Are Files Missing?
If files aren’t showing up in BucketB, the issue is almost certainly not a race condition in the listing step. Here are the most likely culprits to investigate:
PutGCSObjectfailures: The file might have been listed and fetched, but failed to upload to BucketB (e.g., permission errors, network blips, quota limits). Check the processor’s error logs, and verify you’ve configured retry policies or connected a "failure" relationship to handle these cases instead of dropping files.- Misconfigured
ListGCSBucket:- If you disabled bookmarking (not the default), the processor might skip files if it’s set to only list files newer than a fixed time, or if your filter rules (filename patterns, file sizes) exclude the missing files.
- Double-check the processor’s "Filter Attributes" and "Filename Filter" settings to rule out accidental exclusions.
- GCS metadata delays: Occasionally, GCS takes a few seconds to index new files after upload. If a file is uploaded right after
ListGCSBucketstarts a run, it might not show up in that scan—but it will be picked up in the next 30-second run. - File deletion in BucketA: If the original file is deleted from BucketA before
FetchGCSObjectcan retrieve it, the processor won’t be able to process it. - Provenance data gaps: Use NiFi’s Provenance Explorer to search for the missing filenames—this will show exactly where in the flow they were lost (e.g., never listed, fetched but not uploaded).
Quick Troubleshooting Steps
- Check the
ListGCSBucketprocessor’s State tab to confirm the bookmark is advancing correctly (it should reflect the timestamp of the last successful run). - Review the
PutGCSObjectprocessor’s metrics (e.g., "Sent" vs. "Failed" counts) and error logs for clues about upload failures. - Trace missing files via NiFi’s Provenance UI to pinpoint the exact step where they dropped out of the flow.
内容的提问来源于stack exchange,提问作者Shailesh Jain

