@@ -205,70 +205,6 @@ impl NodeStore {
205205 }
206206 Ok ( ( ) )
207207 }
208- pub async fn migrate_existing_nodes ( & self ) -> Result < ( ) > {
209- let mut con = self . redis . client . get_multiplexed_async_connection ( ) . await ?;
210-
211- let mut cursor = 0 ;
212- loop {
213- let ( new_cursor, keys) : ( u64 , Vec < String > ) = redis:: cmd ( "SCAN" )
214- . cursor_arg ( cursor)
215- . arg ( "MATCH" )
216- . arg ( format ! ( "{}:*" , ORCHESTRATOR_BASE_KEY ) )
217- . arg ( "COUNT" )
218- . arg ( 100 )
219- . query_async ( & mut con)
220- . await ?;
221-
222- for key in keys {
223- if let Some ( address) = key. strip_prefix ( & format ! ( "{}:" , ORCHESTRATOR_BASE_KEY ) ) {
224- let _: ( ) = con. sadd ( ORCHESTRATOR_NODE_INDEX , address) . await ?;
225- }
226- }
227-
228- if new_cursor == 0 {
229- break ;
230- }
231- cursor = new_cursor;
232- }
233-
234- // Handle legacy keys with double colons (orchestrator:node::address)
235- let mut cursor = 0 ;
236- loop {
237- let ( new_cursor, keys) : ( u64 , Vec < String > ) = redis:: cmd ( "SCAN" )
238- . cursor_arg ( cursor)
239- . arg ( "MATCH" )
240- . arg ( "orchestrator:node::*" )
241- . arg ( "COUNT" )
242- . arg ( 100 )
243- . query_async ( & mut con)
244- . await ?;
245-
246- for key in keys {
247- if let Some ( address) = key. strip_prefix ( "orchestrator:node::" ) {
248- // Add to index
249- let _: ( ) = con. sadd ( ORCHESTRATOR_NODE_INDEX , address) . await ?;
250-
251- // Get the value from the old key
252- let value: Option < String > = con. get ( & key) . await ?;
253- if let Some ( value) = value {
254- // Set the value with the correct key format
255- let new_key = format ! ( "{}:{}" , ORCHESTRATOR_BASE_KEY , address) ;
256- let _: ( ) = con. set ( & new_key, value) . await ?;
257-
258- // Delete the old key with double colons
259- let _: ( ) = con. del ( & key) . await ?;
260- }
261- }
262- }
263-
264- if new_cursor == 0 {
265- break ;
266- }
267- cursor = new_cursor;
268- }
269-
270- Ok ( ( ) )
271- }
272208}
273209
274210#[ cfg( test) ]
@@ -277,7 +213,7 @@ mod tests {
277213 use crate :: models:: node:: NodeStatus ;
278214 use crate :: models:: node:: OrchestratorNode ;
279215 use alloy:: primitives:: Address ;
280- use redis :: AsyncCommands ;
216+
281217 use std:: str:: FromStr ;
282218
283219 #[ tokio:: test]
@@ -356,62 +292,4 @@ mod tests {
356292 Address :: from_str( "0x0000000000000000000000000000000000000003" ) . unwrap( )
357293 ) ;
358294 }
359-
360- #[ tokio:: test]
361- async fn test_migration_handles_double_colon_keys ( ) {
362- let app_state = create_test_app_state ( ) . await ;
363- let node_store = & app_state. store_context . node_store ;
364- let mut con = app_state
365- . store_context
366- . node_store
367- . redis
368- . client
369- . get_multiplexed_async_connection ( )
370- . await
371- . unwrap ( ) ;
372-
373- let test_address = "0x66295E2B4A78d1Cb57Db16Ac0260024900A5BA9B" ;
374- let test_node = OrchestratorNode {
375- address : Address :: from_str ( test_address) . unwrap ( ) ,
376- ip_address : "192.168.1.1" . to_string ( ) ,
377- port : 8080 ,
378- status : NodeStatus :: Healthy ,
379- ..Default :: default ( )
380- } ;
381-
382- // Manually create a legacy key with double colons
383- let legacy_key = format ! ( "orchestrator:node::{}" , test_address) ;
384- let _: ( ) = con. set ( & legacy_key, test_node. to_string ( ) ) . await . unwrap ( ) ;
385-
386- // Verify the legacy key exists
387- let exists: bool = con. exists ( & legacy_key) . await . unwrap ( ) ;
388- assert ! ( exists) ;
389-
390- // Run migration
391- node_store. migrate_existing_nodes ( ) . await . unwrap ( ) ;
392-
393- // Verify the legacy key is removed
394- let legacy_exists: bool = con. exists ( & legacy_key) . await . unwrap ( ) ;
395- assert ! ( !legacy_exists) ;
396-
397- // Verify the correct key exists
398- let correct_key = format ! ( "orchestrator:node:{}" , test_address) ;
399- let correct_exists: bool = con. exists ( & correct_key) . await . unwrap ( ) ;
400- assert ! ( correct_exists) ;
401-
402- // Verify the node is in the index
403- let in_index: bool = con
404- . sismember ( "orchestrator:node_index" , test_address)
405- . await
406- . unwrap ( ) ;
407- assert ! ( in_index) ;
408-
409- // Verify we can retrieve the node correctly
410- let retrieved_node = node_store
411- . get_node ( & Address :: from_str ( test_address) . unwrap ( ) )
412- . await
413- . unwrap ( ) ;
414- assert ! ( retrieved_node. is_some( ) ) ;
415- assert_eq ! ( retrieved_node. unwrap( ) . address, test_node. address) ;
416- }
417295}
0 commit comments