Skip to content

Commit 929d356

Browse files
fix: Limitless plugin set round robin weights to original props used … (#1223)
1 parent f5b9dd6 commit 929d356

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessConnectionContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@
2727
public class LimitlessConnectionContext {
2828
private HostSpec hostSpec;
2929
private Properties props;
30+
private Properties origProps;
3031
private Connection connection;
3132
private JdbcCallable<Connection, SQLException> connectFunc;
3233
private List<HostSpec> limitlessRouters;
3334

3435
public LimitlessConnectionContext(
3536
final HostSpec hostSpec,
3637
final Properties props,
38+
final Properties origProps,
3739
final Connection connection,
3840
final JdbcCallable<Connection, SQLException> connectFunc,
3941
final List<HostSpec> limitlessRouters
4042
) {
4143
this.hostSpec = hostSpec;
4244
this.props = props;
45+
this.origProps = origProps;
4346
this.connection = connection;
4447
this.connectFunc = connectFunc;
4548
this.limitlessRouters = limitlessRouters;
@@ -53,6 +56,10 @@ public Properties getProps() {
5356
return this.props;
5457
}
5558

59+
public Properties getOrigProps() {
60+
return this.origProps;
61+
}
62+
5663
public Connection getConnection() {
5764
return this.connection;
5865
}

wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessConnectionPlugin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ public Connection connect(
111111

112112
final Properties copyProps = PropertyUtils.copyProperties(props);
113113
copyProps.setProperty(INTERNAL_CONNECT_PROPERTY_NAME, "true");
114-
return connectInternal(driverProtocol, hostSpec, copyProps, isInitialConnection, connectFunc);
114+
return connectInternal(driverProtocol, hostSpec, props, copyProps, isInitialConnection, connectFunc);
115115
}
116116

117117
public Connection connectInternal(
118118
final String driverProtocol,
119119
final HostSpec hostSpec,
120-
final Properties props,
120+
final Properties origProps,
121+
final Properties copyProps,
121122
final boolean isInitialConnection,
122123
final JdbcCallable<Connection, SQLException> connectFunc)
123124
throws SQLException {
@@ -143,7 +144,8 @@ public Connection connectInternal(
143144

144145
final LimitlessConnectionContext context = new LimitlessConnectionContext(
145146
hostSpec,
146-
props,
147+
copyProps,
148+
origProps,
147149
conn,
148150
connectFunc,
149151
null);

wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterMonitor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public void run() {
137137
newLimitlessRouters,
138138
TimeUnit.MILLISECONDS.toNanos(LimitlessRouterServiceImpl.MONITOR_DISPOSAL_TIME_MS.getLong(props)));
139139

140-
RoundRobinHostSelector.setRoundRobinHostWeightPairsProperty(this.props, newLimitlessRouters);
141140
LOGGER.finest(Utils.logTopology(newLimitlessRouters, "[limitlessRouterMonitor] Topology:"));
142141
TimeUnit.MILLISECONDS.sleep(this.intervalMs); // do not include this in the telemetry
143142
} catch (final InterruptedException exception) {

wrapper/src/main/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public void establishConnection(final LimitlessConnectionContext context) throws
131131
return;
132132
}
133133

134-
RoundRobinHostSelector.setRoundRobinHostWeightPairsProperty(context.getProps(), context.getLimitlessRouters());
134+
RoundRobinHostSelector.setRoundRobinHostWeightPairsProperty(
135+
context.getOrigProps(),
136+
context.getLimitlessRouters());
135137
HostSpec selectedHostSpec;
136138
try {
137139
selectedHostSpec = this.pluginService.getHostSpecByStrategy(
@@ -165,7 +167,7 @@ public void establishConnection(final LimitlessConnectionContext context) throws
165167
}
166168
}
167169

168-
protected List<HostSpec> getLimitlessRouters(final String clusterId, final Properties props) throws SQLException {
170+
protected List<HostSpec> getLimitlessRouters(final String clusterId, final Properties props) {
169171
final long cacheExpirationNano = TimeUnit.MILLISECONDS.toNanos(
170172
MONITOR_DISPOSAL_TIME_MS.getLong(props));
171173
return limitlessRouterCache.get(clusterId, cacheExpirationNano);

wrapper/src/test/java/software/amazon/jdbc/plugin/limitless/LimitlessRouterServiceImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import software.amazon.jdbc.RoundRobinHostSelector;
4848
import software.amazon.jdbc.hostavailability.HostAvailability;
4949
import software.amazon.jdbc.hostavailability.SimpleHostAvailabilityStrategy;
50+
import software.amazon.jdbc.util.PropertyUtils;
5051
import software.amazon.jdbc.wrapper.HighestWeightHostSelector;
5152

5253
public class LimitlessRouterServiceImplTest {
@@ -70,6 +71,7 @@ public void init() throws SQLException {
7071
props = new Properties();
7172
when(mockConnectFuncLambda.call()).thenReturn(mockConnection);
7273
when(mockPluginService.getHostListProvider()).thenReturn(mockHostListProvider);
74+
when(mockPluginService.getProperties()).thenReturn(props);
7375
when(mockHostListProvider.getClusterId()).thenReturn(CLUSTER_ID);
7476
}
7577

@@ -85,6 +87,7 @@ void testEstablishConnection_GivenGetEmptyRouterListAndWaitForRouterInfo_ThenThr
8587

8688
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
8789
hostSpec,
90+
PropertyUtils.copyProperties(props),
8891
props,
8992
null,
9093
mockConnectFuncLambda,
@@ -103,6 +106,7 @@ void testEstablishConnection_GivenGetEmptyRouterListAndNoWaitForRouterInfo_ThenC
103106
props.setProperty(LimitlessConnectionPlugin.WAIT_FOR_ROUTER_INFO.name, "false");
104107
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
105108
hostSpec,
109+
PropertyUtils.copyProperties(props),
106110
props,
107111
null,
108112
mockConnectFuncLambda,
@@ -132,6 +136,7 @@ void testEstablishConnection_GivenHostSpecInRouterCache_ThenCallConnectFunc() th
132136

133137
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
134138
routerList.get(1),
139+
PropertyUtils.copyProperties(props),
135140
props,
136141
null,
137142
mockConnectFuncLambda,
@@ -163,6 +168,7 @@ void testEstablishConnection_GivenFetchRouterListAndHostSpecInRouterList_ThenCal
163168

164169
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
165170
routerList.get(1),
171+
PropertyUtils.copyProperties(props),
166172
props,
167173
null,
168174
mockConnectFuncLambda,
@@ -199,6 +205,7 @@ void testEstablishConnection_GivenRouterCache_ThenSelectsHost() throws SQLExcept
199205

200206
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
201207
hostSpec,
208+
PropertyUtils.copyProperties(props),
202209
props,
203210
null,
204211
mockConnectFuncLambda,
@@ -234,6 +241,7 @@ void testEstablishConnection_GivenFetchRouterList_ThenSelectsHost() throws SQLEx
234241

235242
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
236243
hostSpec,
244+
PropertyUtils.copyProperties(props),
237245
props,
238246
null,
239247
mockConnectFuncLambda,
@@ -267,6 +275,7 @@ void testEstablishConnection_GivenHostSpecInRouterCacheAndCallConnectFuncThrows_
267275
final HostSpec selectedRouter = routerList.get(2);
268276
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
269277
routerList.get(1),
278+
PropertyUtils.copyProperties(props),
270279
props,
271280
null,
272281
mockConnectFuncLambda,
@@ -311,6 +320,7 @@ void testEstablishConnection_GivenSelectsHostThrows_ThenRetry() throws SQLExcept
311320

312321
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
313322
hostSpec,
323+
PropertyUtils.copyProperties(props),
314324
props,
315325
null,
316326
mockConnectFuncLambda,
@@ -350,6 +360,7 @@ void testEstablishConnection_GivenSelectsHostNull_ThenRetry() throws SQLExceptio
350360

351361
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
352362
hostSpec,
363+
PropertyUtils.copyProperties(props),
353364
props,
354365
null,
355366
mockConnectFuncLambda,
@@ -392,6 +403,7 @@ void testEstablishConnection_GivenPluginServiceConnectThrows_ThenRetry() throws
392403

393404
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
394405
hostSpec,
406+
PropertyUtils.copyProperties(props),
395407
props,
396408
null,
397409
mockConnectFuncLambda,
@@ -429,6 +441,7 @@ void testEstablishConnection_GivenRetryAndMaxRetriesExceeded_thenThrowSqlExcepti
429441

430442
final LimitlessConnectionContext inputContext = new LimitlessConnectionContext(
431443
routerList.get(0),
444+
PropertyUtils.copyProperties(props),
432445
props,
433446
null,
434447
mockConnectFuncLambda,

0 commit comments

Comments
 (0)