1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-28 03:20:41 +00:00

Add timeout for merge trees

This commit is contained in:
杨赫然 2021-11-24 11:41:47 +08:00
parent ca63ba1269
commit 2d17e125b4
4 changed files with 31 additions and 0 deletions

View File

@ -88,6 +88,15 @@ merge_entries (const char *store_id, int version,
{ {
SeafDirent *files[3]; SeafDirent *files[3];
int i; int i;
gint64 curr_time;
if (opt->start_time > 0 && opt->timeout > 0) {
curr_time = time(NULL);
if (curr_time - opt->start_time > opt->timeout) {
seaf_warning("Merge trees timeout for repo %s/%s.\n", store_id, basedir);
return -1;
}
}
memset (files, 0, sizeof(files[0])*n); memset (files, 0, sizeof(files[0])*n);
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {

View File

@ -25,6 +25,9 @@ typedef struct MergeOptions {
char merged_tree_root[41]; /* merge result */ char merged_tree_root[41]; /* merge result */
int visit_dirs; int visit_dirs;
gboolean conflict; gboolean conflict;
gint64 start_time;
gint64 timeout;
} MergeOptions; } MergeOptions;
int int

View File

@ -148,6 +148,7 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
char *encoding; char *encoding;
int max_indexing_threads; int max_indexing_threads;
int max_index_processing_threads; int max_index_processing_threads;
int put_head_commit_request_timeout;
char *cluster_shared_temp_file_mode = NULL; char *cluster_shared_temp_file_mode = NULL;
host = fileserver_config_get_string (session->config, HOST, &error); host = fileserver_config_get_string (session->config, HOST, &error);
@ -283,6 +284,21 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
/* No windows specific encoding is specified. Set the ZIP_UTF8 flag. */ /* No windows specific encoding is specified. Set the ZIP_UTF8 flag. */
setlocale (LC_ALL, "en_US.UTF-8"); setlocale (LC_ALL, "en_US.UTF-8");
} }
put_head_commit_request_timeout = fileserver_config_get_integer (session->config,
"put_head_commit_request_timeout",
&error);
if (error){
htp_server->put_head_commit_request_timeout = 10; /* default 3600s */
g_clear_error(&error);
} else {
if (put_head_commit_request_timeout<= 0)
htp_server->put_head_commit_request_timeout= 10; /* default 3600s */
else
htp_server->put_head_commit_request_timeout= put_head_commit_request_timeout;
}
seaf_message ("fileserver: put_head_commit_request_timeout = %d\n",
htp_server->put_head_commit_request_timeout);
} }
static int static int
@ -973,6 +989,8 @@ retry:
memcpy (opt.remote_repo_id, repo_id, 36); memcpy (opt.remote_repo_id, repo_id, 36);
memcpy (opt.remote_head, new_commit->commit_id, 40); memcpy (opt.remote_head, new_commit->commit_id, 40);
opt.do_merge = TRUE; opt.do_merge = TRUE;
opt.start_time = time(NULL);
opt.timeout = seaf->http_server->put_head_commit_request_timeout;
roots[0] = base->root_id; /* base */ roots[0] = base->root_id; /* base */
roots[1] = current_head->root_id; /* head */ roots[1] = current_head->root_id; /* head */

View File

@ -22,6 +22,7 @@ struct _HttpServerStruct {
int worker_threads; int worker_threads;
int max_index_processing_threads; int max_index_processing_threads;
int cluster_shared_temp_file_mode; int cluster_shared_temp_file_mode;
int put_head_commit_request_timeout;
}; };
typedef struct _HttpServerStruct HttpServerStruct; typedef struct _HttpServerStruct HttpServerStruct;