Allow to create OSD with mocked blockstore and network
This commit is contained in:
+28
-4
@@ -2,14 +2,22 @@ cmake_minimum_required(VERSION 2.8...3.30)
|
||||
|
||||
project(vitastor)
|
||||
|
||||
# vitastor-osd
|
||||
add_executable(vitastor-osd
|
||||
osd_main.cpp osd.cpp osd_secondary.cpp osd_peering.cpp osd_flush.cpp osd_peering_pg.cpp
|
||||
# libosd
|
||||
add_library(osd STATIC
|
||||
osd.cpp osd_secondary.cpp osd_peering.cpp osd_flush.cpp osd_peering_pg.cpp
|
||||
osd_primary.cpp osd_primary_chain.cpp osd_primary_sync.cpp osd_primary_write.cpp osd_primary_subops.cpp
|
||||
osd_cluster.cpp osd_rmw.cpp osd_scrub.cpp osd_primary_describe.cpp
|
||||
)
|
||||
target_link_libraries(osd pthread)
|
||||
target_compile_options(osd PUBLIC -fPIC)
|
||||
|
||||
# vitastor-osd
|
||||
add_executable(vitastor-osd
|
||||
osd_main.cpp
|
||||
)
|
||||
target_link_libraries(vitastor-osd
|
||||
vitastor_common
|
||||
osd
|
||||
vitastor_net
|
||||
vitastor_blk
|
||||
Jerasure
|
||||
${ISAL_LIBRARIES}
|
||||
@@ -17,6 +25,22 @@ target_link_libraries(vitastor-osd
|
||||
${RDMACM_LIBRARIES}
|
||||
)
|
||||
|
||||
# osd_test
|
||||
add_executable(osd_test
|
||||
EXCLUDE_FROM_ALL
|
||||
../test/osd_test.cpp
|
||||
../client/etcd_state_client_mock.cpp
|
||||
../blockstore/blockstore_mock.cpp
|
||||
../test/mock/messenger.cpp
|
||||
../test/ringloop_mock.cpp
|
||||
)
|
||||
target_link_libraries(osd_test
|
||||
osd
|
||||
vitastor_common
|
||||
Jerasure
|
||||
${ISAL_LIBRARIES}
|
||||
)
|
||||
|
||||
# osd_rmw_test
|
||||
add_executable(osd_rmw_test EXCLUDE_FROM_ALL osd_rmw_test.cpp ../util/allocator.cpp)
|
||||
target_link_libraries(osd_rmw_test Jerasure ${ISAL_LIBRARIES})
|
||||
|
||||
+4
-2
@@ -15,7 +15,8 @@
|
||||
#include "str_util.h"
|
||||
#include "json_util.h"
|
||||
|
||||
osd_t::osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager_t *tfd, std::unique_ptr<etcd_state_client_t> st_cli_ptr)
|
||||
osd_t::osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager_t *tfd,
|
||||
std::unique_ptr<etcd_state_client_t> st_cli_ptr, std::function<blockstore_i*(blockstore_config_t & config)> bs_factory)
|
||||
{
|
||||
zero_buffer_size = 1<<20;
|
||||
zero_buffer = malloc_or_die(zero_buffer_size);
|
||||
@@ -24,6 +25,7 @@ osd_t::osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager
|
||||
this->ringloop = ringloop;
|
||||
this->tfd = tfd;
|
||||
this->st_cli = std::move(st_cli_ptr);
|
||||
this->bs_factory = bs_factory;
|
||||
|
||||
this->cli_config = config.object_items();
|
||||
this->file_config = msgr.read_config(this->cli_config);
|
||||
@@ -115,7 +117,7 @@ void osd_t::init_blockstore(std::function<void()> on_init)
|
||||
if (!json_is_true(this->config["disable_blockstore"]))
|
||||
{
|
||||
auto bs_cfg = json_to_string_map(this->config);
|
||||
this->bs = blockstore_i::create(bs_cfg, ringloop, tfd);
|
||||
this->bs = bs_factory(bs_cfg);
|
||||
// Pre-configure pool PG shards
|
||||
for (auto & pool_item: st_cli->pool_config)
|
||||
{
|
||||
|
||||
+3
-1
@@ -153,6 +153,7 @@ class osd_t
|
||||
// cluster state
|
||||
|
||||
std::unique_ptr<etcd_state_client_t> st_cli;
|
||||
std::function<blockstore_i*(blockstore_config_t & config)> bs_factory;
|
||||
osd_messenger_t msgr;
|
||||
int etcd_failed_attempts = 0;
|
||||
std::string etcd_lease_id;
|
||||
@@ -390,7 +391,8 @@ class osd_t
|
||||
}
|
||||
|
||||
public:
|
||||
osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager_t *tfd, std::unique_ptr<etcd_state_client_t> st_cli_ptr);
|
||||
osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager_t *tfd, std::unique_ptr<etcd_state_client_t> st_cli_ptr,
|
||||
std::function<blockstore_i*(blockstore_config_t & config)> bs_factory);
|
||||
~osd_t();
|
||||
void force_stop(int exitcode);
|
||||
bool shutdown();
|
||||
|
||||
@@ -67,7 +67,13 @@ int main(int narg, char *args[])
|
||||
ring_loop_t *ringloop = new ring_loop_t(RINGLOOP_DEFAULT_SIZE);
|
||||
epoll_manager_t *epmgr = new epoll_manager_t(ringloop);
|
||||
auto st_cli = new etcd_state_client_http_t(epmgr->tfd);
|
||||
osd = new osd_t(config, ringloop, epmgr->tfd, std::unique_ptr<etcd_state_client_t>(st_cli));
|
||||
osd = new osd_t(
|
||||
config, ringloop, epmgr->tfd, std::unique_ptr<etcd_state_client_t>(st_cli),
|
||||
[ringloop, tfd = epmgr->tfd](blockstore_config_t & cfg)
|
||||
{
|
||||
return blockstore_i::create(cfg, ringloop, tfd);
|
||||
}
|
||||
);
|
||||
while (1)
|
||||
{
|
||||
ringloop->loop();
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// License: VNPL-1.1 (see README.md for details)
|
||||
|
||||
#include "osd.h"
|
||||
#ifdef WITH_RDMA
|
||||
#include "msgr_rdma.h"
|
||||
#endif
|
||||
|
||||
#include "json11/json11.hpp"
|
||||
|
||||
@@ -365,12 +362,11 @@ void osd_t::exec_show_config(osd_op_t *cur_op)
|
||||
if (req_json["connect_rdma"].is_string())
|
||||
{
|
||||
// Peer is trying to connect using RDMA, try to satisfy him
|
||||
bool ok = msgr.connect_rdma(cur_op->client_id, req_json["connect_rdma"].string_value(), req_json["rdma_max_msg"].uint64_value());
|
||||
if (ok)
|
||||
json11::Json data = msgr.connect_rdma(cur_op->client_id, req_json["connect_rdma"].string_value(), req_json["rdma_max_msg"].uint64_value());
|
||||
if (!data.is_null())
|
||||
{
|
||||
auto rc = cl->rdma_conn;
|
||||
wire_config["rdma_address"] = rc->addr.to_string();
|
||||
wire_config["rdma_max_msg"] = rc->max_msg;
|
||||
for (auto & kv: data.object_items())
|
||||
wire_config[kv.first] = kv.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user