Use same connection when get file blocks

This commit is contained in:
yangheran 2024-09-02 11:59:19 +08:00
parent e96a93c6e0
commit 547bcdaa36
6 changed files with 48 additions and 15 deletions

View File

@ -243,6 +243,7 @@ checkout_blk_error:
return -1;
}
// The user_conn needs to be returned before free aux.
void
free_checkout_block_aux (CheckoutBlockAux *aux)
{

View File

@ -180,6 +180,7 @@ struct _CheckoutBlockAux {
const char *token;
gboolean use_fileserver_port;
void *task;
void *user_conn;
};
typedef struct _CheckoutBlockAux CheckoutBlockAux;

View File

@ -274,6 +274,22 @@ connection_pool_return_connection (ConnectionPool *pool, Connection *conn)
pthread_mutex_unlock (&pool->lock);
}
void
http_tx_manager_return_connection (const char *host, void *conn)
{
HttpTxPriv *priv = seaf->http_tx_mgr->priv;
ConnectionPool *pool;
pool = find_connection_pool (priv, host);
if (!pool) {
seaf_warning ("Failed to create connection pool for host %s.\n", host);
connection_free (conn);
return;
}
connection_pool_return_connection (pool, conn);
}
#define LOCKED_ERROR_PATTERN "File (.+) is locked"
#define FOLDER_PERM_ERROR_PATTERN "Update to path (.+) is not allowed by folder permission settings"
#define TOO_MANY_FILES_ERROR_PATTERN "Too many files in library"
@ -4755,7 +4771,8 @@ http_tx_manager_get_block (HttpTxManager *manager,
gboolean use_fileserver_port,
int *error_id,
HttpRecvCallback get_blk_cb,
void *user_data)
void *user_data,
void **user_conn)
{
HttpTxPriv *priv = seaf->http_tx_mgr->priv;
ConnectionPool *pool;
@ -4765,19 +4782,24 @@ http_tx_manager_get_block (HttpTxManager *manager,
int status;
int ret = 0;
pool = find_connection_pool (priv, host);
if (!pool) {
*error_id = SYNC_ERROR_ID_NOT_ENOUGH_MEMORY;
seaf_warning ("Failed to create connection pool for host %s.\n", host);
return -1;
if (*user_conn == NULL) {
pool = find_connection_pool (priv, host);
if (!pool) {
*error_id = SYNC_ERROR_ID_NOT_ENOUGH_MEMORY;
seaf_warning ("Failed to create connection pool for host %s.\n", host);
return -1;
}
conn = connection_pool_get_connection (pool);
if (!conn) {
*error_id = SYNC_ERROR_ID_NOT_ENOUGH_MEMORY;
seaf_warning ("Failed to get connection to host %s.\n", host);
return -1;
}
*user_conn = conn;
}
conn = connection_pool_get_connection (pool);
if (!conn) {
*error_id = SYNC_ERROR_ID_NOT_ENOUGH_MEMORY;
seaf_warning ("Failed to get connection to host %s.\n", host);
return -1;
}
conn = *user_conn;
curl = conn->curl;
@ -4806,7 +4828,6 @@ http_tx_manager_get_block (HttpTxManager *manager,
out:
g_free (url);
connection_pool_return_connection (pool, conn);
return ret;
}

View File

@ -115,6 +115,9 @@ http_tx_manager_new (struct _SeafileSession *seaf);
int
http_tx_manager_start (HttpTxManager *mgr);
void
http_tx_manager_return_connection (const char *host, void *conn);
int
http_tx_manager_add_download (HttpTxManager *manager,
const char *repo_id,
@ -330,7 +333,8 @@ http_tx_manager_get_block (HttpTxManager *manager,
gboolean use_fileserver_port,
int *error_id,
HttpRecvCallback get_blk_cb,
void *user_data);
void *user_data,
void **user_conn);
int
http_tx_manager_get_file_block_map (HttpTxManager *manager,

View File

@ -4837,7 +4837,7 @@ checkout_block_cb (const char *repo_id, const char *block_id, int fd, SeafileCry
block_id, user_data->host,
user_data->token, user_data->use_fileserver_port,
&error_id,
update_block_cb, &aux) < 0) {
update_block_cb, &aux, &user_data->user_conn) < 0) {
if (task->state == HTTP_TASK_STATE_CANCELED) {
ret = -1;
goto out;
@ -5165,9 +5165,13 @@ checkout_file_http (FileTxData *data,
seaf_filelock_manager_lock_wt_file (seaf->filelock_mgr,
repo_id, de->name);
if (aux->user_conn)
http_tx_manager_return_connection (aux->host, aux->user_conn);
free_checkout_block_aux (aux);
return error_id;
}
if (aux->user_conn)
http_tx_manager_return_connection (aux->host, aux->user_conn);
free_checkout_block_aux (aux);
if (locked_on_server)

View File

@ -2053,6 +2053,8 @@ check_locked_files (void *vdata)
if (success)
g_hash_table_iter_remove (&iter);
}
if (aux->user_conn)
http_tx_manager_return_connection (aux->host, aux->user_conn);
free_checkout_block_aux (aux);
discard_index (&istate);