@@ -366,7 +366,20 @@ Status ArrayDirectory::load() {
366366
367367 // Load (in parallel) the array metadata URIs
368368 tasks.emplace_back (resources_.get ().compute_tp ().execute ([&]() {
369- load_array_meta_uris ();
369+ float delay = 250 ;
370+ constexpr int max_retries = 25 ;
371+ for (int retry = 0 ; retry <= max_retries; ++retry) {
372+ if (load_array_meta_uris ()) {
373+ break ;
374+ }
375+ // Retry if some metadata files were still flushing to disk.
376+ std::this_thread::sleep_for (std::chrono::milliseconds (delay));
377+ resources_.get ().logger ()->info (
378+ " Encountered partially written array metadata while opening the "
379+ " array. Waiting {}ms and retrying." , delay);
380+ // Apply default REST backoff and retry up to 25 times.
381+ delay *= 1.25 ;
382+ }
370383 return Status::Ok ();
371384 }));
372385 }
@@ -832,14 +845,18 @@ ArrayDirectory::load_consolidated_commit_uris(
832845 return {Status::Ok (), uris, uris_set};
833846}
834847
835- void ArrayDirectory::load_array_meta_uris () {
848+ bool ArrayDirectory::load_array_meta_uris () {
836849 // Load the URIs in the array metadata directory
837850 std::vector<URI> array_meta_dir_uris;
838851 {
839852 auto timer_se = stats_->start_timer (" list_array_meta_uris" );
840853 array_meta_dir_uris =
841854 ls (uri_.join_path (constants::array_metadata_dir_name));
842855 }
856+ auto pred = [](const URI& uri) { return uri.to_string ().ends_with (" .tmp" ); };
857+ if (uri_.is_file () && std::ranges::any_of (array_meta_dir_uris, pred)) {
858+ return false ;
859+ }
843860
844861 // Compute array metadata URIs and vacuum URIs to vacuum. */
845862 auto && [st1, array_meta_uris_to_vacuum, array_meta_vac_uris_to_vacuum] =
@@ -855,6 +872,7 @@ void ArrayDirectory::load_array_meta_uris() {
855872 throw_if_not_ok (st2);
856873 array_meta_uris_ = std::move (array_meta_filtered_uris.value ());
857874 array_meta_dir_uris.clear ();
875+ return true ;
858876}
859877
860878void ArrayDirectory::load_array_schema_uris () {
0 commit comments