-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Pull Request resolved: #274 Implementing Resumable Uploads for GCS as Multipart upload using a cpp library is currently not available using GCP. Changed earlier implementation of using S3 AWS multipart to now using GCP's resumable upload Differential Revision: D37804966 fbshipit-source-id: 3a9af0f03bb9ac38b859bd05d6e169158dbaaf0d
- Loading branch information
1 parent
84fb595
commit 01b63b8
Showing
3 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "fbpcf/io/cloud_util/GCSFileUploader.h" | ||
|
||
#include <folly/logging/xlog.h> | ||
|
||
#include "fbpcf/exception/GcpException.h" | ||
#include "fbpcf/gcp/GCSUtil.h" | ||
#include "gen/aab7ed39/third-party/google-cloud-cpp/google/cloud/storage/google_cloud_cpp_storage#header-mode-symlink-tree-with-header-map,headers/google/cloud/storage/upload_options.h" | ||
|
||
namespace fbpcf::cloudio { | ||
static const std::string FILE_TYPE = "text/csv"; | ||
|
||
void GCSFileUploader::init() { | ||
XLOG(INFO) << "Start resumable upload. "; | ||
const auto& ref = fbpcf::gcp::uriToObjectReference(filePath_); | ||
std::string bucket_ = ref.bucket; | ||
std::string object_ = ref.key; | ||
XLOG(INFO) << "Bucket: " << bucket_ << ", Object Name: " << object_; | ||
namespace gcs = ::google::cloud::storage; | ||
using ::google::cloud::StatusOr; | ||
stream_ = | ||
gcsClient_->WriteObject(bucket_, object_, gcs::ContentType(FILE_TYPE)); | ||
} | ||
|
||
int32_t GCSFileUploader::upload(std::vector<char>& buf) { | ||
stream_.write(buf.data(), buf.size()); | ||
|
||
XLOG(INFO) << " Resumable upload chunk successful. "; | ||
XLOG(INFO) << " Bytes written: " << buf.size(); | ||
|
||
return buf.size(); | ||
} | ||
|
||
int GCSFileUploader::complete() { | ||
stream_.Close(); | ||
namespace gcs = ::google::cloud::storage; | ||
using ::google::cloud::StatusOr; | ||
StatusOr<gcs::ObjectMetadata> metadata = std::move(stream_).metadata(); | ||
if (!metadata) { | ||
XLOG(ERR) << "Failed to close. Message: " << metadata.status().message(); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
} // namespace fbpcf::cloudio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include <google/cloud/storage/client.h> | ||
#include "fbpcf/io/cloud_util/IFileUploader.h" | ||
|
||
namespace fbpcf::cloudio { | ||
class GCSFileUploader : public IFileUploader { | ||
public: | ||
explicit GCSFileUploader( | ||
std::shared_ptr<google::cloud::storage::Client> gcsClient, | ||
const std::string& filePath) | ||
: gcsClient_{std::move(gcsClient)}, filePath_{filePath} { | ||
init(); | ||
} | ||
int upload(std::vector<char>& buf) override; | ||
int complete() override; | ||
|
||
private: | ||
void init() override; | ||
|
||
std::shared_ptr<google::cloud::storage::Client> gcsClient_; | ||
const std::string filePath_; | ||
google::cloud::storage::ObjectWriteStream stream_; | ||
}; | ||
|
||
} // namespace fbpcf::cloudio |