Skip to content

Add server version validation during module loading #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

YueTang-Vanessa
Copy link
Contributor

@YueTang-Vanessa YueTang-Vanessa commented Feb 20, 2025

Check server version during module loading. If server version not satisfy minimal required version, module failed loading with message in log.

Testing

Manually Testing

Created 2 versions of valkey-server and valkey-cli:

  • server version 7.255.255 : make valkey/unstable locally with version.h updated to VALKEY_VERSION 7.255.255 and VALKEY_VERSION_NUM 0x0007FFFF.
  • server version 255.255.255: make valkey/unstable
Load module during server initialized

./valkey-server-7255255 --loadmodule /<path>/libvalkey_bloom.so
Sever aborting.
Output like following:

112072:M 20 Feb 2025 22:48:00.892 # WARNING Your system is configured to use the 'xen' clocksource which might lead to degraded performance. Check the result of the [slow-clocksource] system check: run 'valkey-server --check-system' to check if the system's clocksource isn't degrading performance.
112072:M 20 Feb 2025 22:48:00.892 * oO0OoO0OoO0Oo Valkey is starting oO0OoO0OoO0Oo
112072:M 20 Feb 2025 22:48:00.892 * Valkey version=7.255.255, bits=64, commit=54c4bbce, modified=1, pid=112072, just started
112072:M 20 Feb 2025 22:48:00.892 * Configuration loaded
112072:M 20 Feb 2025 22:48:00.892 * monotonic clock: POSIX clock_gettime
                .+^+.                                                
            .+#########+.                                            
        .+########+########+.           Valkey 7.255.255 (54c4bbce/1) 64 bit
    .+########+'     '+########+.                                    
 .########+'     .+.     '+########.    Running in standalone mode
 |####+'     .+#######+.     '+####|    Port: 6379
 |###|   .+###############+.   |###|    PID: 112072                     
 |###|   |#####*'' ''*#####|   |###|                                 
 |###|   |####'  .-.  '####|   |###|                                 
 |###|   |###(  (@@@)  )###|   |###|          https://valkey.io      
 |###|   |####.  '-'  .####|   |###|                                 
 |###|   |#####*.   .*#####|   |###|                                 
 |###|   '+#####|   |#####+'   |###|                                 
 |####+.     +##|   |#+'     .+####|                                 
 '#######+   |##|        .+########'                                 
    '+###|   |##|    .+########+'                                    
        '|   |####+########+'                                        
             +#########+'                                            
                '+v+'                                                

112072:M 20 Feb 2025 22:48:00.894 * Legacy Redis Module /<path>/libvalkey_bloom.so found
112072:M 20 Feb 2025 22:48:00.894 * <bf> Created new data type 'bloomfltr'
112072:M 20 Feb 2025 22:48:00.894 # <bf> Current server version doesn't satisfy minimal required version for bloom module!
112072:M 20 Feb 2025 22:48:00.894 # Module /<path>/libvalkey_bloom.so initialization failed. Module not loaded.
112072:M 20 Feb 2025 22:48:00.894 # Can't load module from /<path>/libvalkey_bloom.so: server aborting
Loading module via command module load

Client response with (error) ERR Error loading the extension. Please check the server logs.
Server initialized with error message in log,

110951:M 20 Feb 2025 22:46:36.914 * Server initialized
110951:M 20 Feb 2025 22:46:36.914 * Loading RDB produced by Valkey version 7.255.255
110951:M 20 Feb 2025 22:46:36.914 * RDB age 13 seconds
110951:M 20 Feb 2025 22:46:36.914 * RDB memory usage when created 0.93 Mb
110951:M 20 Feb 2025 22:46:36.914 * Done loading RDB, keys loaded: 0, keys expired: 0.
110951:M 20 Feb 2025 22:46:36.914 * DB loaded from disk: 0.000 seconds
110951:M 20 Feb 2025 22:46:36.914 * Ready to accept connections tcp
110951:M 20 Feb 2025 22:47:09.193 * Legacy Redis Module /<path>/libvalkey_bloom.so found
110951:M 20 Feb 2025 22:47:09.193 * <bf> Created new data type 'bloomfltr'
110951:M 20 Feb 2025 22:47:09.193 # <bf> Current server version doesn't satisfy minimal required version for bloom module!
110951:M 20 Feb 2025 22:47:09.193 # Module /<path>/libvalkey_bloom.so initialization failed. Module not loaded.

Integration Test

./build.sh successfully completed. All tests passed.

Status::Ok
fn initialize(ctx: &Context, _args: &[ValkeyString]) -> Status {
let ver = ctx
.get_redis_version()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a small change in the valkeymodule-rs crate to rename this to get_server_version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to valkeymodule-rs: valkey-io/valkeymodule-rs#178. Awaiting for the decision

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you

@KarthikSubbarao KarthikSubbarao merged commit 1e6c23b into valkey-io:unstable Mar 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants