summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClarisse Cheah <clarisse.cheah@mongodb.com>2023-02-06 00:48:26 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-06 01:25:32 +0000
commit362494af33a0c84570024452176bb7daa1d665d6 (patch)
tree6a96ea91d2f9851830d785be0c66d010bbd97e8d
parenta312fc233cd5598ecdae1ac5c369f81b0517a620 (diff)
downloadmongo-362494af33a0c84570024452176bb7daa1d665d6.tar.gz
Import wiredtiger: 82a6defadabfe59093df8346ebce7200a2ac55ff from branch mongodb-master
ref: a9a57414fd..82a6defada for: 6.3.0-rc0 WT-10546 Implement error handling for GCP Connection class
-rw-r--r--src/third_party/wiredtiger/dist/s_string.ok1
-rw-r--r--src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.cpp58
-rw-r--r--src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.h9
-rw-r--r--src/third_party/wiredtiger/import.data2
4 files changed, 47 insertions, 23 deletions
diff --git a/src/third_party/wiredtiger/dist/s_string.ok b/src/third_party/wiredtiger/dist/s_string.ok
index fa2c9e5f155..8f985636411 100644
--- a/src/third_party/wiredtiger/dist/s_string.ok
+++ b/src/third_party/wiredtiger/dist/s_string.ok
@@ -191,6 +191,7 @@ Fsync
Fuerst
GBR
GCC
+GCP
GF
GIDs
GLIBC
diff --git a/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.cpp b/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.cpp
index 1fdc85f84c6..beb09e3b665 100644
--- a/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.cpp
+++ b/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.cpp
@@ -56,9 +56,13 @@ gcp_connection::list_objects(std::vector<std::string> &objects, bool list_single
_gcp_client.ListObjects(_bucket_name, gcs::Prefix(_object_prefix))) {
// Check if the current object is accessible (object exists but the user does not have
// permissions to access)
- if (!object_metadata)
- std::cerr << "List failed: " << object_metadata->name() << "is not accessible"
- << std::endl;
+ if (!object_metadata) {
+ // This is an error, but is non-fatal. We call handle_error to print the error message
+ // and then continue listing objects.
+ handle_error(object_metadata.status(),
+ "List of '" + object_metadata->name() +
+ "' failed: " + object_metadata.status().message());
+ }
objects.push_back(object_metadata->name());
@@ -79,10 +83,9 @@ gcp_connection::put_object(const std::string &object_key, const std::string &fil
_gcp_client.UploadFile(file_path, _bucket_name, _object_prefix + object_key);
// Check if file has been successfully uploaded.
- if (!metadata) {
- std::cerr << "Upload failed: " << metadata.status() << std::endl;
- return -1;
- }
+ if (!metadata)
+ return handle_error(metadata.status(),
+ "Upload of '" + _object_prefix + object_key + "' failed: " + metadata.status().message());
return 0;
}
@@ -93,10 +96,10 @@ gcp_connection::delete_object(const std::string &object_key)
{
auto status = _gcp_client.DeleteObject(_bucket_name, _object_prefix + object_key);
- if (!status.ok()) {
- std::cerr << status.message() << std::endl;
- return -1;
- }
+ if (!status.ok())
+ return handle_error(
+ status, "Delete '" + _object_prefix + object_key + "' failed: " + status.message());
+
return 0;
}
@@ -109,34 +112,33 @@ gcp_connection::read_object(const std::string &object_key, int64_t offset, size_
// The object_exists function will check if the given object exists and print out any error
// messages.
- if (object_exists(object_key, exists, object_size) != 0) {
- return -1;
- }
+ int ret = object_exists(object_key, exists, object_size);
+ if (ret != 0)
+ return ret;
if (!exists) {
std::cerr << "Object '" << object_key << "' does not exist." << std::endl;
- return -1;
+ return ENOENT;
}
if (offset < 0) {
std::cerr << "Offset " << offset << " is invalid. The offset cannot be less than zero."
<< std::endl;
- return -1;
+ return EINVAL;
}
if (offset + len > object_size) {
std::cerr << "Length " << len << " plus offset " << offset
<< " must not exceed the object size " << object_size << "." << std::endl;
- return -1;
+ return EINVAL;
}
gcs::ObjectReadStream stream = _gcp_client.ReadObject(
_bucket_name, _object_prefix + object_key, gcs::ReadFromOffset(offset));
- if (stream.bad()) {
- std::cerr << stream.status().message() << std::endl;
- return -1;
- }
+ if (stream.bad())
+ return handle_error(stream.status(),
+ "Read '" + _object_prefix + object_key + "' failed: " + stream.status().message());
std::istreambuf_iterator<char> begin{stream}, end;
std::string buffer{begin, end};
@@ -169,7 +171,19 @@ gcp_connection::object_exists(const std::string &object_key, bool &exists, size_
return 0;
}
- std::cerr << object_key + ": " + metadata.status().message() << std::endl;
+ return handle_error(metadata.status(),
+ "Object exists check for '" + _object_prefix + object_key +
+ "' failed: " + metadata.status().message());
+}
+// Maps Google Cloud Status code to a system error number which is returned.
+// If a mapping cannot be found the Google Cloud Status code is printed and -1 is returned.
+int
+gcp_connection::handle_error(
+ const google::cloud::Status status, const std::string &error_message) const
+{
+ std::cerr << error_message << std::endl;
+ if (toErrno.find(status.code()) != toErrno.end())
+ return (toErrno.at(status.code()));
return -1;
}
diff --git a/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.h b/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.h
index 786c1f367d4..5815de5cf2a 100644
--- a/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.h
+++ b/src/third_party/wiredtiger/ext/storage_sources/gcp_store/gcp_connection.h
@@ -33,6 +33,14 @@
#include <string>
#include <vector>
+// Mapping between Google Status codes and corresponding system error numbers to be used by the GCP
+// connection methods to return system error numbers expected by the filesystem interface.
+static const std::map<google::cloud::StatusCode, int32_t> toErrno = {
+ {google::cloud::StatusCode::kUnknown, EAGAIN},
+ {google::cloud::StatusCode::kInvalidArgument, EINVAL},
+ {google::cloud::StatusCode::kNotFound, ENOENT},
+ {google::cloud::StatusCode::kAlreadyExists, EBUSY},
+ {google::cloud::StatusCode::kPermissionDenied, EACCES}};
class gcp_connection {
public:
gcp_connection(const std::string &bucket_name, const std::string &prefix);
@@ -41,6 +49,7 @@ class gcp_connection {
int delete_object(const std::string &object_key);
int object_exists(const std::string &object_key, bool &exists, size_t &object_size);
int read_object(const std::string &object_key, int64_t offset, size_t len, void *buf);
+ int handle_error(const google::cloud::Status status, const std::string &error_message) const;
~gcp_connection() = default;
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index 7f977ec4559..6fda752ac10 100644
--- a/src/third_party/wiredtiger/import.data
+++ b/src/third_party/wiredtiger/import.data
@@ -2,5 +2,5 @@
"vendor": "wiredtiger",
"github": "wiredtiger/wiredtiger.git",
"branch": "mongodb-master",
- "commit": "a9a57414fdd7d91ba80bd718d3b9649f4cbdeaa2"
+ "commit": "82a6defadabfe59093df8346ebce7200a2ac55ff"
}