Exemplo n.º 1
0
static int
start_index_or_transfer (SeafCloneManager *mgr, CloneTask *task, GError **error)
{
    IndexAux *aux;
    int ret = 0;

    if (is_non_empty_directory (task->worktree)) {
        transition_state (task, CLONE_STATE_INDEX);

        aux = g_new0 (IndexAux, 1);
        aux->mgr = mgr;
        aux->task = task;

        ccnet_job_manager_schedule_job (seaf->job_mgr,
                                        index_files_job,
                                        index_files_done,
                                        aux);
    } else {
        ret = add_transfer_task (mgr, task, error);
        if (ret == 0)
            transition_state (task, CLONE_STATE_FETCH);
        else
            transition_to_error (task, CLONE_ERROR_FETCH);
    }

    return ret;
}
Exemplo n.º 2
0
static int
schedule_pulse (void *vscheduler)
{
    Scheduler *sched = vscheduler;
    RepoSizeJob *job;

    while (sched->priv->n_running_repo_size_jobs < CONCURRENT_JOBS) {
        job = (RepoSizeJob *)g_queue_pop_head (sched->priv->repo_size_job_queue);
        if (!job)
            break;

        int ret = ccnet_job_manager_schedule_job (sched->seaf->job_mgr,
                                        compute_repo_size,
                                        compute_repo_size_done,
                                        job);
        if (ret < 0) {
            g_warning ("[scheduler] failed to start compute job.\n");
            g_queue_push_head (sched->priv->repo_size_job_queue, job);
            break;
        }
        ++(sched->priv->n_running_repo_size_jobs);
    }

    return 1;
}
Exemplo n.º 3
0
static void
on_start_cleanup (SeafileSession *session)
{
    ccnet_job_manager_schedule_job (seaf->job_mgr, 
                                    on_start_cleanup_job, 
                                    cleanup_job_done,
                                    session);
}
Exemplo n.º 4
0
static void
start_checkout (SeafRepo *repo, CloneTask *task)
{
    if (repo->encrypted && task->passwd != NULL) {
        /* keep this password check to be compatible with old servers. */
        if (repo->enc_version >= 1 && 
            seaf_repo_verify_passwd (repo->id, task->passwd, repo->magic) < 0) {
            seaf_warning ("[Clone mgr] incorrect password.\n");
            transition_to_error (task, CLONE_ERROR_PASSWD);
            return;
        }

        if (seaf_repo_manager_set_repo_passwd (seaf->repo_mgr,
                                               repo,
                                               task->passwd) < 0) {
            seaf_warning ("[Clone mgr] failed to set passwd for %s.\n", repo->id);
            transition_to_error (task, CLONE_ERROR_INTERNAL);
            return;
        }
    } else if (repo->encrypted) {
        seaf_warning ("[Clone mgr] Password is empty for encrypted repo %s.\n",
                   repo->id);
        transition_to_error (task, CLONE_ERROR_PASSWD);
        return;
    }

    if (g_access (task->worktree, F_OK) != 0 &&
        g_mkdir_with_parents (task->worktree, 0777) < 0) {
        seaf_warning ("[clone mgr] Failed to create worktree %s.\n",
                      task->worktree);
        transition_to_error (task, CLONE_ERROR_CHECKOUT);
        return;
    }

    if (!is_non_empty_directory (task->worktree)) {
        transition_state (task, CLONE_STATE_CHECKOUT);
        seaf_repo_manager_add_checkout_task (seaf->repo_mgr,
                                             repo,
                                             task->worktree,
                                             on_checkout_done,
                                             task->manager);
    } else {
        MergeAux *aux = g_new0 (MergeAux, 1);
        aux->task = task;
        aux->repo = repo;

        transition_state (task, CLONE_STATE_MERGE);
        ccnet_job_manager_schedule_job (seaf->job_mgr,
                                        merge_job,
                                        merge_job_done,
                                        aux);
    }
}
Exemplo n.º 5
0
void
schedule_create_system_default_repo (SeafileSession *session)
{
    char *sql = "CREATE TABLE IF NOT EXISTS SystemInfo "
        "(info_key VARCHAR(256), info_value VARCHAR(1024))";
    if (seaf_db_query (session->db, sql) < 0)
        return;

    ccnet_job_manager_schedule_job (session->job_mgr,
                                    create_system_default_repo,
                                    NULL, session);
}
Exemplo n.º 6
0
static void
dns_lookup_peer (CcnetPeer* peer)
{
    DNSLookupData *data;

    if (peer->dns_done)
        return;

    data = g_new0 (DNSLookupData, 1);
    data->peer = peer;
    ccnet_job_manager_schedule_job (peer->manager->session->job_mgr,
                                    dns_lookup,
                                    dns_lookup_cb,
                                    data);
}
Exemplo n.º 7
0
static int
schedule_merge_tasks (void *vscheduler)
{
    MergeScheduler *scheduler = vscheduler;
    int n_running = g_hash_table_size (scheduler->running);
    MergeTask *task;

    /* seaf_debug ("Waiting tasks %d, running tasks %d.\n", */
    /*             g_queue_get_length (scheduler->queue), n_running); */

    if (n_running >= MAX_RUNNING_TASKS)
        return TRUE;

    pthread_mutex_lock (&scheduler->q_lock);

    while (n_running < MAX_RUNNING_TASKS) {
        task = g_queue_pop_head (scheduler->queue);
        if (!task)
            break;

        if (!g_hash_table_lookup (scheduler->running, task->repo_id)) {
            int ret = ccnet_job_manager_schedule_job (scheduler->tpool,
                                                      merge_virtual_repo,
                                                      merge_virtual_repo_done,
                                                      task);
            if (ret < 0) {
                g_queue_push_tail (scheduler->queue, task);
                break;
            }

            g_hash_table_insert (scheduler->running,
                                 g_strdup(task->repo_id),
                                 task);
            n_running++;

            seaf_debug ("Run task for repo %.8s.\n", task->repo_id);
        } else {
            seaf_debug ("A task for repo %.8s is already running.\n", task->repo_id);

            g_queue_push_tail (scheduler->queue, task);
            break;
        }
    }

    pthread_mutex_unlock (&scheduler->q_lock);

    return TRUE;
}
Exemplo n.º 8
0
int
gc_start ()
{
    int ret;

    g_atomic_int_set (&gc_started, 1);

    ret = ccnet_job_manager_schedule_job (seaf->job_mgr,
                                          gc_thread_func,
                                          gc_thread_done,
                                          NULL);
    if (ret < 0)
        return ret;

    return 0;
}
Exemplo n.º 9
0
Arquivo: gc.c Projeto: 2bj/seafile
int
gc_start ()
{
    int ret;

    gc_started = TRUE;

    ret = ccnet_job_manager_schedule_job (seaf->job_mgr,
                                          gc_thread_func,
                                          gc_thread_done,
                                          NULL);
    if (ret < 0)
        return ret;

    return 0;
}
Exemplo n.º 10
0
int
block_tx_client_start (BlockTxInfo *info, BlockTxClientDoneCB cb)
{
    BlockTxClient *client = g_new0 (BlockTxClient, 1);
    int ret = 0;

    client->info = info;
    client->cb = cb;

    ret = ccnet_job_manager_schedule_job (seaf->job_mgr,
                                          block_tx_client_thread,
                                          block_tx_client_thread_done,
                                          client);
    if (ret < 0) {
        seaf_warning ("Failed to start block tx client thread.\n");
        return -1;
    }

    return 0;
}
Exemplo n.º 11
0
int
ccnet_processor_thread_create (CcnetProcessor *processor,
                               CcnetJobManager *job_mgr,
                               ProcThreadFunc func,
                               ProcThreadDoneFunc done_func,
                               void *data)
{
    ProcThreadData *tdata;

    tdata = g_new(ProcThreadData, 1);
    tdata->proc = processor;
    tdata->func = func;
    tdata->done_func = done_func;
    tdata->data = data;

    ccnet_job_manager_schedule_job (job_mgr ? job_mgr : processor->session->job_mgr,
                                    processor_thread_func_wrapper,
                                    processor_thread_done,
                                    tdata);
    processor->thread_running = TRUE;
    return 0;
}
Exemplo n.º 12
0
int
block_tx_server_start (evutil_socket_t data_fd)
{
    BlockTxServer *server = g_new0 (BlockTxServer, 1);
    int ret = 0;

    int val = 1;
    ev_socklen_t optlen = sizeof(int);
    setsockopt (data_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, optlen);

    server->data_fd = data_fd;

    ret = ccnet_job_manager_schedule_job (seaf->job_mgr,
                                          block_tx_server_thread,
                                          block_tx_server_thread_done,
                                          server);
    if (ret < 0) {
        seaf_warning ("Failed to start block tx server thread.\n");
        return -1;
    }

    return 0;
}
Exemplo n.º 13
0
int
seaf_wt_monitor_start (SeafWTMonitor *monitor)
{
    if (ccnet_pipe (monitor->cmd_pipe) < 0) {
        seaf_warning ("[wt mon] failed to create command pipe: %s.\n",
                      strerror(errno));
        return -1;
    }

    if (ccnet_pipe (monitor->res_pipe) < 0) {
        seaf_warning ("[wt mon] failed to create result pipe: %s.\n",
                      strerror(errno));
        return -1;
    }

    if (ccnet_job_manager_schedule_job (monitor->seaf->job_mgr,
                                        monitor->job_func,
                                        NULL, monitor) < 0) {
        seaf_warning ("[wt mon] failed to start monitor thread.\n");
        return -1;
    }

    return 0;
}