MCPcopy Create free account
hub / github.com/apache/arrow / Upload

Method Upload

cpp/src/arrow/filesystem/s3fs.cc:2003–2059  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2001
2002 template <typename RequestType, typename OutcomeType>
2003 Status Upload(
2004 RequestType&& req,
2005 UploadResultCallbackFunction<RequestType, OutcomeType> sync_result_callback,
2006 UploadResultCallbackFunction<RequestType, OutcomeType> async_result_callback,
2007 const void* data, int64_t nbytes, std::shared_ptr<Buffer> owned_buffer = nullptr) {
2008 req.SetBucket(ToAwsString(path_.bucket));
2009 req.SetKey(ToAwsString(path_.key));
2010 req.SetContentLength(nbytes);
2011 RETURN_NOT_OK(SetSSECustomerKey(&req, sse_customer_key_));
2012
2013 if (!background_writes_) {
2014 // GH-45304: avoid setting a body stream if length is 0.
2015 // This workaround can be removed once we require AWS SDK 1.11.489 or later.
2016 if (nbytes != 0) {
2017 req.SetBody(std::make_shared<StringViewStream>(data, nbytes));
2018 }
2019
2020 ARROW_ASSIGN_OR_RAISE(auto outcome, TriggerUploadRequest(req, holder_));
2021
2022 RETURN_NOT_OK(sync_result_callback(req, upload_state_, part_number_, outcome));
2023 } else {
2024 // (GH-45304: avoid setting a body stream if length is 0, see above)
2025 if (nbytes != 0) {
2026 // If the data isn't owned, make an immutable copy for the lifetime of the closure
2027 if (owned_buffer == nullptr) {
2028 ARROW_ASSIGN_OR_RAISE(owned_buffer, AllocateBuffer(nbytes, io_context_.pool()));
2029 memcpy(owned_buffer->mutable_data(), data, nbytes);
2030 } else {
2031 DCHECK_EQ(data, owned_buffer->data());
2032 DCHECK_EQ(nbytes, owned_buffer->size());
2033 }
2034 req.SetBody(std::make_shared<StringViewStream>(owned_buffer->data(),
2035 owned_buffer->size()));
2036 }
2037
2038 {
2039 std::unique_lock<std::mutex> lock(upload_state_->mutex);
2040 if (upload_state_->uploads_in_progress++ == 0) {
2041 upload_state_->pending_uploads_completed = Future<>::Make();
2042 }
2043 }
2044
2045 // The closure keeps the buffer and the upload state alive
2046 auto deferred = [owned_buffer, holder = holder_, req = std::move(req),
2047 state = upload_state_, async_result_callback,
2048 part_number = part_number_]() mutable -> Status {
2049 ARROW_ASSIGN_OR_RAISE(auto outcome, TriggerUploadRequest(req, holder));
2050
2051 return async_result_callback(req, state, part_number, outcome);
2052 };
2053 RETURN_NOT_OK(SubmitIO(io_context_, std::move(deferred)));
2054 }
2055
2056 ++part_number_;
2057
2058 return Status::OK();
2059 }
2060

Callers

nothing calls this directly

Calls 11

ToAwsStringFunction · 0.85
SetSSECustomerKeyFunction · 0.85
SubmitIOFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.50
AllocateBufferFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50
poolMethod · 0.45
mutable_dataMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected