@@ -44,6 +44,9 @@ const schemaChangeTypes = {
4444const supportedProductTypeKey = 'PRODUCT_TYPE' ;
4545const supportedDbaas = 'DATASTAX_APOLLO' ;
4646
47+ // Process-wide counter used to give each ControlConnection a stable id for log correlation
48+ let controlConnectionCounter = 0 ;
49+
4750/**
4851 * Represents a connection used by the driver to receive events and to check the status of the cluster.
4952 * <p>It uses an existing connection from the hosts' connection pool to maintain the driver metadata up-to-date.</p>
@@ -92,7 +95,8 @@ class ControlConnection extends events.EventEmitter {
9295
9396 // Reference to the encoder of the last valid connection
9497 this . _encoder = null ;
95- this . _debouncer = new EventDebouncer ( options . refreshSchemaDelay , this . log . bind ( this ) ) ;
98+ this . _id = ++ controlConnectionCounter ;
99+ this . _debouncer = new EventDebouncer ( options . refreshSchemaDelay , this . log . bind ( this ) , this . _id ) ;
96100 this . _profileManager = profileManager ;
97101 this . _triedHosts = null ;
98102 this . _resolvedContactPoints = new Map ( ) ;
@@ -579,6 +583,7 @@ class ControlConnection extends events.EventEmitter {
579583 this . connection . on ( 'nodeTopologyChange' , this . _nodeTopologyChangeHandler . bind ( this ) ) ;
580584 this . connection . on ( 'nodeStatusChange' , this . _nodeStatusChangeHandler . bind ( this ) ) ;
581585 this . connection . on ( 'nodeSchemaChange' , this . _nodeSchemaChangeHandler . bind ( this ) ) ;
586+ console . log ( `[cc ${ this . _id } ] Listener count on ${ this . connection . endpointFriendlyName } : ${ this . connection . listenerCount ( 'nodeSchemaChange' ) } ` ) ;
582587 const request = new requests . RegisterRequest ( [ 'TOPOLOGY_CHANGE' , 'STATUS_CHANGE' , 'SCHEMA_CHANGE' ] ) ;
583588 await this . connection . send ( request , null ) ;
584589 }
@@ -633,7 +638,7 @@ class ControlConnection extends events.EventEmitter {
633638 * Handles a SCHEMA_CHANGE event
634639 */
635640 _nodeSchemaChangeHandler ( event ) {
636- this . log ( 'info' , ' Schema change' , event ) ;
641+ this . log ( 'info' , `[cc ${ this . _id } ] Schema change` , event ) ;
637642 if ( ! this . options . isMetadataSyncEnabled ) {
638643 return ;
639644 }
@@ -659,10 +664,10 @@ class ControlConnection extends events.EventEmitter {
659664 delete self . metadata . keyspaces [ event . keyspace ] ;
660665 } ;
661666
662- return this . _scheduleObjectRefresh ( handler , event . keyspace , null , processNow ) ;
667+ return this . _scheduleObjectRefresh ( handler , event . keyspace , null , processNow , event ) ;
663668 }
664669
665- return this . _scheduleKeyspaceRefresh ( event . keyspace , processNow ) ;
670+ return this . _scheduleKeyspaceRefresh ( event . keyspace , processNow , event ) ;
666671 }
667672
668673 const ksInfo = this . metadata . keyspaces [ event . keyspace ] ;
@@ -713,19 +718,20 @@ class ControlConnection extends events.EventEmitter {
713718 * @param {Boolean } processNow
714719 * @returns {Promise<void> }
715720 */
716- _scheduleObjectRefresh ( handler , keyspace , cqlObject , processNow ) {
717- return this . _debouncer . eventReceived ( { handler, keyspace, cqlObject } , processNow ) ;
721+ _scheduleObjectRefresh ( handler , keyspace , cqlObject , processNow , event = null ) {
722+ return this . _debouncer . eventReceived ( { handler, keyspace, cqlObject, event } , processNow ) ;
718723 }
719724
720725 /**
721726 * @param {String } keyspace
722727 * @param {Boolean } processNow
723728 * @returns {Promise<void> }
724729 */
725- _scheduleKeyspaceRefresh ( keyspace , processNow ) {
730+ _scheduleKeyspaceRefresh ( keyspace , processNow , event = null ) {
726731 return this . _debouncer . eventReceived ( {
727732 handler : ( ) => this . metadata . refreshKeyspace ( keyspace ) ,
728- keyspace
733+ keyspace,
734+ event
729735 } , processNow ) ;
730736 }
731737
0 commit comments