Add settings to disable/enable MySQL/PostgreSQL module - Closes #4951
JA
1y ago+1250+1250+0123456789012345678901234567890123456789-52-52-01234567890123456789
PR 4960: Comprehensive MySQL/PostgreSQL Module Control
Main Purpose
This PR implements fine-grained control over ProxySQL's MySQL and PostgreSQL modules, allowing users to selectively enable or disable specific components via CLI arguments or configuration file settings. This addresses issue #4951 and provides better resource management and customization capabilities.
New CLI Arguments Added
--mysql-workers <true|false>: Enable/disable MySQL worker threads--pgsql-workers <true|false>: Enable/disable PostgreSQL worker threads--mysql-admin <true|false>: Enable/disable MySQL admin interface--pgsql-admin <true|false>: Enable/disable PostgreSQL admin interface--mysql-monitor <true|false>: Enable/disable MySQL monitor module--pgsql-monitor <true|false>: Enable/disable PostgreSQL monitor module
Configuration File Support
Corresponding boolean settings can be specified in the ProxySQL configuration file:
mysql-workers=true
mysql-admin=true
mysql-monitor=true
pgsql-workers=true
pgsql-admin=true
pgsql-monitor=true
Core Implementation Features
1. Selective Module Startup
- Worker Threads: Controls whether MySQL and/or PostgreSQL worker threads are created
- Admin Interfaces: Manages which admin interfaces (MySQL and/or PostgreSQL) listen for connections
- Monitor Modules: Controls whether MySQL and/or PostgreSQL monitoring threads are started
2. Intelligent Thread Management
- MySQL Workers: When disabled, no MySQL worker threads are created, reducing resource usage
- PostgreSQL Workers: When disabled, no PostgreSQL worker threads are created
- Admin Interfaces: Each interface can be independently enabled/disabled
- Monitor Modules: Each monitor runs independently based on its setting
3. Admin Interface Variable Synchronization
- Critical Fix: Added synchronization between internal global variables and admin interface variables
mysql-monitor_enabled: Now accurately reflects--mysql-monitorCLI argument statepgsql-monitor_enabled: Now accurately reflects--pgsql-monitorCLI argument state- Ensures admin interface queries return correct module status
Resource Management Benefits
- Reduced Memory Usage: Disabled modules don't allocate memory for threads and data structures
- Lower CPU Usage: No background processing for disabled modules
- Faster Startup: Skip initialization of disabled components
- Customizable Deployments: Run only the modules you need
Use Cases Enabled
- MySQL-Only Deployments: Disable all PostgreSQL modules for pure MySQL environments
- PostgreSQL-Only Deployments: Disable all MySQL modules for pure PostgreSQL environments
- Admin-Only Mode: Run admin interfaces without worker threads for configuration management
- Monitor-Only Mode: Run monitoring without proxying capabilities
- Resource-Constrained Environments: Disable unnecessary modules to save resources
Comprehensive Testing Coverage
Worker/Admin Module Tests (reg_test_4960_modules_startup-t)
- 16 test combinations covering all possible enable/disable states
- Port binding verification ensures interfaces start/stop correctly
- CLI argument and config file validation
- Tests each combination: MySQL workers, PgSQL workers, MySQL admin, PgSQL admin
Monitor Module Tests (reg_test_4960_monitor_modules-t)
- 4 test combinations for monitor module states
- Database validation via admin interface variables
- Synchronization verification between CLI args and runtime state
Technical Implementation Details
- Global Variables: Added
mysql_workers,pgsql_workers,mysql_admin,pgsql_admintoProxySQL_GlobalVariables - Thread Control Logic: Modified thread creation loops to respect module enable/disable flags
- Admin Interface Management: Updated interface initialization to check module flags
- Configuration Processing: Added CLI argument parsing and config file reading
- Coherence Checks: Added logging for module state consistency
- Variable Synchronization: Fixed admin interface to reflect actual module state
Backward Compatibility
- All modules are enabled by default, maintaining existing behavior
- No breaking changes to existing configurations
- Graceful degradation when modules are disabled
- Clear error messages and logging for troubleshooting
Documentation and Monitoring
- Informative Logging: Module status logged during startup
- Admin Interface Visibility: Module status queryable via
global_variablestable - Runtime Status: Monitor module state accessible through admin interface
This implementation provides ProxySQL administrators with unprecedented control over which components run, enabling more efficient resource utilization and customized deployment scenarios while maintaining full backward compatibility.