Skip to content

Commit

Permalink
[client] Handle ccnet_job_manager_schedule_job() failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
killing committed Jan 4, 2016
1 parent accd5f2 commit 837403a
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 80 deletions.
56 changes: 32 additions & 24 deletions daemon/clone-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,16 @@ check_head_commit_done (HttpHeadCommit *result, void *user_data)
static void
http_check_head_commit (CloneTask *task)
{
http_tx_manager_check_head_commit (seaf->http_tx_mgr,
task->repo_id,
task->repo_version,
task->effective_url,
task->token,
task->use_fileserver_port,
check_head_commit_done,
task);
int ret = http_tx_manager_check_head_commit (seaf->http_tx_mgr,
task->repo_id,
task->repo_version,
task->effective_url,
task->token,
task->use_fileserver_port,
check_head_commit_done,
task);
if (ret < 0)
transition_to_error (task, CLONE_ERROR_CONNECT);
}

static char *
Expand Down Expand Up @@ -351,11 +353,12 @@ check_http_protocol_done (HttpProtocolVersion *result, void *user_data)
http_check_head_commit (task);
} else if (strncmp(task->server_url, "https", 5) != 0) {
char *host_fileserver = http_fileserver_url(task->server_url);
http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
host_fileserver,
TRUE,
check_http_fileserver_protocol_done,
task);
if (http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
host_fileserver,
TRUE,
check_http_fileserver_protocol_done,
task) < 0)
transition_state (task, CLONE_STATE_CONNECT);
g_free (host_fileserver);
} else {
/* Wait for periodic retry. */
Expand All @@ -366,11 +369,15 @@ check_http_protocol_done (HttpProtocolVersion *result, void *user_data)
static void
check_http_protocol (CloneTask *task)
{
http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
task->server_url,
FALSE,
check_http_protocol_done,
task);
if (http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
task->server_url,
FALSE,
check_http_protocol_done,
task) < 0) {
transition_to_error (task, CLONE_ERROR_CONNECT);
return;
}

transition_state (task, CLONE_STATE_CHECK_HTTP);
}

Expand Down Expand Up @@ -2425,10 +2432,11 @@ check_folder_permissions (CloneTask *task)
requests = g_list_append (requests, req);

/* The requests list will be freed in http tx manager. */
http_tx_manager_get_folder_perms (seaf->http_tx_mgr,
task->effective_url,
task->use_fileserver_port,
requests,
check_folder_perms_done,
task);
if (http_tx_manager_get_folder_perms (seaf->http_tx_mgr,
task->effective_url,
task->use_fileserver_port,
requests,
check_folder_perms_done,
task) < 0)
transition_to_error (task, CLONE_ERROR_INTERNAL);
}
73 changes: 48 additions & 25 deletions daemon/http-tx-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,16 @@ http_tx_manager_check_protocol_version (HttpTxManager *manager,
data->callback = callback;
data->user_data = user_data;

ccnet_job_manager_schedule_job (seaf->job_mgr,
check_protocol_version_thread,
check_protocol_version_done,
data);
int ret = ccnet_job_manager_schedule_job (seaf->job_mgr,
check_protocol_version_thread,
check_protocol_version_done,
data);
if (ret < 0) {
g_free (data->host);
g_free (data);
}

return 0;
return ret;
}

/* Check Head Commit. */
Expand Down Expand Up @@ -1302,10 +1306,15 @@ http_tx_manager_check_head_commit (HttpTxManager *manager,
data->user_data = user_data;
data->use_fileserver_port = use_fileserver_port;

ccnet_job_manager_schedule_job (seaf->job_mgr,
check_head_commit_thread,
check_head_commit_done,
data);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
check_head_commit_thread,
check_head_commit_done,
data) < 0) {
g_free (data->host);
g_free (data->token);
g_free (data);
return -1;
}

return 0;
}
Expand Down Expand Up @@ -1651,10 +1660,14 @@ http_tx_manager_get_folder_perms (HttpTxManager *manager,
data->user_data = user_data;
data->use_fileserver_port = use_fileserver_port;

ccnet_job_manager_schedule_job (seaf->job_mgr,
get_folder_perms_thread,
get_folder_perms_done,
data);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
get_folder_perms_thread,
get_folder_perms_done,
data) < 0) {
g_free (data->host);
g_free (data);
return -1;
}

return 0;
}
Expand Down Expand Up @@ -1924,10 +1937,14 @@ http_tx_manager_get_locked_files (HttpTxManager *manager,
data->user_data = user_data;
data->use_fileserver_port = use_fileserver_port;

ccnet_job_manager_schedule_job (seaf->job_mgr,
get_locked_files_thread,
get_locked_files_done,
data);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
get_locked_files_thread,
get_locked_files_done,
data) < 0) {
g_free (data->host);
g_free (data);
return -1;
}

return 0;
}
Expand Down Expand Up @@ -2044,10 +2061,13 @@ http_tx_manager_add_upload (HttpTxManager *manager,
g_strdup(repo_id),
task);

