summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp
diff options
context:
space:
mode:
authorSiddhartha Mahajan <siddhartha.mahajan8899@mongodb.com>2023-01-27 00:14:32 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-27 00:51:32 +0000
commit78903039c4a045fe75c2e7ad294dda3023c2d3e1 (patch)
tree6870de14d2fb7386415b5f5da9889ff3b855a43b /src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp
parent5719127434096769792d880e017f8edd9465fef9 (diff)
downloadmongo-78903039c4a045fe75c2e7ad294dda3023c2d3e1.tar.gz
Import wiredtiger: b18bedf3fd9fab37cd4ce03076ebb1a3bf02db83 from branch mongodb-master
ref: 32fada0e21..b18bedf3fd for: 6.3.0-rc0 WT-10518 Implement bucket_exists, object_exists and constructor for Azure
Diffstat (limited to 'src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp')
-rw-r--r--src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp b/src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp
index 5ce5be2ebe5..7f4a645f85a 100644
--- a/src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp
+++ b/src/third_party/wiredtiger/ext/storage_sources/azure_store/azure_connection.cpp
@@ -39,6 +39,13 @@ azure_connection::azure_connection(const std::string &bucket_name, const std::st
std::getenv("AZURE_STORAGE_CONNECTION_STRING"), bucket_name)),
_bucket_name(bucket_name), _object_prefix(obj_prefix)
{
+ // Confirm that we can access the bucket, else fail.
+ bool exists;
+ int ret = bucket_exists(exists);
+ if (ret != 0)
+ throw std::runtime_error(_bucket_name + " : Unable to access bucket.");
+ if (exists == false)
+ throw std::runtime_error(_bucket_name + " : No such bucket.");
}
// Build a list of all of the objects in the bucket.
@@ -95,3 +102,50 @@ azure_connection::get_object(const std::string &path) const
{
return 0;
}
+
+int
+azure_connection::object_exists(const std::string &object_key, bool &exists) const
+{
+ exists = false;
+ std::string obj = _object_prefix + object_key;
+
+ auto list_blob_response = _azure_client.ListBlobs();
+
+ for (const auto blob_item : list_blob_response.Blobs) {
+ // Check if object exists.
+ if (blob_item.Name.compare(obj) == 0) {
+ // Check if object is deleted and has not been cleared by garbage collection.
+ if (blob_item.IsDeleted) {
+ return -1;
+ }
+ exists = true;
+ break;
+ }
+ }
+ return 0;
+}
+
+int
+azure_connection::bucket_exists(bool &exists) const
+{
+ exists = false;
+
+ auto service_client = Azure::Storage::Blobs::BlobServiceClient::CreateFromConnectionString(
+ std::getenv("AZURE_STORAGE_CONNECTION_STRING"));
+
+ // Get list of containers associated with the class Azure client.
+ auto list_container_response = service_client.ListBlobContainers();
+
+ for (const auto container_item : list_container_response.BlobContainers) {
+ // Check if bucket exists.
+ if (container_item.Name.compare(_bucket_name) == 0) {
+ // Check if bucket is deleted and has not been cleared by garbage collection.
+ if (container_item.IsDeleted) {
+ return -1;
+ }
+ exists = true;
+ break;
+ }
+ }
+ return 0;
+}