Skip to content

Commit 64e53e3

Browse files
committed
update
1 parent f6ffd5f commit 64e53e3

File tree

9 files changed

+37
-18
lines changed

9 files changed

+37
-18
lines changed

src/iceberg/catalog/rest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(ICEBERG_REST_SOURCES
1919
catalog.cc
2020
json_internal.cc
2121
config.cc
22-
http_client_internal.cc
22+
http_client.cc
2323
resource_paths.cc)
2424

2525
set(ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS)

src/iceberg/catalog/rest/catalog.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "iceberg/catalog/rest/constant.h"
3131
#include "iceberg/catalog/rest/endpoint_util.h"
3232
#include "iceberg/catalog/rest/error_handlers.h"
33-
#include "iceberg/catalog/rest/http_client_interal.h"
33+
#include "iceberg/catalog/rest/http_client.h"
3434
#include "iceberg/catalog/rest/http_response.h"
3535
#include "iceberg/catalog/rest/json_internal.h"
3636
#include "iceberg/catalog/rest/types.h"

src/iceberg/catalog/rest/catalog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "iceberg/catalog.h"
2626
#include "iceberg/catalog/rest/config.h"
27-
#include "iceberg/catalog/rest/http_client_interal.h"
27+
#include "iceberg/catalog/rest/http_client.h"
2828
#include "iceberg/catalog/rest/iceberg_rest_export.h"
2929
#include "iceberg/catalog/rest/resource_paths.h"
3030
#include "iceberg/result.h"

