Skip to content

Commit d8bbfe4

Browse files
authored
Merge pull request #101 from ebean-orm/feature/remove-warning-size-feature
Remove the ConnectionPool warning size feature
2 parents 5a40a35 + 2e48870 commit d8bbfe4

File tree

5 files changed

+10
-102
lines changed

5 files changed

+10
-102
lines changed

ebean-datasource-api/src/main/java/io/ebean/datasource/DataSourceAlert.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,4 @@ public interface DataSourceAlert {
2323
*/
2424
void dataSourceDown(DataSource dataSource, SQLException reason);
2525

26-
/**
27-
* Send an alert to say the dataSource is getting close to its max size.
28-
*/
29-
void dataSourceWarning(DataSource dataSource, String msg);
3026
}

ebean-datasource-api/src/main/java/io/ebean/datasource/DataSourcePool.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,4 @@ default SQLException getDataSourceDownReason() {
133133
*/
134134
void setMaxSize(int max);
135135

136-
/**
137-
* Deprecated - looking to remove.
138-
* <p>
139-
* Set a new maximum size. The pool should respect this new warning level immediately
140-
* and not require a restart. We may want to increase the maxConnections if the
141-
* pool gets large and hits the warning levels.
142-
*/
143-
@Deprecated(forRemoval = true)
144-
void setWarningSize(int warningSize);
145-
146-
/**
147-
* Deprecated - looking to remove.
148-
* <p>
149-
* Return the warning size. When the pool hits this size it can send a
150-
* warning message to an administrator.
151-
*/
152-
@Deprecated(forRemoval = true)
153-
int getWarningSize();
154-
155136
}

