11import EventEmitter from "events" ;
22import { RedisClientOptions } from "." ;
33import RedisCommandsQueue from "./commands-queue" ;
4- import RedisSocket , { RedisSocketOptions , RedisTcpSocketOptions } from "./socket" ;
4+ import RedisSocket from "./socket" ;
55import { RedisArgument } from "../.." ;
66import { isIP } from "net" ;
77import { lookup } from "dns/promises" ;
@@ -25,6 +25,11 @@ export interface SocketTimeoutUpdate {
2525 timeout ?: number ;
2626}
2727
28+ export const dbgMaintenance = ( ...args : any [ ] ) => {
29+ if ( ! process . env . DEBUG_MAINTENANCE ) return ;
30+ return console . log ( '[MNT]' , ...args ) ;
31+ }
32+
2833export default class EnterpriseMaintenanceManager extends EventEmitter {
2934 #commandsQueue: RedisCommandsQueue ;
3035 #options: RedisClientOptions ;
@@ -47,16 +52,19 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
4752 case PN . MOVING : {
4853 const [ _ , afterMs , url ] = push ;
4954 const [ host , port ] = url . toString ( ) . split ( ":" ) ;
55+ dbgMaintenance ( 'Received MOVING:' , afterMs , host , Number ( port ) ) ;
5056 this . #onMoving( afterMs , host , Number ( port ) ) ;
5157 return true ;
5258 }
5359 case PN . MIGRATING :
5460 case PN . FAILING_OVER : {
61+ dbgMaintenance ( 'Received MIGRATING|FAILING_OVER' ) ;
5562 this . #onMigrating( ) ;
5663 return true ;
5764 }
5865 case PN . MIGRATED :
5966 case PN . FAILED_OVER : {
67+ dbgMaintenance ( 'Received MIGRATED|FAILED_OVER' ) ;
6068 this . #onMigrated( ) ;
6169 return true ;
6270 }
@@ -83,6 +91,7 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
8391 ) : Promise < void > => {
8492 // 1 [EVENT] MOVING PN received
8593 // 2 [ACTION] Pause writing
94+ dbgMaintenance ( 'Pausing writing of new commands to old socket' ) ;
8695 this . emit ( MAINTENANCE_EVENTS . PAUSE_WRITING ) ;
8796 this . #onMigrating( ) ;
8897
@@ -93,13 +102,18 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
93102 } ) ;
94103 //todo
95104 newSocket . setMaintenanceTimeout ( ) ;
105+ dbgMaintenance ( `Connecting to new socket: ${ host } :${ port } ` ) ;
96106 await newSocket . connect ( ) ;
107+ dbgMaintenance ( `Connected to new socket` ) ;
97108 // 3 [EVENT] New socket connected
98109
110+ dbgMaintenance ( `Wait for all in-flight commands to complete` ) ;
99111 await this . #commandsQueue. waitForInflightCommandsToComplete ( ) ;
112+ dbgMaintenance ( `In-flight commands completed` ) ;
100113 // 4 [EVENT] In-flight commands completed
101114
102115 // 5 + 6
116+ dbgMaintenance ( 'Resume writing' )
103117 this . emit ( MAINTENANCE_EVENTS . RESUME_WRITING , newSocket ) ;
104118 this . #onMigrated( ) ;
105119 } ;
0 commit comments