diff --git a/example/benchmark/src/benchmark/bandwidth.cpp b/example/benchmark/src/benchmark/bandwidth.cpp index 67ac182..c3e17d3 100644 --- a/example/benchmark/src/benchmark/bandwidth.cpp +++ b/example/benchmark/src/benchmark/bandwidth.cpp @@ -3,9 +3,8 @@ #include "cloud/aws_resolver.hpp" #include "cloud/azure.hpp" #include "cloud/gcp.hpp" -#include "network/get_transaction.hpp" +#include "network/transaction.hpp" #include "network/original_message.hpp" -#include "network/put_transaction.hpp" #include "network/s3_send_receiver.hpp" #include "network/tasked_send_receiver.hpp" #include "perfevent/PerfEvent.hpp" @@ -217,7 +216,7 @@ void Bandwidth::runUring(const Settings& benchmarkSettings, const string& uri) sendReceivers.back()->reuse(result.moveDataVector()); }; - network::GetTransaction getTxn[benchmarkSettings.concurrentThreads]; + network::Transaction getTxn[benchmarkSettings.concurrentThreads]; for (auto i = 0u; i < benchmarkSettings.concurrentThreads; i++) getTxn[i].setProvider(cloudProvider.get()); @@ -225,13 +224,13 @@ void Bandwidth::runUring(const Settings& benchmarkSettings, const string& uri) if (benchmarkSettings.blobFiles > benchmarkSettings.requests) { for (auto i = 0u; i < benchmarkSettings.requests; i++) { auto filePath = benchmarkSettings.filePath + to_string(dist(rng)) + ".bin"; - getTxn[0].addRequest(callback, filePath, range, nullptr, 0, i); + getTxn[0].getObjectRequest(callback, filePath, range, nullptr, 0, i); } } else { auto createRequests = [&](uint64_t start, uint64_t end, uint64_t threadId) { for (auto i = start; i < end; i++) { auto filePath = benchmarkSettings.filePath + to_string((i % benchmarkSettings.blobFiles) + 1) + ".bin"; - getTxn[threadId].addRequest(callback, filePath, range, nullptr, 0, i); + getTxn[threadId].getObjectRequest(callback, filePath, range, nullptr, 0, i); } }; auto start = 0ull; @@ -288,7 +287,7 @@ void Bandwidth::runUring(const Settings& benchmarkSettings, const string& uri) finishedMessages++; }; - network::PutTransaction putTxn(cloudProvider.get()); + network::Transaction putTxn(cloudProvider.get()); auto blob = make_unique>(1 << 24); if (benchmarkSettings.encryption) { auto plainBlob = make_unique>((1 << 24) - 16); @@ -308,7 +307,7 @@ void Bandwidth::runUring(const Settings& benchmarkSettings, const string& uri) end = benchmarkSettings.requests; for (uint64_t j = start; j < end; j++) { auto filePath = "upload_" + benchmarkSettings.filePath + to_string(j + 1) + ".bin"; - putTxn.addRequest(callbackUpload, filePath, reinterpret_cast(blob->data()), blob->size(), nullptr, 0, i); + putTxn.putObjectRequest(callbackUpload, filePath, reinterpret_cast(blob->data()), blob->size(), nullptr, 0, i); } } diff --git a/example/simple/main.cpp b/example/simple/main.cpp index 0c126b0..488aa46 100644 --- a/example/simple/main.cpp +++ b/example/simple/main.cpp @@ -1,5 +1,5 @@ #include "cloud/provider.hpp" -#include "network/get_transaction.hpp" +#include "network/transaction.hpp" #include "network/tasked_send_receiver.hpp" #include #include @@ -28,8 +28,8 @@ int main(int /*argc*/, char** /*argv*/) { auto provider = anyblob::cloud::Provider::makeProvider(bucketName, false, "", "", &sendReceiver); // Create the get request - anyblob::network::GetTransaction getTxn(provider.get()); - getTxn.addRequest(fileName); + anyblob::network::Transaction getTxn(provider.get()); + getTxn.getObjectRequest(fileName); // Retrieve the request synchronously with the scheduler object on this thread getTxn.processSync(sendReceiver); diff --git a/include/cloud/provider.hpp b/include/cloud/provider.hpp index a618c3a..3dd3a7f 100644 --- a/include/cloud/provider.hpp +++ b/include/cloud/provider.hpp @@ -14,9 +14,6 @@ namespace anyblob { namespace network { class TaskedSendReceiver; class Transaction; -class GetTransaction; -class PutTransaction; -class DeleteTransaction; struct OriginalMessage; }; // namespace network namespace utils { @@ -109,9 +106,6 @@ class Provider { [[nodiscard]] virtual Instance getInstanceDetails(network::TaskedSendReceiver& sendReceiver) = 0; friend network::Transaction; - friend network::GetTransaction; - friend network::PutTransaction; - friend network::DeleteTransaction; }; //--------------------------------------------------------------------------- } // namespace cloud diff --git a/include/network/delete_transaction.hpp b/include/network/delete_transaction.hpp deleted file mode 100644 index fcf8ef9..0000000 --- a/include/network/delete_transaction.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once -#include "cloud/provider.hpp" -#include "network/original_message.hpp" -#include "network/transaction.hpp" -#include -//--------------------------------------------------------------------------- -// AnyBlob - Universal Cloud Object Storage Library -// Dominik Durner, 2023 -// -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// SPDX-License-Identifier: MPL-2.0 -//--------------------------------------------------------------------------- -namespace anyblob { -//--------------------------------------------------------------------------- -namespace network { -//--------------------------------------------------------------------------- -/// Specialization of a delete request -class DeleteTransaction : public Transaction { - public: - /// The default constructor - DeleteTransaction() = default; - /// The explicit constructor - explicit DeleteTransaction(const cloud::Provider* provider) : Transaction(provider) {} - - /// Build a new delete request for synchronous calls - inline void addRequest(const std::string& remotePath, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto originalMsg = std::make_unique(provider->deleteRequest(remotePath), provider->getAddress(), provider->getPort(), result, capacity, traceId); - messages.push_back(std::move(originalMsg)); - } - - /// Build a new delete request with callback - template - inline void addRequest(Callback&& callback, const std::string& remotePath, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto originalMsg = std::make_unique>(std::forward(callback), provider->deleteRequest(remotePath), provider->getAddress(), provider->getPort(), result, capacity, traceId); - messages.push_back(std::move(originalMsg)); - } -}; -//--------------------------------------------------------------------------- -} // namespace network -} // namespace anyblob diff --git a/include/network/get_transaction.hpp b/include/network/get_transaction.hpp deleted file mode 100644 index e75de41..0000000 --- a/include/network/get_transaction.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "cloud/provider.hpp" -#include "network/original_message.hpp" -#include "network/transaction.hpp" -#include -//--------------------------------------------------------------------------- -// AnyBlob - Universal Cloud Object Storage Library -// Dominik Durner, 2023 -// -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// SPDX-License-Identifier: MPL-2.0 -//--------------------------------------------------------------------------- -namespace anyblob { -//--------------------------------------------------------------------------- -namespace network { -//--------------------------------------------------------------------------- -/// Specialization for get requests -class GetTransaction : public Transaction { - public: - /// The default constructor - GetTransaction() = default; - /// The explicit constructor - explicit GetTransaction(const cloud::Provider* provider) : Transaction(provider) {} - - /// Build a new get request for synchronous calls - /// Note that the range is [start, end[, [0, 0[ gets the whole object - inline void addRequest(const std::string& remotePath, std::pair range = {0, 0}, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto originalMsg = std::make_unique(provider->getRequest(remotePath, range), provider->getAddress(), provider->getPort(), result, capacity, traceId); - messages.push_back(std::move(originalMsg)); - } - - /// Build a new get request with callback - /// Note that the range is [start, end[, [0, 0[ gets the whole object - template - inline void addRequest(Callback&& callback, const std::string& remotePath, std::pair range = {0, 0}, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto originalMsg = std::make_unique>(std::forward(callback), provider->getRequest(remotePath, range), provider->getAddress(), provider->getPort(), result, capacity, traceId); - messages.push_back(std::move(originalMsg)); - } -}; -//--------------------------------------------------------------------------- -} // namespace network -} // namespace anyblob diff --git a/include/network/put_transaction.hpp b/include/network/put_transaction.hpp deleted file mode 100644 index 8e4cb76..0000000 --- a/include/network/put_transaction.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include "cloud/provider.hpp" -#include "network/original_message.hpp" -#include "network/transaction.hpp" -#include -//--------------------------------------------------------------------------- -// AnyBlob - Universal Cloud Object Storage Library -// Dominik Durner, 2023 -// -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// SPDX-License-Identifier: MPL-2.0 -//--------------------------------------------------------------------------- -namespace anyblob { -//--------------------------------------------------------------------------- -namespace network { -//--------------------------------------------------------------------------- -/// Specialization of a put request -class PutTransaction : public Transaction { - public: - /// The default constructor - PutTransaction() = default; - /// The explicit constructor - explicit PutTransaction(const cloud::Provider* provider) : Transaction(provider) {} - - /// Build a new put request for synchronous calls - inline void addRequest(const std::string& remotePath, const char* data, uint64_t size, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto object = std::string_view(data, size); - auto originalMsg = std::make_unique(provider->putRequest(remotePath, object), provider->getAddress(), provider->getPort(), result, capacity, traceId); - originalMsg->setPutRequestData(reinterpret_cast(data), size); - messages.push_back(std::move(originalMsg)); - } - - /// Build a new put request with callback - template - inline void addRequest(Callback&& callback, const std::string& remotePath, const char* data, uint64_t size, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { - assert(provider); - auto object = std::string_view(data, size); - auto originalMsg = std::make_unique>(std::forward(callback), provider->putRequest(remotePath, object), provider->getAddress(), provider->getPort(), result, capacity, traceId); - originalMsg->setPutRequestData(reinterpret_cast(data), size); - messages.push_back(std::move(originalMsg)); - } -}; -//--------------------------------------------------------------------------- -} // namespace network -} // namespace anyblob diff --git a/include/network/transaction.hpp b/include/network/transaction.hpp index 234b443..0c99764 100644 --- a/include/network/transaction.hpp +++ b/include/network/transaction.hpp @@ -1,5 +1,8 @@ #pragma once +#include "cloud/provider.hpp" #include "network/message_result.hpp" +#include "network/original_message.hpp" +#include #include #include #include @@ -24,7 +27,6 @@ class TaskedSendReceiver; class TaskedSendReceiverGroup; //--------------------------------------------------------------------------- /// The request/response transaction handler used to transfer data from and to remote storage -/// Used as interface in the initiation GetTransaction and PutTransaction class Transaction { public: class Iterator; @@ -38,12 +40,13 @@ class Transaction { /// The message message_vector_type messages; + public: + /// The constructor Transaction() = default; /// The explicit constructor with the provider explicit Transaction(const cloud::Provider* provider) : provider(provider), messages() {} - public: /// Set the provider constexpr void setProvider(const cloud::Provider* provider) { this->provider = provider; } /// Sends the request messages to the task group @@ -51,6 +54,57 @@ class Transaction { /// Processes the request messages void processSync(TaskedSendReceiver& sendReceiver); + /// Build a new get request for synchronous calls + /// Note that the range is [start, end[, [0, 0[ gets the whole object + inline void getObjectRequest(const std::string& remotePath, std::pair range = {0, 0}, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto originalMsg = std::make_unique(provider->getRequest(remotePath, range), provider->getAddress(), provider->getPort(), result, capacity, traceId); + messages.push_back(std::move(originalMsg)); + } + + /// Build a new get request with callback + /// Note that the range is [start, end[, [0, 0[ gets the whole object + template + inline void getObjectRequest(Callback&& callback, const std::string& remotePath, std::pair range = {0, 0}, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto originalMsg = std::make_unique>(std::forward(callback), provider->getRequest(remotePath, range), provider->getAddress(), provider->getPort(), result, capacity, traceId); + messages.push_back(std::move(originalMsg)); + } + + /// Build a new put request for synchronous calls + inline void putObjectRequest(const std::string& remotePath, const char* data, uint64_t size, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto object = std::string_view(data, size); + auto originalMsg = std::make_unique(provider->putRequest(remotePath, object), provider->getAddress(), provider->getPort(), result, capacity, traceId); + originalMsg->setPutRequestData(reinterpret_cast(data), size); + messages.push_back(std::move(originalMsg)); + } + + /// Build a new put request with callback + template + inline void putObjectRequest(Callback&& callback, const std::string& remotePath, const char* data, uint64_t size, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto object = std::string_view(data, size); + auto originalMsg = std::make_unique>(std::forward(callback), provider->putRequest(remotePath, object), provider->getAddress(), provider->getPort(), result, capacity, traceId); + originalMsg->setPutRequestData(reinterpret_cast(data), size); + messages.push_back(std::move(originalMsg)); + } + + /// Build a new delete request for synchronous calls + inline void deleteObjectRequest(const std::string& remotePath, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto originalMsg = std::make_unique(provider->deleteRequest(remotePath), provider->getAddress(), provider->getPort(), result, capacity, traceId); + messages.push_back(std::move(originalMsg)); + } + + /// Build a new delete request with callback + template + inline void deleteObjectRequest(Callback&& callback, const std::string& remotePath, uint8_t* result = nullptr, uint64_t capacity = 0, uint64_t traceId = 0) { + assert(provider); + auto originalMsg = std::make_unique>(std::forward(callback), provider->deleteRequest(remotePath), provider->getAddress(), provider->getPort(), result, capacity, traceId); + messages.push_back(std::move(originalMsg)); + } + /// The iterator using iterator = Iterator; /// The const iterator diff --git a/test/integration/minio.cpp b/test/integration/minio.cpp index 063094d..9464c20 100644 --- a/test/integration/minio.cpp +++ b/test/integration/minio.cpp @@ -1,9 +1,7 @@ #include "catch2/single_include/catch2/catch.hpp" #include "cloud/provider.hpp" -#include "network/get_transaction.hpp" -#include "network/put_transaction.hpp" -#include "network/delete_transaction.hpp" #include "network/tasked_send_receiver.hpp" +#include "network/transaction.hpp" #include #include #include @@ -46,9 +44,9 @@ TEST_CASE("MinIO Integration") { // The file to be uploaded and downloaded string bucketName = "minio://"; bucketName = bucketName + endpoint + "/" + bucket + ":" + region; - string fileName[] {"test.txt", "long.txt"}; + string fileName[]{"test.txt", "long.txt"}; string longText = stringGen(1 << 24); - string content[] {"Hello World!", longText}; + string content[]{"Hello World!", longText}; // Create a new task group (18 concurrent request maximum, and up to 1024 outstanding submissions) anyblob::network::TaskedSendReceiverGroup group(18, 1024); @@ -60,9 +58,9 @@ TEST_CASE("MinIO Integration") { auto provider = anyblob::cloud::Provider::makeProvider(bucketName, false, key, secret, &sendReceiver); { // Create the put request - anyblob::network::PutTransaction putTxn(provider.get()); + anyblob::network::Transaction putTxn(provider.get()); for (auto i = 0u; i < 2; i++) - putTxn.addRequest(fileName[i], content[i].data(), content[i].size()); + putTxn.putObjectRequest(fileName[i], content[i].data(), content[i].size()); // Upload the request synchronously with the scheduler object on this thread putTxn.processSync(sendReceiver); @@ -75,9 +73,9 @@ TEST_CASE("MinIO Integration") { } { // Create the get request - anyblob::network::GetTransaction getTxn(provider.get()); + anyblob::network::Transaction getTxn(provider.get()); for (auto i = 0u; i < 2; i++) - getTxn.addRequest(fileName[i]); + getTxn.getObjectRequest(fileName[i]); // Retrieve the request synchronously with the scheduler object on this thread getTxn.processSync(sendReceiver); @@ -105,9 +103,9 @@ TEST_CASE("MinIO Integration") { } { // Create the put request - anyblob::network::DeleteTransaction deleteTxn(provider.get()); + anyblob::network::Transaction deleteTxn(provider.get()); for (auto i = 0u; i < 2; i++) - deleteTxn.addRequest(fileName[i]); + deleteTxn.deleteObjectRequest(fileName[i]); // Upload the request synchronously with the scheduler object on this thread deleteTxn.processSync(sendReceiver); @@ -118,7 +116,6 @@ TEST_CASE("MinIO Integration") { REQUIRE(it.success()); } } - } //--------------------------------------------------------------------------- } // namespace test