proxy-wasm/proxy-wasm-cpp-host

Add a thread agnostic class to manage wasm vms and plugins

chaoqin-li1123 opened this issue · 0 comments

Currently, getOrCreateThreadLocalWasm and getOrCreateThreadLocalPlugin use two static thread local hash maps to bookkeep the existing healthy wasm vms and wasm plugins. This is not compatible with envoy's thread local slot and prevent the wasm lifetime management code to be reused. It maybe cleaner to refactor the management of wasm vm and plugin into a WasmManager class which is thread agnostic and manage the lifetime of wasm vm and wasm plugins. Then the WasmManager can be use as a thread local variable in a more flexible way and we can put all the wasm management code there. The class can has interface that looks like

class WasmManager {
  WasmHandleSharedPtr getWasm(string vm_key);
  WasmHandleSharedPtr createWasm(string vm_key, ...);
  PluginHandleSharedPtr getPlugin(string vm_key, string plugin_key);
  PluginHandleSharedPtr createPlugin(wasm_handle, plugin, ...);
private:
  hash_map<string, WasmHandleSharedPtr> wasms_;
  hash_map<string, PluginHandleSharedPtr> plugins_;
};