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

Method DoWrite

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

Source from the content-addressed store, hash-verified

1889 }
1890
1891 Status DoWrite(const void* data, int64_t nbytes,
1892 std::shared_ptr<Buffer> owned_buffer = nullptr) {
1893 if (closed_) {
1894 return Status::Invalid("Operation on closed stream");
1895 }
1896
1897 const int8_t* data_ptr = reinterpret_cast<const int8_t*>(data);
1898 auto advance_ptr = [&data_ptr, &nbytes](const int64_t offset) {
1899 data_ptr += offset;
1900 nbytes -= offset;
1901 };
1902
1903 // Handle case where we have some bytes buffered from prior calls.
1904 if (current_part_size_ > 0) {
1905 // Try to fill current buffer
1906 const int64_t to_copy = std::min(nbytes, kPartUploadSize - current_part_size_);
1907 RETURN_NOT_OK(current_part_->Write(data_ptr, to_copy));
1908 current_part_size_ += to_copy;
1909 advance_ptr(to_copy);
1910 pos_ += to_copy;
1911
1912 // If buffer isn't full, break
1913 if (current_part_size_ < kPartUploadSize) {
1914 return Status::OK();
1915 }
1916
1917 // Upload current buffer. We're only reaching this point if we have accumulated
1918 // enough data to upload.
1919 RETURN_NOT_OK(CommitCurrentPart());
1920 }
1921
1922 // We can upload chunks without copying them into a buffer
1923 while (nbytes >= kPartUploadSize) {
1924 RETURN_NOT_OK(UploadPart(data_ptr, kPartUploadSize));
1925 advance_ptr(kPartUploadSize);
1926 pos_ += kPartUploadSize;
1927 }
1928
1929 // Buffer remaining bytes
1930 if (nbytes > 0) {
1931 current_part_size_ = nbytes;
1932 ARROW_ASSIGN_OR_RAISE(current_part_, io::BufferOutputStream::Create(
1933 kPartUploadSize, io_context_.pool()));
1934 RETURN_NOT_OK(current_part_->Write(data_ptr, current_part_size_));
1935 pos_ += current_part_size_;
1936 }
1937
1938 return Status::OK();
1939 }
1940
1941 Status Flush() override {
1942 auto fut = FlushAsync();

Callers

nothing calls this directly

Calls 5

InvalidFunction · 0.50
OKFunction · 0.50
ARROW_ASSIGN_OR_RAISEFunction · 0.50
WriteMethod · 0.45
poolMethod · 0.45

Tested by

no test coverage detected