@@ -44,16 +44,12 @@ export class RdsHostListProvider implements DynamicHostListProvider {
4444 private initialHostList : HostInfo [ ] ;
4545 protected initialHost : HostInfo ;
4646 private refreshRateNano : number ;
47- private suggestedClusterIdRefreshRateNano : number = 10 * 60 * 1_000_000_000 ; // 10 minutes
4847 private hostList ?: HostInfo [ ] ;
4948 protected readonly connectionUrlParser : ConnectionUrlParser ;
5049 protected readonly hostListProviderService : HostListProviderService ;
5150
52- public static readonly suggestedPrimaryClusterIdCache : CacheMap < string , string > = new CacheMap < string , string > ( ) ;
53- public static readonly primaryClusterIdCache : CacheMap < string , boolean > = new CacheMap < string , boolean > ( ) ;
5451 public clusterId : string = Date . now ( ) . toString ( ) ;
5552 public isInitialized : boolean = false ;
56- public isPrimaryClusterId ?: boolean ;
5753 public clusterInstanceTemplate ?: HostInfo ;
5854
5955 constructor ( properties : Map < string , any > , originalUrl : string , hostListProviderService : HostListProviderService ) {
@@ -87,8 +83,6 @@ export class RdsHostListProvider implements DynamicHostListProvider {
8783 return ;
8884 }
8985
90- this . isPrimaryClusterId = false ;
91-
9286 const hostInfoBuilder = this . hostListProviderService . getHostInfoBuilder ( ) ;
9387
9488 this . clusterInstanceTemplate = hostInfoBuilder
@@ -98,29 +92,7 @@ export class RdsHostListProvider implements DynamicHostListProvider {
9892
9993 this . validateHostPatternSetting ( this . clusterInstanceTemplate . host ) ;
10094
101- const clusterIdSetting : string = WrapperProperties . CLUSTER_ID . get ( this . properties ) ;
102- if ( clusterIdSetting ) {
103- this . clusterId = clusterIdSetting ;
104- } else if ( this . rdsUrlType === RdsUrlType . RDS_PROXY ) {
105- // Each proxy is associated with a single cluster, so it's safe to use RDS Proxy Url as cluster
106- // identification
107- this . clusterId = this . initialHost . url ;
108- } else if ( this . rdsUrlType . isRds ) {
109- const clusterSuggestedResult : ClusterSuggestedResult | null = this . getSuggestedClusterId ( this . initialHost . hostAndPort ) ;
110- if ( clusterSuggestedResult && clusterSuggestedResult . clusterId ) {
111- this . clusterId = clusterSuggestedResult . clusterId ;
112- this . isPrimaryClusterId = clusterSuggestedResult . isPrimaryClusterId ;
113- } else {
114- const clusterRdsHostUrl : string | null = this . rdsHelper . getRdsClusterHostUrl ( this . initialHost . host ) ;
115- if ( clusterRdsHostUrl ) {
116- this . clusterId = this . clusterInstanceTemplate . isPortSpecified ( )
117- ? `${ clusterRdsHostUrl } :${ this . clusterInstanceTemplate . port } `
118- : clusterRdsHostUrl ;
119- this . isPrimaryClusterId = true ;
120- RdsHostListProvider . primaryClusterIdCache . put ( this . clusterId , true , this . suggestedClusterIdRefreshRateNano ) ;
121- }
122- }
123- }
95+ this . clusterId = WrapperProperties . CLUSTER_ID . get ( this . properties ) ;
12496
12597 this . isInitialized = true ;
12698 }
@@ -195,18 +167,11 @@ export class RdsHostListProvider implements DynamicHostListProvider {
195167 throw new AwsWrapperError ( "no cluster id" ) ;
196168 }
197169
198- const suggestedPrimaryClusterId : string | null = RdsHostListProvider . suggestedPrimaryClusterIdCache . get ( this . clusterId ) ;
199- if ( suggestedPrimaryClusterId && this . clusterId !== suggestedPrimaryClusterId ) {
200- this . clusterId = suggestedPrimaryClusterId ;
201- this . isPrimaryClusterId = true ;
202- }
203-
204170 const cachedHosts : HostInfo [ ] | null = this . getStoredTopology ( ) ;
205171
206172 // This clusterId is a primary one and is about to create a new entry in the cache.
207173 // When a primary entry is created it needs to be suggested for other (non-primary) entries.
208174 // Remember a flag to do suggestion after cache is updated.
209- const needToSuggest : boolean = ! cachedHosts && this . isPrimaryClusterId === true ;
210175 if ( ! cachedHosts || forceUpdate ) {
211176 // need to re-fetch the topology.
212177 if ( ! targetClient || ! ( await this . hostListProviderService . isClientValid ( targetClient ) ) ) {
@@ -216,9 +181,6 @@ export class RdsHostListProvider implements DynamicHostListProvider {
216181 const hosts = await this . queryForTopology ( targetClient , this . hostListProviderService . getDialect ( ) ) ;
217182 if ( hosts && hosts . length > 0 ) {
218183 this . storageService . set ( this . clusterId , new Topology ( hosts ) ) ;
219- if ( needToSuggest ) {
220- this . suggestPrimaryCluster ( hosts ) ;
221- }
222184 return new FetchTopologyResult ( false , hosts ) ;
223185 }
224186 }
@@ -230,63 +192,6 @@ export class RdsHostListProvider implements DynamicHostListProvider {
230192 }
231193 }
232194
233- private getSuggestedClusterId ( hostAndPort : string ) : ClusterSuggestedResult | null {
234- const cache : ExpirationCache < string , Topology > = this . storageService . getAll ( Topology ) as ExpirationCache < string , Topology > ;
235- if ( ! cache ) {
236- return null ;
237- }
238- for ( const [ key , hosts ] of cache . getEntries ( ) ) {
239- const isPrimaryCluster : boolean = RdsHostListProvider . primaryClusterIdCache . get ( key , false , this . suggestedClusterIdRefreshRateNano ) ?? false ;
240- if ( key === hostAndPort ) {
241- return new ClusterSuggestedResult ( hostAndPort , isPrimaryCluster ) ;
242- }
243-
244- if ( hosts ) {
245- for ( const hostInfo of hosts . hosts ) {
246- if ( hostInfo . hostAndPort === hostAndPort ) {
247- logger . debug ( Messages . get ( "RdsHostListProvider.suggestedClusterId" , key , hostAndPort ) ) ;
248- return new ClusterSuggestedResult ( key , isPrimaryCluster ) ;
249- }
250- }
251- }
252- }
253- return null ;
254- }
255-
256- suggestPrimaryCluster ( primaryClusterHosts : HostInfo [ ] ) : void {
257- if ( ! primaryClusterHosts ) {
258- return ;
259- }
260-
261- const primaryClusterHostUrls : Set < string > = new Set < string > ( ) ;
262- primaryClusterHosts . forEach ( ( hostInfo ) => {
263- primaryClusterHostUrls . add ( hostInfo . url ) ;
264- } ) ;
265-
266- const cache : ExpirationCache < string , Topology > = this . storageService . getAll ( Topology ) as ExpirationCache < string , Topology > ;
267- if ( ! cache ) {
268- return ;
269- }
270- for ( const [ clusterId , clusterHosts ] of cache . getEntries ( ) ) {
271- const isPrimaryCluster : boolean | null = RdsHostListProvider . primaryClusterIdCache . get (
272- clusterId ,
273- false ,
274- this . suggestedClusterIdRefreshRateNano
275- ) ;
276- const suggestedPrimaryClusterId : string | null = RdsHostListProvider . suggestedPrimaryClusterIdCache . get ( clusterId ) ;
277- if ( isPrimaryCluster || suggestedPrimaryClusterId || ! clusterHosts ) {
278- continue ;
279- }
280-
281- for ( const clusterHost of clusterHosts . hosts ) {
282- if ( primaryClusterHostUrls . has ( clusterHost . url ) ) {
283- RdsHostListProvider . suggestedPrimaryClusterIdCache . put ( clusterId , this . clusterId , this . suggestedClusterIdRefreshRateNano ) ;
284- break ;
285- }
286- }
287- }
288- }
289-
290195 async queryForTopology ( targetClient : ClientWrapper , dialect : DatabaseDialect ) : Promise < HostInfo [ ] > {
291196 if ( ! isDialectTopologyAware ( dialect ) ) {
292197 throw new TypeError ( Messages . get ( "RdsHostListProvider.incorrectDialect" ) ) ;
@@ -366,8 +271,8 @@ export class RdsHostListProvider implements DynamicHostListProvider {
366271 }
367272
368273 static clearAll ( ) : void {
369- RdsHostListProvider . primaryClusterIdCache . clear ( ) ;
370- RdsHostListProvider . suggestedPrimaryClusterIdCache . clear ( ) ;
274+ // No-op
275+ // TODO: remove if still not used after full service container refactoring
371276 }
372277
373278 clear ( ) : void {
@@ -420,13 +325,3 @@ export class FetchTopologyResult {
420325 this . isCachedData = isCachedData ;
421326 }
422327}
423-
424- class ClusterSuggestedResult {
425- clusterId : string ;
426- isPrimaryClusterId : boolean ;
427-
428- constructor ( clusterId : string , isPrimaryClusterId : boolean ) {
429- this . clusterId = clusterId ;
430- this . isPrimaryClusterId = isPrimaryClusterId ;
431- }
432- }
0 commit comments