Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/spider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ set(SPIDER_CORE_HEADERS

add_library(spider_core)
target_sources(spider_core PRIVATE ${SPIDER_CORE_SOURCES})
target_sources(spider_core PUBLIC ${SPIDER_CORE_HEADERS})
target_sources(
spider_core
PUBLIC
FILE_SET spider_core_headers
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/..
FILES ${SPIDER_CORE_HEADERS}
)
target_link_libraries(
spider_core
PUBLIC
Expand Down Expand Up @@ -150,7 +157,14 @@ set(SPIDER_CLIENT_SHARED_HEADERS

add_library(spider_client)
target_sources(spider_client PRIVATE ${SPIDER_CLIENT_SHARED_SOURCES})
target_sources(spider_client PUBLIC ${SPIDER_CLIENT_SHARED_HEADERS})
target_sources(
spider_client
PUBLIC
FILE_SET spider_client_shared_headers
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/..
FILES ${SPIDER_CLIENT_SHARED_HEADERS}
)
target_link_libraries(
spider_client
PUBLIC
Expand Down
39 changes: 39 additions & 0 deletions src/spider/worker/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <tuple>

#include <boost/dll/alias.hpp>
#include <spdlog/spdlog.h>

#include "../io/MsgPack.hpp" // IWYU pragma: keep
#include "TaskExecutorMessage.hpp"
Expand Down Expand Up @@ -60,6 +61,44 @@ void create_error_buffer(
packer.pack(message);
}

auto response_get_result_buffers(msgpack::sbuffer const& buffer
) -> std::optional<std::vector<msgpack::sbuffer>> {
// NOLINTBEGIN(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic)
try {
std::vector<msgpack::sbuffer> result_buffers;
msgpack::object_handle const handle = msgpack::unpack(buffer.data(), buffer.size());
msgpack::object const object = handle.get();

if (msgpack::type::ARRAY != object.type || object.via.array.size < 2) {
spdlog::error("Cannot split result into buffers: Wrong type");
return std::nullopt;
}

if (worker::TaskExecutorResponseType::Result
!= object.via.array.ptr[0].as<worker::TaskExecutorResponseType>())
{
spdlog::error(
"Cannot split result into buffers: Wrong response type {}",
static_cast<std::underlying_type_t<worker::TaskExecutorResponseType>>(
object.via.array.ptr[0].as<worker::TaskExecutorResponseType>()
)
);
return std::nullopt;
}

for (size_t i = 1; i < object.via.array.size; ++i) {
msgpack::object const& obj = object.via.array.ptr[i];
result_buffers.emplace_back();
msgpack::pack(result_buffers.back(), obj);
}
return result_buffers;
} catch (msgpack::type_error& e) {
spdlog::error("Cannot split result into buffers: {}", e.what());
return std::nullopt;
}
// NOLINTEND(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic)
}

auto FunctionManager::get_function(std::string const& name) const -> Function const* {
if (auto const func_iter = m_function_map.find(name); func_iter != m_function_map.end()) {
return &(func_iter->second);
Expand Down
40 changes: 2 additions & 38 deletions src/spider/worker/FunctionManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <absl/container/flat_hash_map.h>
#include <boost/uuid/uuid.hpp>
#include <fmt/format.h>
#include <spdlog/spdlog.h>

#include "../client/Data.hpp"
#include "../client/task.hpp"
Expand Down Expand Up @@ -162,43 +161,8 @@ auto response_get_result(msgpack::sbuffer const& buffer) -> std::optional<std::t
// NOLINTEND(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic)
}

inline auto response_get_result_buffers(msgpack::sbuffer const& buffer
) -> std::optional<std::vector<msgpack::sbuffer>> {
// NOLINTBEGIN(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic)
try {
std::vector<msgpack::sbuffer> result_buffers;
msgpack::object_handle const handle = msgpack::unpack(buffer.data(), buffer.size());
msgpack::object const object = handle.get();

if (msgpack::type::ARRAY != object.type || object.via.array.size < 2) {
spdlog::error("Cannot split result into buffers: Wrong type");
return std::nullopt;
}

if (worker::TaskExecutorResponseType::Result
!= object.via.array.ptr[0].as<worker::TaskExecutorResponseType>())
{
spdlog::error(
"Cannot split result into buffers: Wrong response type {}",
static_cast<std::underlying_type_t<worker::TaskExecutorResponseType>>(
object.via.array.ptr[0].as<worker::TaskExecutorResponseType>()
)
);
return std::nullopt;
}

for (size_t i = 1; i < object.via.array.size; ++i) {
msgpack::object const& obj = object.via.array.ptr[i];
result_buffers.emplace_back();
msgpack::pack(result_buffers.back(), obj);
}
return result_buffers;
} catch (msgpack::type_error& e) {
spdlog::error("Cannot split result into buffers: {}", e.what());
return std::nullopt;
}
// NOLINTEND(cppcoreguidelines-pro-type-union-access,cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
auto response_get_result_buffers(msgpack::sbuffer const& buffer
) -> std::optional<std::vector<msgpack::sbuffer>>;

template <TaskIo T>
auto create_result_response(T const& t) -> msgpack::sbuffer {
Expand Down
10 changes: 5 additions & 5 deletions tests/worker/worker-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <random>
#include <stdexcept>

#include "../../src/spider/client/Data.hpp"
#include "../../src/spider/client/Driver.hpp"
#include "../../src/spider/client/Job.hpp"
#include "../../src/spider/client/TaskContext.hpp"
#include "../../src/spider/client/TaskGraph.hpp"
#include <spider/client/Data.hpp>
#include <spider/client/Driver.hpp>
#include <spider/client/Job.hpp>
#include <spider/client/TaskContext.hpp>
#include <spider/client/TaskGraph.hpp>

auto sum_test(spider::TaskContext& /*context*/, int const x, int const y) -> int {
std::cerr << x << " + " << y << " = " << x + y << "\n";
Expand Down
4 changes: 2 additions & 2 deletions tests/worker/worker-test.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SPIDER_TEST_WORKER_TEST_HPP
#define SPIDER_TEST_WORKER_TEST_HPP

#include "../../src/spider/client/Data.hpp"
#include "../../src/spider/client/TaskContext.hpp"
#include <spider/client/Data.hpp>
#include <spider/client/TaskContext.hpp>

auto sum_test(spider::TaskContext& /*context*/, int x, int y) -> int;

Expand Down