Skip to content

Commit 81bb127

Browse files
committed
Sink InitializeMultipartUpload to a later point
1 parent 510f5d3 commit 81bb127

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

extension/httpfs/include/s3fs.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class S3FileHandle : public HTTPFileHandle {
127127

128128
S3AuthParams auth_params;
129129
const S3ConfigParams config_params;
130+
bool initialized_multipart_upload {false};
130131

131132
public:
132133
void Close() override;

extension/httpfs/s3fs.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)