Add a basic OSD test as an example

This commit is contained in:
Vitaliy Filippov
2026-06-13 19:56:06 +03:00
parent 27bd38d95e
commit 91698404a7
12 changed files with 543 additions and 37 deletions
+3
View File
@@ -39,7 +39,10 @@ target_link_libraries(osd_test
vitastor_common
Jerasure
${ISAL_LIBRARIES}
${LIBURING_LIBRARIES}
)
add_test(NAME osd_test COMMAND osd_test)
add_dependencies(build_tests osd_test)
# osd_rmw_test
add_executable(osd_rmw_test EXCLUDE_FROM_ALL osd_rmw_test.cpp ../util/allocator.cpp)
+17 -9
View File
@@ -30,7 +30,10 @@ osd_t::osd_t(const json11::Json & config, ring_loop_i *ringloop, timerfd_manager
this->cli_config = config.object_items();
this->file_config = msgr.read_config(this->cli_config);
parse_config(true);
}
void osd_t::start()
{
if (json_is_true(this->config["osd_memlock"]))
{
// Lock all OSD memory if requested
@@ -130,17 +133,22 @@ void osd_t::init_blockstore(std::function<void()> on_init)
autosync_writes = max_autosync;
if (on_init)
{
init_consumer.loop = [this, on_init]()
if (bs->is_started())
on_init();
else
{
// Wait for blockstore initialisation before actually starting OSD logic
// to prevent peering timeouts during restart with filled databases
if (bs->is_started())
init_consumer.loop = [this, on_init]()
{
ringloop->set_immediate([this, on_init] { init_consumer.loop = NULL; on_init(); });
ringloop->unregister_consumer(&init_consumer);
}
};
ringloop->register_consumer(&init_consumer);
// Wait for blockstore initialisation before actually starting OSD logic
// to prevent peering timeouts during restart with filled databases
if (bs->is_started())
{
ringloop->set_immediate([this, on_init] { init_consumer.loop = NULL; on_init(); });
ringloop->unregister_consumer(&init_consumer);
}
};
ringloop->register_consumer(&init_consumer);
}
}
}
else if (on_init)
+9
View File
@@ -97,8 +97,12 @@ struct osd_pg_lock_t
uint64_t state = 0;
};
struct osd_test_fixture_t;
class osd_t
{
friend struct osd_test_fixture_t;
// config
json11::Json::object cli_config, file_config, etcd_global_config, etcd_osd_config, config;
@@ -394,6 +398,11 @@ 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,
std::function<blockstore_i*(blockstore_config_t & config)> bs_factory);
~osd_t();
// Wire the OSD into the world: install timers, hook the messenger up to
// ringloop, register as a ringloop consumer, and kick off the etcd
// config-load chain. Separated from the constructor so tests can build
// an inert osd_t, prime mocks, then drive startup explicitly.
void start();
void force_stop(int exitcode);
bool shutdown();
};
+1
View File
@@ -74,6 +74,7 @@ int main(int narg, char *args[])
return blockstore_i::create(cfg, ringloop, tfd);
}
);
osd->start();
while (1)
{
ringloop->loop();