src/iceberg/catalog/rest/endpoint_util.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ namespace iceberg::rest {
3131
/// \brief Trim a single trailing slash from a URI string_view.
3232
/// \details If \p uri_sv ends with '/', remove that last character; otherwise the input
3333
/// is returned unchanged.
34-
/// \param uri_sv The URI string view to trim.
35-
/// \return The (possibly) trimmed URI string view.
36-
inline std::string_view TrimTrailingSlash(std::string_view uri_sv) {
37-
if (uri_sv.ends_with('/')) {
38-
uri_sv.remove_suffix(1);
34+
/// \param uri_sv The URI string to trim.
35+
/// \return The (possibly) trimmed URI string.
36+
inline std::string TrimTrailingSlash(std::string uri_sv) {
37+
if (!uri_sv.empty() && uri_sv.back() == '/') {
38+
uri_sv.pop_back();
3939
}
4040
return uri_sv;
4141
}

src/iceberg/catalog/rest/http_client_internal.cc renamed to src/iceberg/catalog/rest/http_client.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* under the License.
1818
*/
1919

20+
#include "iceberg/catalog/rest/http_client.h"
21+
2022
#include <nlohmann/json.hpp>
2123

2224
#include "cpr/body.h"
2325
#include "cpr/cprtypes.h"
2426
#include "iceberg/catalog/rest/config.h"
25-
#include "iceberg/catalog/rest/http_client_interal.h"
2627
#include "iceberg/catalog/rest/json_internal.h"
2728
#include "iceberg/json_internal.h"
2829
#include "iceberg/util/macros.h"
@@ -94,6 +95,8 @@ Result<HttpResponse> HttpClient::Get(
9495
const std::string& path, const std::unordered_map<std::string, std::string>& params,
9596
const std::unordered_map<std::string, std::string>& headers,
9697
const ErrorHandler& error_handler) {
98+
std::lock_guard<std::mutex> lock(session_mutex_);
99+
97100
PrepareSession(path, headers, params);
98101
cpr::Response response = session_->Get();
99102
ICEBERG_RETURN_UNEXPECTED(HandleFailureResponse(response, error_handler));
@@ -104,6 +107,8 @@ Result<HttpResponse> HttpClient::Post(
104107
const std::string& path, const std::string& body,
105108
const std::unordered_map<std::string, std::string>& headers,
106109
const ErrorHandler& error_handler) {
110+
std::lock_guard<std::mutex> lock(session_mutex_);
111+
107112
PrepareSession(path, headers);
108113
session_->SetBody(cpr::Body{body});
109114
cpr::Response response = session_->Post();
@@ -116,6 +121,8 @@ Result<HttpResponse> HttpClient::PostForm(
116121
const std::unordered_map<std::string, std::string>& form_data,
117122
const std::unordered_map<std::string, std::string>& headers,
118123
const ErrorHandler& error_handler) {
124+
std::lock_guard<std::mutex> lock(session_mutex_);
125+
119126
PrepareSession(path, headers);
120127
std::vector<cpr::Pair> pair_list;
121128
pair_list.reserve(form_data.size());
@@ -131,6 +138,8 @@ Result<HttpResponse> HttpClient::PostForm(
131138
Result<HttpResponse> HttpClient::Head(
132139
const std::string& path, const std::unordered_map<std::string, std::string>& headers,
133140
const ErrorHandler& error_handler) {
141+
std::lock_guard<std::mutex> lock(session_mutex_);
142+
134143
PrepareSession(path, headers);
135144
cpr::Response response = session_->Head();
136145
ICEBERG_RETURN_UNEXPECTED(HandleFailureResponse(response, error_handler));
@@ -140,6 +149,8 @@ Result<HttpResponse> HttpClient::Head(
140149
Result<HttpResponse> HttpClient::Delete(
141150
const std::string& path, const std::unordered_map<std::string, std::string>& headers,
142151
const ErrorHandler& error_handler) {
152+
std::lock_guard<std::mutex> lock(session_mutex_);
153+
143154
PrepareSession(path, headers);
144155
cpr::Response response = session_->Delete();
145156
ICEBERG_RETURN_UNEXPECTED(HandleFailureResponse(response, error_handler));

src/iceberg/catalog/rest/http_client_interal.h renamed to src/iceberg/catalog/rest/http_client.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class ICEBERG_REST_EXPORT HttpClient {
4545

4646
HttpClient(const HttpClient&) = delete;
4747
HttpClient& operator=(const HttpClient&) = delete;
48-
HttpClient(HttpClient&&) = default;
49-
HttpClient& operator=(HttpClient&&) = default;
48+
HttpClient(HttpClient&&) = delete;
49+
HttpClient& operator=(HttpClient&&) = delete;
5050

5151
/// \brief Sends a GET request.
5252
Result<HttpResponse> Get(const std::string& path,
@@ -82,6 +82,12 @@ class ICEBERG_REST_EXPORT HttpClient {
8282
const std::unordered_map<std::string, std::string>& params = {});
8383

8484
std::unordered_map<std::string, std::string> default_headers_;
85+
86+
// Mutex to protect the non-thread-safe cpr::Session.
87+
mutable std::mutex session_mutex_;
88+
89+
// TODO(Li Feiyang): use connection pool to support external multi-threaded concurrent
90+
// calls
8591
std::unique_ptr<cpr::Session> session_;
8692
};
8793

src/iceberg/catalog/rest/meson.build

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
iceberg_rest_sources = files(
1919
'catalog.cc',
2020
'config.cc',
21-
'http_client_internal.cc',
21+
'http_client.cc',
2222
'json_internal.cc',
2323
'resource_path.cc',
2424
)
@@ -57,11 +57,14 @@ install_headers(
5757
'catalog.h',
5858
'config.h',
5959
'constant.h',
60-
'http_client_interal.h',
60+
'http_client.h',
61+
'http_response.h',
6162
'json_internal.h',
63+
'iceberg_rest_export.h',
6264
'types.h',
63-
'util.h',
6465
'resource_paths.h',
66+
'endpoint_util.h',
67+
'error_handlers.h',
6568
],
6669
subdir: 'iceberg/catalog/rest',
6770
)

src/iceberg/catalog/rest/types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#pragma once
2121

22-
#include <algorithm>
2322
#include <format>
2423
#include <memory>
2524
#include <string>

src/iceberg/test/rest_catalog_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RestCatalogTest : public ::testing::Test {
6161
RestCatalogConfig config_;
6262
};
6363

64-
TEST_F(RestCatalogTest, DISABLED_MakeCatalogSuccess) {
64+
TEST_F(RestCatalogTest, MakeCatalogSuccess) {
6565
auto catalog_result = RestCatalog::Make(config_);
6666
EXPECT_THAT(catalog_result, IsOk());
6767

@@ -82,7 +82,7 @@ TEST_F(RestCatalogTest, DISABLED_MakeCatalogEmptyUri) {
8282
EXPECT_THAT(catalog_result, HasErrorMessage("uri"));
8383
}
8484

85-
TEST_F(RestCatalogTest, DISABLED_MakeCatalogWithCustomProperties) {
85+
TEST_F(RestCatalogTest, MakeCatalogWithCustomProperties) {
8686
RestCatalogConfig custom_config = config_;
8787
custom_config
8888
.Set(RestCatalogConfig::Entry<std::string>{"custom_prop", ""},
@@ -93,7 +93,7 @@ TEST_F(RestCatalogTest, DISABLED_MakeCatalogWithCustomProperties) {
9393
EXPECT_THAT(catalog_result, IsOk());
9494
}
9595

96-
TEST_F(RestCatalogTest, DISABLED_ListNamespaces) {
96+
TEST_F(RestCatalogTest, ListNamespaces) {
9797
auto catalog_result = RestCatalog::Make(config_);
9898
ASSERT_THAT(catalog_result, IsOk());
9999
auto& catalog = catalog_result.value();

0 commit comments

Comments
 (0)