Skip to content

Commit 6f606a1

Browse files
committed
Query also oldest connection in queue
1 parent 45df099 commit 6f606a1

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ final class ConnectionBuffer {
142142
}
143143
}
144144

145+
/**
146+
* affinity is supported by the buffer.
147+
*/
148+
boolean isAffinitySupported() {
149+
return affinityLists != null;
150+
}
151+
145152
/**
146153
* Return the number of free connections.
147154
*/

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,14 @@ private PooledConnection _obtainConnection(Object affinitiyId) throws Interrupte
226226
return connection;
227227
}
228228
connection = createConnection();
229+
if (connection == null && buffer.isAffinitySupported()) {
230+
// we could not find connection with required affinity and
231+
// buffer is full. So try to get oldest connection from buffer
232+
connection = extractFromFreeList(ConnectionBuffer.GET_OLDEST);
233+
}
229234
if (connection != null) {
230235
return connection;
231236
}
232-
if (affinitiyId != null) {
233-
connection = extractFromFreeList(ConnectionBuffer.GET_OLDEST);
234-
if (connection != null) {
235-
return connection;
236-
}
237-
}
238237
}
239238
try {
240239
// The pool is at maximum size. We are going to go into
@@ -292,6 +291,9 @@ private PooledConnection _obtainConnectionWaitLoop(Object affinitiyId) throws SQ
292291
try {
293292
nanos = notEmpty.awaitNanos(nanos);
294293
PooledConnection c = extractFromFreeList(affinitiyId);
294+
if (c == null && buffer.isAffinitySupported()) {
295+
c = extractFromFreeList(ConnectionBuffer.GET_OLDEST);
296+
}
295297
if (c != null) {
296298
// successfully waited
297299
return c;

0 commit comments

Comments
 (0)