-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Objective
To migrate the existing myvector MySQL plugin to the MySQL Component Infrastructure. This will improve modularity, align with modern MySQL architecture, and ensure future compatibility, as the traditional plugin infrastructure is being deprecated.
1. Analysis of the Existing Plugin Architecture
The current implementation is a multi-purpose audit plugin with the following key functionalities:
- Query Rewriting: It uses the
MYSQL_AUDIT_PARSE_PREPARSEaudit event hook inmyvector_plugin.ccto intercept and rewrite SQL statements containingMYVECTORannotations (e.g.,CREATE TABLE ... MYVECTOR(...),... WHERE MYVECTOR_IS_ANN(...)). - User-Defined Functions (UDFs): It registers several UDFs, whose logic resides in
myvector.cc. These includemyvector_construct,myvector_display,myvector_distance, andmyvector_ann_set, which are the primary user interface for vector operations. - Background Binlog Processing: It starts a background thread (
myvector_binlog_loopinmyvector_binlog.cc) to monitor the binary log. This enables "online" vector indexes to be updated automatically in response to DML operations on base tables. - Configuration: It uses global system variables (e.g.,
myvector_index_dir,myvector_config_file) declared withMYSQL_SYSVARfor configuration. - Build System: It uses the
MYSQL_ADD_PLUGINmacro inCMakeLists.txtfor compilation and linking.
2. Proposed Component Architecture
The monolithic plugin will be decomposed into a single component that provides several distinct services. This modular approach is the core benefit of the component infrastructure.
- Main Component (
myvector_component.cc): This will be the main entry point. It will manage the component's lifecycle (init/deinit) and register the various services below. - Manifest File (
myvector.json): A required JSON file that describes the component to the MySQL server. - Query Rewriter Service: A dedicated service implementing the
mysql::Query_rewriter_serviceinterface. This is the modern, official way to perform query rewriting, replacing the general-purpose audit hook. - Binlog Monitoring Service: A background service that encapsulates the binlog monitoring thread. Its lifecycle (start/stop) will be managed by the main component. All state (MySQL connection, binlog position, etc.) will be contained within this service.
- UDF Service: A service responsible for registering and deregistering all
myvectorUDFs using themysql_udf_metadataservice provided by the server.
3. Detailed Implementation Plan
Here is a step-by-step plan for the migration:
Step 1: Project Scaffolding
- Create New Directory: Create a new directory,
src/component_src, to house all new files related to the component. This keeps the new architecture separate from the legacy plugin code during development. - Create Manifest File: Create
src/component_src/myvector.json. This file will contain essential metadata.{ "name": "myvector", "description": "Vector Storage & Search Component for MySQL", "license": "GPL", "version": "1.3.0" }
Step 2: Core Component and Service Implementation
- Main Component File: Create
src/component_src/myvector_component.cc. This file will contain the component's main lifecycle functions (myvector_component_init,myvector_component_deinit) and the component declaration (mysql_declare_component). - Query Rewriter Service:
- Create
src/component_src/myvector_query_rewrite_service.cc. - Implement a class that inherits from
mysql::Query_rewriter_service. - Move the query rewriting logic from
myvector_sql_preparseinto therewrite_querymethod of this new class. - Register the service using the
SERVICE_REGISTRATIONmacro.
- Create
- Binlog Monitoring Service:
- Create
src/component_src/myvector_binlog_service.hto define the service interface withstart_binlog_monitoring()andstop_binlog_monitoring()methods. - Create
src/component_src/myvector_binlog_service.cc. - Move the logic from
myvector_binlog_loopand related functions/globals fromsrc/myvector_binlog.ccinto the implementation of this service class. The thread and its state will become private members of the class. - The
startmethod will launch the thread, andstopwill signal it to terminate and join.
- Create
- UDF Service:
- Create
src/component_src/myvector_udf_service.hto define the service interface. - Create
src/component_src/myvector_udf_service.cc. - Move all UDF implementation functions from
src/myvector.ccinto this file. - Remove the
PLUGIN_EXPORTmacros. - Implement
register_udfsandderegister_udfsmethods that use the server'smysql_udf_metadataservice to manage the UDFs.
- Create
Step 3: Integration and Refactoring
- Integrate Services: Update
src/component_src/myvector_component.cc:- In
myvector_component_init, get themysql_udf_metadataservice and call theregister_udfsmethod from the UDF service. Then, call thestart_binlog_monitoringmethod from the binlog service. - In
myvector_component_deinit, callderegister_udfsandstop_binlog_monitoring. - Add all implemented services to the
mysql_declare_componentdescriptor block.
- In
- Refactor Configuration:
- Remove the
MYSQL_SYSVARdeclarations frommyvector_plugin.cc. - The configuration file (
myvector.cnf) loading logic will be explicitly called during the component'sinitphase. The loaded values will be passed to or stored within the services that need them, eliminating the need for global system variables.
- Remove the
Step 4: Update the Build System
- Modify
CMakeLists.txt:- Remove the
MYSQL_ADD_PLUGIN(...)block. - Add a new
add_library(myvector_component SHARED ...)command. - The source files for the library will include all new
src/component_src/*.ccfiles plus the existing core logic files (src/myvector.cc,src/myvectorutils.cc, etc.). The oldsrc/myvector_plugin.ccwill be excluded. - Add
install(TARGETS myvector_component ...)to install the shared library to the correct MySQL directory (e.g.,lib/plugin). - Add
install(FILES src/component_src/myvector.json ...)to install the manifest file.
- Remove the
Step 5: Testing Strategy
- Build: Compile the project using
cmakeandmake. - Installation: In a test MySQL 8.0+ instance, place the compiled
myvector_component.soandmyvector.jsonin the appropriate directories. - Activation: Connect to MySQL and run
INSTALL COMPONENT 'file://myvector'. Verify success by checking the MySQL error log and querying themysql.componenttable. - Functional Verification:
- Execute SQL queries to test each registered UDF.
- Test the query rewriting by running
CREATE TABLEandSELECTstatements withMYVECTORannotations. - Test the binlog service by creating a table with an
online=Yindex, performing DML, and querying the index to verify it was updated.
- Deactivation: Run
UNINSTALL COMPONENT 'file://myvector'and confirm that the component is cleanly unloaded and all UDFs are deregistered.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels