Skip to content

Commit 5733cc8

Browse files
authored
Fix flaky BigQuery file loads by safely handling concurrent mkdirs (#38426)
1 parent 8363afe commit 5733cc8

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

sdks/python/apache_beam/io/gcp/bigquery_file_loads.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ def _make_new_file_writer(
134134
directory = fs.FileSystems.join(file_prefix, destination)
135135

136136
if not fs.FileSystems.exists(directory):
137-
fs.FileSystems.mkdirs(directory)
137+
try:
138+
fs.FileSystems.mkdirs(directory)
139+
except IOError:
140+
# Concurrent workers may race to create the same directory.
141+
# Ignore the IOError if another worker successfully created it.
142+
if not fs.FileSystems.exists(directory):
143+
raise
138144

139145
file_name = str(uuid.uuid4())
140146
file_path = fs.FileSystems.join(file_prefix, destination, file_name)

0 commit comments

Comments
 (0)