1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-12 21:35:30 +00:00

Improved concurrent update handling.

This commit is contained in:
Jonathan Xu
2017-08-16 17:44:32 +08:00
parent d94a542de9
commit a87db5b58e
3 changed files with 25 additions and 19 deletions

View File

@@ -831,7 +831,7 @@ fast_forward_or_merge (const char *repo_id,
SeafCommit *base,
SeafCommit *new_commit)
{
#define MAX_RETRY_COUNT 3
#define MAX_RETRY_COUNT 10
SeafRepo *repo = NULL;
SeafCommit *current_head = NULL, *merged_commit = NULL;
@@ -924,6 +924,10 @@ retry:
seaf_commit_unref (merged_commit);
merged_commit = NULL;
if (++retry_cnt <= MAX_RETRY_COUNT) {
/* Sleep random time between 100 and 1000 millisecs. */
usleep (g_random_int_range(1, 11) * 100 * 1000);
repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo) {
seaf_warning ("Repo %s doesn't exist.\n", repo_id);
@@ -931,9 +935,6 @@ retry:
goto out;
}
if (++retry_cnt <= MAX_RETRY_COUNT) {
/* Sleep random time between 100 and 1000 millisecs. */
usleep (g_random_int_range(1, 11) * 100 * 1000);
goto retry;
} else {
ret = -1;

View File

@@ -442,7 +442,7 @@ gen_new_commit (const char *repo_id,
char *new_commit_id,
GError **error)
{
#define MAX_RETRY_COUNT 3
#define MAX_RETRY_COUNT 10
SeafRepo *repo = NULL;
SeafCommit *new_commit = NULL, *current_head = NULL, *merged_commit = NULL;
@@ -560,6 +560,10 @@ retry:
seaf_commit_unref (merged_commit);
merged_commit = NULL;
if (++retry_cnt <= MAX_RETRY_COUNT) {
/* Sleep random time between 100 and 1000 millisecs. */
usleep (g_random_int_range(1, 11) * 100 * 1000);
repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
if (!repo) {
seaf_warning ("Repo %s doesn't exist.\n", repo_id);
@@ -568,11 +572,11 @@ retry:
goto out;
}
if (++retry_cnt <= MAX_RETRY_COUNT) {
/* Sleep random time between 100 and 1000 millisecs. */
usleep (g_random_int_range(1, 11) * 100 * 1000);
goto retry;
} else {
seaf_warning ("Too many retries for concurrent update on repo %s. Stop retrying.\n",
repo_id);
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL, "Concurrent update");
ret = -1;
goto out;
}

View File

@@ -6,6 +6,7 @@
#include "seafile-session.h"
#include "size-sched.h"
#define DEBUG_FLAG SEAFILE_DEBUG_OTHER
#include "log.h"
typedef struct SizeSchedulerPriv {
@@ -169,7 +170,7 @@ set_repo_size (SeafDB *db,
}
} else {
if (strcmp (old_head_id, cached_head_id) != 0) {
g_message ("[size sched] Size update conflict for repo %s, rollback.\n",
seaf_debug ("[size sched] Size update conflict for repo %s, rollback.\n",
repo_id);
ret = SET_SIZE_CONFLICT;
goto rollback;