Skip to content

Commit 0bc6974

Browse files
shendachuanob-robot
authored andcommitted
fix dblink lru connection pool core
1 parent 6890818 commit 0bc6974

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

deps/oblib/src/lib/mysqlclient/ob_connection_allocator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ int ObLruConnectionAllocator<T>::free_session_conn_array(uint32_t sessid, int64_
378378
} else {
379379
T *conn = NULL;
380380
while (local_array.count() < local_array_size && OB_SUCCESS == conn_array->pop_back(conn)) {
381-
if (OB_SUCCESS != local_array.push_back(conn)) {
381+
if (OB_SUCCESS != lru_list_erase(conn, sessid)){ // delete respective node from lru list.
382+
ObLruConnectionAllocator<T>::free(conn);
383+
_OB_LOG(ERROR, "lru_list failed to erase, sessid=%u, ret=%d", sessid, ret);
384+
} else if (OB_SUCCESS != local_array.push_back(conn)) {
385+
ObLruConnectionAllocator<T>::free(conn);
382386
_OB_LOG(ERROR, "push back failed, ret=%d", ret);
383387
}
384388
}
@@ -466,9 +470,6 @@ int ObLruConnectionAllocator<T>::get_cached(T *&conn, uint32_t sessid)
466470
if (NULL == conn) {
467471
ret = OB_ERR_UNEXPECTED;
468472
_OB_LOG(WARN, "connection ptr is NULL, sessid=%u, ret=%d", sessid, ret);
469-
} else if (OB_FAIL(lru_list_erase(conn, sessid))){ // delete respective node from lru list.
470-
ObLruConnectionAllocator<T>::free(conn);
471-
_OB_LOG(WARN, "lru_list failed to erase, sessid=%u, ret=%d", sessid, ret);
472473
}
473474
} else if (OB_FAIL(lru_list_pop_front(conn, other_sessid))) {
474475
// do nothing

deps/oblib/src/lib/mysqlclient/ob_server_connection_pool.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,23 @@ int ObServerConnectionPool::acquire(ObMySQLConnection *&conn, uint32_t sessid)
5959
ret = OB_RESOURCE_OUT;
6060
} else if (free_conn_count_ > 0) {
6161
if (OB_FAIL(connection_pool_ptr_->get_cached(connection, sessid))) {
62-
ATOMIC_DEC(&free_conn_count_);
63-
LOG_WARN("fail get conn", K(free_conn_count_), K(busy_conn_count_), K(ret));
62+
if (OB_ENTRY_NOT_EXIST == ret) {
63+
// cached connection consumed by other session concurrently.
64+
ret = OB_SUCCESS;
65+
} else {
66+
LOG_WARN("fail get conn", K(free_conn_count_), K(busy_conn_count_), K(ret));
67+
}
6468
} else {
6569
connection->init(this);
6670
ATOMIC_INC(&busy_conn_count_);
6771
ATOMIC_DEC(&free_conn_count_);
6872
}
73+
}
74+
if (OB_FAIL(ret) || NULL != connection) {
75+
// do nothing.
6976
} else if (busy_conn_count_ < max_allowed_conn_count_) {
7077
ret = connection_pool_ptr_->alloc(connection, sessid);
7178
if (OB_ERR_ALREADY_EXISTS == ret) {
72-
7379
connection->init(this);
7480
ATOMIC_INC(&busy_conn_count_);
7581
ATOMIC_DEC(&free_conn_count_);

0 commit comments

Comments
 (0)