Skip to content

Commit feea4d3

Browse files
committed
set autocommit=false as default for ZonalFile
1 parent 64f2513 commit feea4d3

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

gcsfs/extended_gcsfs.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _open(
117117
acl=None,
118118
consistency=None,
119119
metadata=None,
120-
autocommit=True,
120+
autocommit=None,
121121
fixed_key_metadata=None,
122122
generation=None,
123123
**kwargs,
@@ -126,7 +126,16 @@ def _open(
126126
Open a file.
127127
"""
128128
bucket, _, _ = self.split_path(path)
129+
130+
# Determine the final autocommit value based on bucket type. For zonal
131+
# buckets, default autocommit is False; for others, it is True.
132+
final_autocommit = autocommit
129133
bucket_type = self._sync_lookup_bucket_type(bucket)
134+
if autocommit is None:
135+
if bucket_type == BucketType.ZONAL_HIERARCHICAL:
136+
final_autocommit = False
137+
else:
138+
final_autocommit = True
130139
return gcs_file_types[bucket_type](
131140
self,
132141
path,
@@ -136,7 +145,7 @@ def _open(
136145
consistency=consistency,
137146
metadata=metadata,
138147
acl=acl,
139-
autocommit=autocommit,
148+
autocommit=final_autocommit,
140149
fixed_key_metadata=fixed_key_metadata,
141150
generation=generation,
142151
**kwargs,

gcsfs/zonal_file.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@
1010

1111
logger = logging.getLogger("gcsfs.zonal_file")
1212

13+
DEFAULT_BLOCK_SIZE = 5 * 2**20
14+
1315

1416
class ZonalFile(GCSFile):
1517
"""
1618
ZonalFile is subclass of GCSFile and handles data operations from
1719
Zonal buckets only using a high-performance gRPC path.
1820
"""
1921

20-
def __init__(self, *args, **kwargs):
22+
def __init__(
23+
self,
24+
gcsfs,
25+
path,
26+
mode="rb",
27+
block_size=DEFAULT_BLOCK_SIZE,
28+
autocommit=False,
29+
*args,
30+
**kwargs,
31+
):
2132
"""
2233
Initializes the ZonalFile object.
2334
"""
24-
super().__init__(*args, **kwargs)
35+
super().__init__(gcsfs, path, mode, block_size, autocommit, *args, **kwargs)
2536
self.mrd = None
2637
if "r" in self.mode:
2738
self.mrd = asyn.sync(
@@ -37,7 +48,7 @@ def __init__(self, *args, **kwargs):
3748
)
3849
else:
3950
raise NotImplementedError(
40-
"Only read operations are currently supported for Zonal buckets."
51+
"Only 'r' and 'w' modes are currently supported for Zonal buckets."
4152
)
4253

4354
async def _init_mrd(self, bucket_name, object_name, generation=None):

0 commit comments

Comments
 (0)