@@ -138,40 +138,14 @@ def read_blob(
138138 OSError:
139139 If an I/O error occurs while reading the file.
140140 """
141- file_descriptor = None
142- _map = None
143141 try :
144142 file_descriptor = os .open (blob_name , os .O_RDONLY | os .O_BINARY )
145- # on platforms that support it give the kernel a hint about access pattern
146143 if hasattr (os , "posix_fadvise" ):
147- # sequential access is the common pattern for dataset reads
148- try :
149- os .posix_fadvise (file_descriptor , 0 , 0 , os .POSIX_FADV_SEQUENTIAL )
150- except OSError :
151- # fallback to WILLNEED if SEQUENTIAL is not allowed
152- with contextlib .suppress (Exception ):
153- os .posix_fadvise (file_descriptor , 0 , 0 , os .POSIX_FADV_WILLNEED )
154-
144+ os .posix_fadvise (file_descriptor , 0 , 0 , os .POSIX_FADV_WILLNEED )
155145 size = os .fstat (file_descriptor ).st_size
156146 _map = mmap .mmap (file_descriptor , length = size , ** mmap_config )
157-
158- # On Linux advise the kernel that access will be sequential to improve readahead
159- if IS_LINUX :
160- # if anything goes wrong, ignore
161- with contextlib .suppress (Exception ):
162- libc = ctypes .CDLL ("libc.so.6" )
163- # MADV_SEQUENTIAL is 2 on Linux, but don't hardcode if available
164- MADV_SEQUENTIAL = 2
165- addr = ctypes .c_void_p (ctypes .addressof (ctypes .c_char .from_buffer (_map )))
166- length = ctypes .c_size_t (size )
167- libc .madvise (addr , length , MADV_SEQUENTIAL )
168-
169- # pass a memoryview of the mmap to decoders - this makes intent explicit
170- # and lets decoders that can accept memoryviews avoid extra copies
171- buffer = memoryview (_map )
172-
173147 result = decoder (
174- buffer ,
148+ _map ,
175149 just_schema = just_schema ,
176150 projection = projection ,
177151 selection = selection ,
@@ -181,20 +155,14 @@ def read_blob(
181155
182156 if not just_schema :
183157 stats = self .read_blob_statistics (
184- blob_name = blob_name , blob_bytes = buffer , decoder = decoder
158+ blob_name = blob_name , blob_bytes = _map , decoder = decoder
185159 )
186160 if self .relation_statistics is None :
187161 self .relation_statistics = stats
188162
189163 return result
190164 finally :
191- # Ensure mmap is closed before closing the file descriptor
192- with contextlib .suppress (Exception ):
193- if _map is not None :
194- _map .close ()
195- with contextlib .suppress (Exception ):
196- if file_descriptor is not None :
197- os .close (file_descriptor )
165+ os .close (file_descriptor )
198166
199167 @single_item_cache
200168 def get_list_of_blob_names (self , * , prefix : str ) -> List [str ]:
0 commit comments