@@ -336,6 +336,8 @@ string S3FileSystem::InitializeMultipartUpload(S3FileHandle &file_handle) {
336336
337337 open_tag_pos += 10 ; // Skip open tag
338338
339+ file_handle.initialized_multipart_upload = true ;
340+
339341 return result.substr (open_tag_pos, close_tag_pos - open_tag_pos);
340342}
341343
@@ -437,6 +439,9 @@ void S3FileSystem::FlushBuffer(S3FileHandle &file_handle, shared_ptr<S3WriteBuff
437439#endif
438440 file_handle.uploads_in_progress ++;
439441 }
442+ if (file_handle.initialized_multipart_upload == false ) {
443+ file_handle.multipart_upload_id = InitializeMultipartUpload (file_handle);
444+ }
440445
441446#ifdef SAME_THREAD_UPLOAD
442447 UploadBuffer (file_handle, write_buffer);
@@ -459,6 +464,9 @@ void S3FileSystem::FlushAllBuffers(S3FileHandle &file_handle) {
459464 }
460465 file_handle.write_buffers_lock .unlock ();
461466
467+ if (file_handle.initialized_multipart_upload == false ) {
468+ file_handle.multipart_upload_id = InitializeMultipartUpload (file_handle);
469+ }
462470 // Flush all buffers that aren't already uploading
463471 for (auto &write_buffer : to_flush) {
464472 if (!write_buffer->uploading ) {
@@ -889,8 +897,6 @@ void S3FileHandle::Initialize(optional_ptr<FileOpener> opener) {
889897 part_size = ((minimum_part_size + Storage::DEFAULT_BLOCK_SIZE - 1 ) / Storage::DEFAULT_BLOCK_SIZE) *
890898 Storage::DEFAULT_BLOCK_SIZE;
891899 D_ASSERT (part_size * max_part_count >= config_params.max_file_size );
892-
893- multipart_upload_id = s3fs.InitializeMultipartUpload (*this );
894900 }
895901}
896902
0 commit comments