ccnet_job_manager_schedule_job (seaf->job_mgr,
http_upload_thread,
http_upload_done,
task);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
http_upload_thread,
http_upload_done,
task) < 0) {
g_hash_table_remove (manager->priv->upload_tasks, repo_id);
return -1;
}

return 0;
}
Expand Down Expand Up @@ -3358,10 +3378,13 @@ http_tx_manager_add_download (HttpTxManager *manager,
NULL);
task->repo_name = g_strdup(repo_name);

ccnet_job_manager_schedule_job (seaf->job_mgr,
http_download_thread,
http_download_done,
task);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
http_download_thread,
http_download_done,
task) < 0) {
g_hash_table_remove (manager->priv->download_tasks, repo_id);
return -1;
}

return 0;
}
Expand Down
79 changes: 48 additions & 31 deletions daemon/sync-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,9 @@ check_head_commit_http (SyncTask *task)
task);
if (ret == 0)
transition_sync_state (task, SYNC_STATE_INIT);
else if (ret < 0)
seaf_sync_manager_set_task_error (task, SYNC_ERROR_GET_SYNC_INFO);

return ret;
}

Expand Down Expand Up @@ -1706,10 +1709,11 @@ commit_repo (SyncTask *task)

transition_sync_state (task, SYNC_STATE_COMMIT);

ccnet_job_manager_schedule_job (seaf->job_mgr,
commit_job,
commit_job_done,
task);
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
commit_job,
commit_job_done,
task) < 0)
seaf_sync_manager_set_task_error (task, SYNC_ERROR_COMMIT);
}

static int
Expand Down Expand Up @@ -2112,11 +2116,12 @@ check_http_protocol_done (HttpProtocolVersion *result, void *user_data)
state->checking = FALSE;
} else if (strncmp(state->testing_host, "https", 5) != 0) {
char *host_fileserver = http_fileserver_url(state->testing_host);
http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
host_fileserver,
TRUE,
check_http_fileserver_protocol_done,
state);
if (http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
host_fileserver,
TRUE,
check_http_fileserver_protocol_done,
state) < 0)
state->checking = FALSE;
g_free (host_fileserver);
} else {
state->checking = FALSE;
Expand Down Expand Up @@ -2168,11 +2173,13 @@ check_http_protocol (SeafSyncManager *mgr, SeafRepo *repo)

state->last_http_check_time = (gint64)time(NULL);

http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
repo->server_url,
FALSE,
check_http_protocol_done,
state);
if (http_tx_manager_check_protocol_version (seaf->http_tx_mgr,
repo->server_url,
FALSE,
check_http_protocol_done,
state) < 0)
return FALSE;

state->checking = TRUE;

return FALSE;
Expand Down Expand Up @@ -2559,12 +2566,15 @@ check_folder_permissions_one_server (SeafSyncManager *mgr,
server_state->checking_folder_perms = TRUE;

/* The requests list will be freed in http tx manager. */
http_tx_manager_get_folder_perms (seaf->http_tx_mgr,
server_state->effective_host,
server_state->use_fileserver_port,
requests,
check_folder_perms_done,
server_state);
if (http_tx_manager_get_folder_perms (seaf->http_tx_mgr,
server_state->effective_host,
server_state->use_fileserver_port,
requests,
check_folder_perms_done,
server_state) < 0) {
seaf_warning ("Failed to schedule check folder permissions\n");
server_state->checking_folder_perms = FALSE;
}
}

static void
Expand Down Expand Up @@ -2683,12 +2693,15 @@ check_locked_files_one_server (SeafSyncManager *mgr,
server_state->checking_locked_files = TRUE;

/* The requests list will be freed in http tx manager. */
http_tx_manager_get_locked_files (seaf->http_tx_mgr,
server_state->effective_host,
server_state->use_fileserver_port,
requests,
check_server_locked_files_done,
server_state);
if (http_tx_manager_get_locked_files (seaf->http_tx_mgr,
server_state->effective_host,
server_state->use_fileserver_port,
requests,
check_server_locked_files_done,
server_state) < 0) {
seaf_warning ("Failed to schedule check server locked files\n");
server_state->checking_locked_files = FALSE;
}
}

static void
Expand Down Expand Up @@ -2799,11 +2812,15 @@ auto_sync_pulse (void *vmanager)
now - repo->last_check_locked_time >= CHECK_LOCKED_FILES_INTERVAL)
{
repo->checking_locked_files = TRUE;
ccnet_job_manager_schedule_job (seaf->job_mgr,
check_locked_files,
check_locked_files_done,
repo);
repo->last_check_locked_time = now;
if (ccnet_job_manager_schedule_job (seaf->job_mgr,
check_locked_files,
check_locked_files_done,
repo) < 0) {
seaf_warning ("Failed to schedule check local locked files\n");
repo->checking_locked_files = FALSE;
} else {
repo->last_check_locked_time = now;
}

}
}
Expand Down

0 comments on commit 837403a

Please sign in to comment.