forked from facebookresearch/fbpcf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support GCP Uploader (facebookresearch#274)
Summary: Pull Request resolved: facebookresearch#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: 296749559f9e8d287668b1c2961b02cff9ee56ac
- Loading branch information
1 parent
7c6d327
commit 74e793e
Showing
3 changed files
with
96 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,45 @@ | ||
/* | ||
* 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 <folly/logging/xlog.h> | ||
|
||
#include "fbpcf/exception/GcpException.h" | ||
#include "fbpcf/gcp/GCSUtil.h" | ||
#include "fbpcf/io/cloud_util/GCSFileUploader.h" | ||
|
||
namespace fbpcf::cloudio { | ||
static const std::string FILE_TYPE = "text/csv"; | ||
|
||
void GCSFileUploader::init() {} | ||
|
||
int32_t GCSFileUploader::upload(std::vector<char>& buf) { | ||
XLOG(INFO) << "Start resumable upload. "; | ||
const auto& ref = fbpcf::gcp::uriToObjectReference(filePath_); | ||
std::string bucket_ = ref.bucket; | ||
std::string object_ = ref.key; | ||
|
||
namespace gcs = ::google::cloud::storage; | ||
using ::google::cloud::StatusOr; | ||
std::string str(buf.begin(), buf.end()); | ||
|
||
StatusOr<gcs::ObjectMetadata> object_metadata = gcsClient_->InsertObject( | ||
bucket_, object_, str, gcs::ContentType(FILE_TYPE)); | ||
|
||
if (!object_metadata) { | ||
throw GcpException{ | ||
"Resumable upload failed: " + object_metadata.status().message()}; | ||
return 0; | ||
} | ||
XLOG(INFO) << " Resumable upload successful "; | ||
XLOG(INFO) << "Bucket: " << bucket_ << ", Object Name: " << object_; | ||
return str.size(); | ||
} | ||
|
||
int GCSFileUploader::complete() { | ||
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,35 @@ | ||
/* | ||
* 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_; | ||
}; | ||
|
||
} // namespace fbpcf::cloudio |