Skip to content

Commit 271b045

Browse files
class RestClient C.41 conformance. (#4994)
The centerpiece of this PR is to bring `class RestClient` into conformance with C.41. Full initialization of that class was happening not only in its `init()` member function but also in `StorageManager::set_default_tags`. The PR removes both of these functions and moves their behavior to `RestClient::RestClient`, which has a new signature and much-expanded body. An interrelated goal is to extricate `class StorageManager` from the implementation of C API function `tiledb_ctx_set_tag`; the new implementation calls `RestClient` directly. Not only was initialization for this happening outside of `RestClient`, but the underlying data structure was duplicated in `StorageManager` and then only used to run a few tests. This PR removes the relevant member functions and variables from `class StorageManager`, reworks the C API function to call `RestClient` directly, adds `RestClient::extra_headers()` to replace `StorageManager::tags()`, and reworks the C API tests accordingly. This PR has a bit of ancillary support work. It adds `Context::has_rest_client()` and adds a proxy for this and `Context::rest_client()` in the C API handle class for `class Context`. It updates use of `Config::get` to non-deprecated varieties. This PR remove all preprocessor use of the configuration variable `TILEDB_SERIALIZATION` from `class RestClient`. Instead of using the preprocessor, there is now a server-disabled base class and a server-enabled derived class. The server-enabled class is now declared and defined in separate translation units. `TILEDB_SERIALIZATION` now affects what sources files are compiled with ordinary build dependencies. The only remaining involvement of `class StorageManager` with `class RestClient` is an accessor to the `RestClient` instance (currently) held within its `ContextResources` member variable. Removing this accessor is out of scope for this PR. --- TYPE: NO_HISTORY DESC: `class RestClient` C.41 conformance. --------- Co-authored-by: KiterLuc <[email protected]>
1 parent 493e3f9 commit 271b045

24 files changed

+2900
-2390
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,28 +384,28 @@ set(TILEDB_EXPORT_HEADER "${TILEDB_EXPORT_HEADER_DIR}/${TILEDB_EXPORT_HEADER_NAM
384384
set(TILEDB_EXPORT_HEADER_LOCALINSTALL_PATH "tiledb/api/c_api/${TILEDB_EXPORT_HEADER_NAME}")
385385

386386
##################################
387-
# VFS Object Storage Configuration
387+
# Library Configuration
388388
##################################
389-
# Create an interface library for use in passing the
390-
# appropriate compiler definitions for the set of
391-
# configured object storage backends.
389+
#
390+
# `configuration_definitions` is an interface library that contains compiler
391+
# definitions corresponding to the configuration variables passed to CMake
392392

393-
add_library(object_store_definitions INTERFACE)
393+
add_library(configuration_definitions INTERFACE)
394394

395395
if (TILEDB_AZURE)
396-
target_compile_definitions(object_store_definitions INTERFACE -DHAVE_AZURE)
396+
target_compile_definitions(configuration_definitions INTERFACE -DHAVE_AZURE)
397397
endif()
398398

399399
if (TILEDB_GCS)
400-
target_compile_definitions(object_store_definitions INTERFACE -DHAVE_GCS)
400+
target_compile_definitions(configuration_definitions INTERFACE -DHAVE_GCS)
401401
endif()
402402

403403
if (TILEDB_HDFS)
404-
target_compile_definitions(object_store_definitions INTERFACE -DHAVE_HDFS)
404+
target_compile_definitions(configuration_definitions INTERFACE -DHAVE_HDFS)
405405
endif()
406406

407407
if (TILEDB_S3)
408-
target_compile_definitions(object_store_definitions INTERFACE -DHAVE_S3)
408+
target_compile_definitions(configuration_definitions INTERFACE -DHAVE_S3)
409409
endif()
410410

411411
##################################

cmake/object_library.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ macro(TileDB_Environment_object_library_end)
178178
foreach(Compile_Definition IN LISTS TileDB_Environment_object_library_end_Compile_Definitions)
179179
target_compile_definitions(${TileDB_Environment_object_library_end_Library} PUBLIC ${Compile_Definition})
180180
endforeach()
181+
#
182+
# All object libraries ought to depend upon the `configuration_definitions`
183+
# library, but at present it's premature for that
184+
#
185+
#target_link_libraries(${TileDB_Environment_object_library_end_Library} PUBLIC configuration_definitions)
181186

182187
# Compile test
183188
add_executable(${TileDB_Environment_object_library_end_Compile} EXCLUDE_FROM_ALL)

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ target_link_libraries(tiledb_unit
302302
TILEDB_CORE_OBJECTS
303303
Catch2::Catch2
304304
tiledb_test_support_lib
305+
configuration_definitions
305306
)
306307

307308
target_link_libraries(tiledb_unit PRIVATE $<BUILD_INTERFACE:common>)

test/src/unit-ctx.cc

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -43,56 +43,63 @@
4343
TEST_CASE("C API: Test context tags", "[capi][ctx-tags]") {
4444
tiledb_ctx_t* ctx = nullptr;
4545
REQUIRE(tiledb_ctx_alloc(nullptr, &ctx) == TILEDB_OK);
46-
tiledb::sm::StorageManager* sm = ctx->storage_manager();
4746

48-
// Check defaults
49-
REQUIRE(sm->tags().size() == 2);
50-
REQUIRE(sm->tags().at("x-tiledb-api-language") == "c");
51-
REQUIRE(
52-
sm->tags().at("x-tiledb-version") ==
53-
(std::to_string(tiledb::sm::constants::library_version[0]) + "." +
54-
std::to_string(tiledb::sm::constants::library_version[1]) + "." +
55-
std::to_string(tiledb::sm::constants::library_version[2])));
47+
// Only run these tests if the rest client has been initialized
48+
if (ctx->has_rest_client()) {
49+
auto& rest_client{ctx->rest_client()};
50+
SECTION("Defaults") {
51+
REQUIRE(rest_client.extra_headers().size() == 2);
52+
REQUIRE(rest_client.extra_headers().at("x-tiledb-api-language") == "c");
53+
REQUIRE(
54+
rest_client.extra_headers().at("x-tiledb-version") ==
55+
(std::to_string(tiledb::sm::constants::library_version[0]) + "." +
56+
std::to_string(tiledb::sm::constants::library_version[1]) + "." +
57+
std::to_string(tiledb::sm::constants::library_version[2])));
58+
}
59+
SECTION("tiledb_ctx_set_tag") {
60+
REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value1") == TILEDB_OK);
61+
REQUIRE(rest_client.extra_headers().size() == 3);
62+
REQUIRE(rest_client.extra_headers().at("tag1") == "value1");
5663

57-
// Check setter
58-
REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value1") == TILEDB_OK);
59-
REQUIRE(sm->tags().size() == 3);
60-
REQUIRE(sm->tags().at("tag1") == "value1");
61-
62-
REQUIRE(tiledb_ctx_set_tag(ctx, "tag2", "value2") == TILEDB_OK);
63-
REQUIRE(sm->tags().size() == 4);
64-
REQUIRE(sm->tags().at("tag2") == "value2");
65-
66-
REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value3") == TILEDB_OK);
67-
REQUIRE(sm->tags().size() == 4);
68-
REQUIRE(sm->tags().at("tag1") == "value3");
64+
REQUIRE(tiledb_ctx_set_tag(ctx, "tag2", "value2") == TILEDB_OK);
65+
REQUIRE(rest_client.extra_headers().size() == 4);
66+
REQUIRE(rest_client.extra_headers().at("tag2") == "value2");
6967

68+
REQUIRE(tiledb_ctx_set_tag(ctx, "tag1", "value3") == TILEDB_OK);
69+
REQUIRE(rest_client.extra_headers().size() == 4);
70+
REQUIRE(rest_client.extra_headers().at("tag1") == "value3");
71+
}
72+
}
7073
tiledb_ctx_free(&ctx);
7174
}
7275

7376
TEST_CASE("C++ API: Test context tags", "[cppapi][ctx-tags]") {
7477
tiledb::Context ctx;
75-
tiledb::sm::StorageManager* sm = ctx.ptr().get()->storage_manager();
76-
77-
// Check defaults
78-
REQUIRE(sm->tags().size() == 2);
79-
REQUIRE(sm->tags().at("x-tiledb-api-language") == "c++");
80-
REQUIRE(
81-
sm->tags().at("x-tiledb-version") ==
82-
(std::to_string(tiledb::sm::constants::library_version[0]) + "." +
83-
std::to_string(tiledb::sm::constants::library_version[1]) + "." +
84-
std::to_string(tiledb::sm::constants::library_version[2])));
8578

86-
// Check setter
87-
REQUIRE_NOTHROW(ctx.set_tag("tag1", "value1"));
88-
REQUIRE(sm->tags().size() == 3);
89-
REQUIRE(sm->tags().at("tag1") == "value1");
79+
// Only run these tests if the rest client has been initialized
80+
if (ctx.ptr().get()->has_rest_client()) {
81+
auto& rest_client{ctx.ptr().get()->rest_client()};
82+
SECTION("Defaults") {
83+
REQUIRE(rest_client.extra_headers().size() == 2);
84+
REQUIRE(rest_client.extra_headers().at("x-tiledb-api-language") == "c++");
85+
REQUIRE(
86+
rest_client.extra_headers().at("x-tiledb-version") ==
87+
(std::to_string(tiledb::sm::constants::library_version[0]) + "." +
88+
std::to_string(tiledb::sm::constants::library_version[1]) + "." +
89+
std::to_string(tiledb::sm::constants::library_version[2])));
90+
}
91+
SECTION("tiledb_ctx_set_tag") {
92+
REQUIRE_NOTHROW(ctx.set_tag("tag1", "value1"));
93+
REQUIRE(rest_client.extra_headers().size() == 3);
94+
REQUIRE(rest_client.extra_headers().at("tag1") == "value1");
9095

91-
REQUIRE_NOTHROW(ctx.set_tag("tag2", "value2"));
92-
REQUIRE(sm->tags().size() == 4);
93-
REQUIRE(sm->tags().at("tag2") == "value2");
96+
REQUIRE_NOTHROW(ctx.set_tag("tag2", "value2"));
97+
REQUIRE(rest_client.extra_headers().size() == 4);
98+
REQUIRE(rest_client.extra_headers().at("tag2") == "value2");
9499

95-
REQUIRE_NOTHROW(ctx.set_tag("tag1", "value3"));
96-
REQUIRE(sm->tags().size() == 4);
97-
REQUIRE(sm->tags().at("tag1") == "value3");
100+
REQUIRE_NOTHROW(ctx.set_tag("tag1", "value3"));
101+
REQUIRE(rest_client.extra_headers().size() == 4);
102+
REQUIRE(rest_client.extra_headers().at("tag1") == "value3");
103+
}
104+
}
98105
}

test/src/unit-curl.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,13 @@ TEST_CASE(
117117
ThreadPool tp{1};
118118
ContextResources resources(
119119
cfg, tiledb::test::g_helper_logger(), 1, 1, "test");
120-
tiledb::sm::RestClient rest_client;
121-
REQUIRE(rest_client
122-
.init(
123-
&tiledb::test::g_helper_stats,
124-
&cfg,
125-
&tp,
126-
tiledb::test::g_helper_logger(),
127-
resources)
128-
.ok());
129-
CHECK(rest_client.rest_server() == "http://localhost:8080");
120+
auto rest_client{tiledb::sm::RestClientFactory::make(
121+
tiledb::test::g_helper_stats,
122+
cfg,
123+
tp,
124+
*tiledb::test::g_helper_logger().get(),
125+
resources.create_memory_tracker())};
126+
CHECK(rest_client->rest_server() == "http://localhost:8080");
130127
}
131128

132129
TEST_CASE(

tiledb/CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ set(TILEDB_CORE_SOURCES
322322
list(APPEND TILEDB_CORE_SOURCES ${TILEDB_COMMON_SOURCES})
323323
list(APPEND TILEDB_CORE_SOURCES ${TILEDB_API_SOURCES})
324324

325-
326-
327325
#openssl3 md5 deprecation mitigation
328326
if(MSVC)
329327
set_source_files_properties(${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/crypto/crypto_openssl.cc PROPERTIES COMPILE_OPTIONS "/wd4996")
@@ -334,11 +332,12 @@ endif()
334332
if (TILEDB_SERIALIZATION)
335333
list(APPEND TILEDB_CORE_SOURCES
336334
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/curl.cc
335+
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client_remote.cc
337336
)
338337

339338
if(NOT WIN32)
340339
set_source_files_properties(
341-
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client.cc
340+
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client_remote.cc
342341
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array.cc
343342
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array_directory.cc
344343
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array_schema.cc
@@ -362,7 +361,7 @@ if (TILEDB_SERIALIZATION)
362361
endif()
363362
if(MSVC)
364363
set_source_files_properties(
365-
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client.cc
364+
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/rest/rest_client_remote.cc
366365
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array.cc
367366
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array_directory.cc
368367
${TILEDB_CORE_INCLUDE_DIR}/tiledb/sm/serialization/array_schema.cc
@@ -440,7 +439,7 @@ target_link_libraries(TILEDB_CORE_OBJECTS
440439
${TILEDB_CORE_OBJECTS_LIBS}
441440
)
442441

443-
target_link_libraries(TILEDB_CORE_OBJECTS INTERFACE object_store_definitions)
442+
target_link_libraries(TILEDB_CORE_OBJECTS INTERFACE configuration_definitions)
444443

445444
############################################################
446445
# provide actions/target for preparation of magic.mgc data for embedding/build
@@ -503,7 +502,7 @@ endif()
503502
add_library(TILEDB_CORE_OBJECTS_ILIB INTERFACE)
504503

505504
# object store definitions
506-
target_link_libraries(TILEDB_CORE_OBJECTS_ILIB INTERFACE object_store_definitions)
505+
target_link_libraries(TILEDB_CORE_OBJECTS_ILIB INTERFACE configuration_definitions)
507506

508507
# blosc link dependencies
509508
target_link_libraries(TILEDB_CORE_OBJECTS_ILIB INTERFACE ${TileDB_blosc_LINK_OPTIONS})
@@ -938,8 +937,8 @@ set(TILEDB_INSTALL_TARGETS
938937
)
939938
if (NOT BUILD_SHARED_LIBS)
940939
list(APPEND TILEDB_INSTALL_TARGETS
941-
TILEDB_CORE_OBJECTS_ILIB
942-
object_store_definitions
940+
TILEDB_CORE_OBJECTS_ILIB
941+
configuration_definitions
943942
)
944943
endif()
945944

tiledb/api/c_api/context/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ list(APPEND OTHER_SOURCES
4141
commence(object_library capi_context_stub)
4242
this_target_sources(${SOURCES} ${OTHER_SOURCES})
4343
this_target_link_libraries(export)
44-
this_target_link_libraries(storage_manager_stub)
4544
this_target_object_libraries(capi_config_stub)
46-
this_target_object_libraries(vfs stats thread_pool)
45+
this_target_object_libraries(storage_manager_stub)
46+
this_target_object_libraries(rest_client stats thread_pool vfs)
4747
conclude(object_library)
4848

4949
add_test_subdirectory()

tiledb/api/c_api/context/context_api.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "context_api_external.h"
3535
#include "context_api_internal.h"
3636
#include "tiledb/api/c_api_support/c_api_support.h"
37+
#include "tiledb/sm/rest/rest_client.h"
3738

3839
namespace tiledb::api {
3940

@@ -121,12 +122,12 @@ capi_return_t tiledb_ctx_cancel_tasks(tiledb_ctx_t* ctx) {
121122
capi_return_t tiledb_ctx_set_tag(
122123
tiledb_ctx_t* ctx, const char* key, const char* value) {
123124
if (key == nullptr) {
124-
throw CAPIStatusException("tiledb_ctx_set_tag: key may not be null");
125+
throw CAPIException("tiledb_ctx_set_tag: key may not be null");
125126
}
126127
if (value == nullptr) {
127-
throw CAPIStatusException("tiledb_ctx_set_tag: value may not be null");
128+
throw CAPIException("tiledb_ctx_set_tag: value may not be null");
128129
}
129-
throw_if_not_ok(ctx->storage_manager()->set_tag(key, value));
130+
ctx->rest_client().add_header(key, value);
130131
return TILEDB_OK;
131132
}
132133

tiledb/api/c_api/context/context_api_internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ struct tiledb_ctx_handle_t
7171
return ctx_.storage_manager();
7272
}
7373

74+
inline tiledb::sm::RestClient& rest_client() {
75+
return ctx_.rest_client();
76+
}
77+
78+
inline bool has_rest_client() {
79+
return ctx_.has_rest_client();
80+
}
81+
7482
inline optional<std::string> last_error() {
7583
return ctx_.last_error();
7684
}

tiledb/api/c_api_support/exception_wrapper/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ commence(unit_test capi_ew_with_hook)
7777
this_target_link_libraries(export)
7878
this_target_object_libraries(
7979
exception_wrapper
80+
rest_client
8081
storage_manager_stub
8182
vfs
8283
)

0 commit comments

Comments
 (0)