File tree Expand file tree Collapse file tree
ebean-datasource/src/main/java/io/ebean/datasource/pool Expand file tree Collapse file tree Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments