Add Plugin hot-plug: PluginManager, versioned state ABI, file watching
Backward-compatible C ABI v2 (Plugin.hpp; ABI_VERSION unchanged, IPlugin vtable frozen): optional void_plugin_state_version / serialize_state / free_string / deserialize_state(inst, json, from_version). State transfer prefers serialize->deserialize (survives layout changes; migrations live in the new .so via Json::MigrationChain), falling back to the existing transfer_state, then no-op. PluginLoader::reload gains this chain; the shared transfer_plugin_state helper drives it. Existing ABI-v1 plugins (TestPlugin) load and reload unchanged. PluginManager (Manager.hpp/.cpp): multi-plugin registry with RCU-style pinned handles. acquire(name) is one atomic<shared_ptr> load returning a PluginHandle that keeps its instance alive for the whole call. reload() is transactional: build new instance, transfer state from old, then atomic-exchange it in; on any failure the old instance stays. In-flight handles keep the old instance and its mapped .so alive (dlclose_on_swap= false) until they drop, so work never stops and callers never see a torn or freed object. watch(name) auto-reloads via FileSystem::FileWatcher (debounced); on_reloaded fires after each swap. Reload-safety: dlopen of a fresh-inode hotswap copy is required to load new bytes; deployments must install the new .so by atomic rename, never in-place overwrite of the mapped file (corrupts the running mapping -> SIGBUS). Documented; tests install via copy-to-.incoming + rename. Tests: StatefulPluginV1/V2 (shared IStateful interface, atomic counter; v2 adds a field and migrates v1 JSON). Manager.cpp covers load/acquire, v1->v2 migration, pinned-handle-survives-reload, legacy transfer_state fallback, and watch auto-reload. HotReloadUnderLoad.cpp: 6 reader threads calling through acquire() while 24 v1<->v2 reloads run concurrently -- zero crashes, state survives every migration, ASan+UBSan clean, stable across 10+ runs. 965 tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
697e07843c
commit
b343bce396
13 files changed
+1179
-38
No files matched your search
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Plugin/Plugin.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
// Shared interface for the stateful hot-reload test plugins. The host
|
||||
// holds an IPlugin*; because every stateful plugin's concrete type derives
|
||||
// from IStateful through a single-inheritance chain, the host recovers the
|
||||
// richer interface with static_cast (dynamic_cast is unreliable across
|
||||
// RTLD_LOCAL boundaries). The vtable layout is identical on both sides as
|
||||
// long as this header is shared — which it is.
|
||||
namespace VoidTest
|
||||
{
|
||||
class IStateful : public Void::Plugin::IPlugin
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] virtual int counter() const = 0;
|
||||
virtual void bump() = 0;
|
||||
[[nodiscard]] virtual int schema_version() const = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline IStateful* as_stateful(Void::Plugin::IPlugin* p)
|
||||
{
|
||||
return static_cast<IStateful*>(p);
|
||||
}
|
||||
} // namespace VoidTest
|
||||
Reference in new issue
Block a user