ebean-datasource/src/main/java/io/ebean/datasource/pool/ConnectionPool.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ final class ConnectionPool implements DataSourcePool {
7070
*/
7171
private final AtomicBoolean dataSourceUp = new AtomicBoolean(false);
7272
private SQLException dataSourceDownReason;
73-
private final AtomicBoolean inWarningMode = new AtomicBoolean();
7473
private final int minConnections;
7574
private int maxConnections;
76-
private int warningSize;
7775
private final int waitTimeoutMillis;
7876
private final int pstmtCacheSize;
7977
private final PooledConnectionQueue queue;
@@ -276,19 +274,6 @@ public SQLException dataSourceDownReason() {
276274
return dataSourceDownReason;
277275
}
278276

279-
/**
280-
* Called when the pool hits the warning level.
281-
*/
282-
void notifyWarning(String msg) {
283-
if (inWarningMode.compareAndSet(false, true)) {
284-
// send an Error to the event log...
285-
Log.warn(msg);
286-
if (notify != null) {
287-
notify.dataSourceWarning(this, msg);
288-
}
289-
}
290-
}
291-
292277
private void notifyDataSourceIsDown(SQLException reason) {
293278
if (dataSourceUp.get()) {
294279
reset();
@@ -448,17 +433,6 @@ int minSize() {
448433
return minConnections;
449434
}
450435

451-
@Override
452-
public void setWarningSize(int warningSize) {
453-
queue.setWarningSize(warningSize);
454-
this.warningSize = warningSize;
455-
}
456-
457-
@Override
458-
public int getWarningSize() {
459-
return warningSize;
460-
}
461-
462436
/**
463437
* Return the time in millis that threads will wait when the pool has hit
464438
* the max size. These threads wait for connections to be returned by the
@@ -587,7 +561,6 @@ PooledConnection createConnectionForQueue(int connId) throws SQLException {
587561
*/
588562
private void reset() {
589563
queue.reset(leakTimeMinutes);
590-
inWarningMode.set(false);
591564
}
592565

593566
/**

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ final class PooledConnectionQueue {
3535
private final Condition notEmpty;
3636
private int connectionId;
3737
private final long waitTimeoutMillis;
38-
private final long leakTimeMinutes;
3938
private final long maxAgeMillis;
4039
private final int minSize;
41-
private int warningSize;
4240
private int maxSize;
4341
/**
4442
* Number of threads in the wait queue.
@@ -72,9 +70,7 @@ final class PooledConnectionQueue {
7270
this.name = pool.name();
7371
this.minSize = pool.minSize();
7472
this.maxSize = pool.maxSize();
75-
this.warningSize = pool.getWarningSize();
7673
this.waitTimeoutMillis = pool.waitTimeoutMillis();
77-
this.leakTimeMinutes = pool.leakTimeMinutes();
7874
this.maxAgeMillis = pool.maxAgeMillis();
7975
this.validateStaleMillis = pool.validateStaleMillis();
8076
this.busyList = new BusyConnectionBuffer(maxSize, 20);
@@ -128,18 +124,6 @@ void setMaxSize(int maxSize) {
128124
}
129125
}
130126

131-
void setWarningSize(int warningSize) {
132-
lock.lock();
133-
try {
134-
if (warningSize > this.maxSize) {
135-
throw new IllegalArgumentException("warningSize " + warningSize + " > maxSize " + this.maxSize);
136-
}
137-
this.warningSize = warningSize;
138-
} finally {
139-
lock.unlock();
140-
}
141-
}
142-
143127
private int totalConnections() {
144128
return freeList.size() + busyList.size();
145129
}
@@ -253,7 +237,6 @@ private PooledConnection _obtainConnection() throws InterruptedException, SQLExc
253237
if (Log.isLoggable(DEBUG)) {
254238
Log.debug("DataSource [{0}] grow; id[{1}] busy[{2}] max[{3}]", name, c.name(), busySize, maxSize);
255239
}
256-
checkForWarningSize();
257240
return c;
258241
}
259242
}
@@ -422,23 +405,6 @@ void closeBusyConnections(long leakTimeMinutes) {
422405
}
423406
}
424407

425-
/**
426-
* As the pool grows it gets closer to the maxConnections limit. We can send
427-
* an Alert (or warning) as we get close to this limit and hence an
428-
* Administrator could increase the pool size if desired.
429-
* <p>
430-
* This is called whenever the pool grows in size (towards the max limit).
431-
*/
432-
private void checkForWarningSize() {
433-
// the total number of connections that we can add
434-
// to the pool before it hits the maximum
435-
int availableGrowth = (maxSize - totalConnections());
436-
if (availableGrowth < warningSize) {
437-
closeBusyConnections(leakTimeMinutes);
438-
pool.notifyWarning("DataSource [" + name + "] is [" + availableGrowth + "] connections from its maximum size.");
439-
}
440-
}
441-
442408
String getBusyConnectionInformation() {
443409
return getBusyConnectionInformation(false);
444410
}

ebean-datasource/src/test/java/io/ebean/datasource/pool/ConnectionPoolDbOutageTest.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ public class ConnectionPoolDbOutageTest implements DataSourceAlert, WaitFor {
2525
private static final Logger log = LoggerFactory.getLogger(ConnectionPoolDbOutageTest.class);
2626
private String connString;
2727
private Connection h2Conn;
28-
28+
2929
private int up;
3030
private int down;
31-
private int warn;
32-
33-
31+
3432
@AfterEach
3533
void afterAll() throws SQLException {
3634
h2Conn.close();
3735
}
38-
36+
3937
/**
4038
* Changes the password and closes all exisitng sessions.
4139
*/
@@ -47,11 +45,11 @@ void setPassword(String pw) throws SQLException {
4745
sessions.add(rs.getInt(1));
4846
}
4947
}
50-
48+
5149
try (Statement stmt = h2Conn.createStatement()) {
5250
stmt.execute("alter user sa set password '" + pw + "'");
5351
}
54-
52+
5553
h2Conn.close();
5654
// reopen connection with new credentials and kill old session
5755
h2Conn = DriverManager.getConnection(connString, "sa", pw);
@@ -82,11 +80,11 @@ private DataSourceConfig config() {
8280
public void testOfflineFromStart() throws InterruptedException, SQLException {
8381
connString = "jdbc:h2:mem:testOfflineFromStart";
8482
h2Conn = DriverManager.getConnection(connString, "sa", "unknown");
85-
83+
8684
DataSourceConfig config = config();
8785
assertThat(down).isEqualTo(0);
8886
ConnectionPool pool = new ConnectionPool("mem:testOfflineFromStart", config);
89-
//
87+
9088
waitFor(() -> {
9189
assertThat(pool.isOnline()).isFalse();
9290
assertThat(up).isEqualTo(0);
@@ -104,14 +102,13 @@ public void testOfflineFromStart() throws InterruptedException, SQLException {
104102
assertThat(down).isEqualTo(1);
105103
assertThat(pool.size()).isEqualTo(1);
106104
});
107-
108105
}
109106

110107
@Test
111108
public void testOfflineDuringRun() throws InterruptedException, SQLException {
112109
connString = "jdbc:h2:mem:testOfflineDuringRun";
113110
h2Conn = DriverManager.getConnection(connString, "sa", "sa");
114-
111+
115112
DataSourceConfig config = config();
116113
ConnectionPool pool = new ConnectionPool("testOfflineDuringRun", config);
117114
waitFor(()-> {
@@ -121,15 +118,15 @@ public void testOfflineDuringRun() throws InterruptedException, SQLException {
121118
assertThat(pool.size()).isEqualTo(3);
122119
});
123120
log.info("pool created ");
124-
121+
125122
// simulate an outage
126123
setPassword("outage");
127124
waitFor(()-> {
128125
assertThat(pool.isOnline()).isFalse();
129126
assertThat(up).isEqualTo(1);
130127
assertThat(down).isEqualTo(1);
131128
});
132-
129+
133130
// recover from outage
134131
setPassword("sa");
135132
waitFor(()-> {
@@ -148,9 +145,4 @@ public void dataSourceUp(DataSource dataSource) {
148145
public void dataSourceDown(DataSource dataSource, SQLException reason) {
149146
down++;
150147
}
151-
152-
@Override
153-
public void dataSourceWarning(DataSource dataSource, String msg) {
154-
warn++;
155-
}
156148
}

0 commit comments

Comments
 (0)