コード例 #1
0
ファイル: jstatctl.c プロジェクト: trws/flux-core
static int update_rdl (flux_t *h, int64_t j, const char *rs)
{
    int rc = -1;
    char *key = lwj_key (h, j, ".rdl");
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    if (flux_kvs_txn_pack (txn, 0, key, "s", rs) < 0) {
        flux_log_error (h, "update %s", key);
        goto done;
    }
    if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) {
        flux_log_error (h, "commit failed");
        goto done;
    }
    flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new rdl.", j);
    rc = 0;

done:
    flux_kvs_txn_destroy (txn);
    flux_future_destroy (f);
    free (key);

    return rc;
}
コード例 #2
0
ファイル: jstatctl.c プロジェクト: trws/flux-core
static int update_rdesc (flux_t *h, int64_t j, json_object *o)
{
    int rc = -1;
    int64_t nnodes = 0;
    int64_t ntasks = 0;
    int64_t walltime = 0;
    char *key1 = NULL;
    char *key2 = NULL;
    char *key3 = NULL;
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!Jget_int64 (o, JSC_RDESC_NNODES, &nnodes))
        goto done;
    if (!Jget_int64 (o, JSC_RDESC_NTASKS, &ntasks))
        goto done;
    if (!Jget_int64 (o, JSC_RDESC_WALLTIME, &walltime))
        goto done;
    if ((nnodes < 0) || (ntasks < 0) || (walltime < 0))
        goto done;
    key1 = lwj_key (h, j, ".nnodes");
    key2 = lwj_key (h, j, ".ntasks");
    key3 = lwj_key (h, j, ".walltime");
    if (!key1 || !key2 || !key3)
        goto done;
    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    if (flux_kvs_txn_pack (txn, 0, key1, "I", nnodes) < 0) {
        flux_log_error (h, "update %s", key1);
        goto done;
    }
    if (flux_kvs_txn_pack (txn, 0, key2, "I", ntasks) < 0) {
        flux_log_error (h, "update %s", key2);
        goto done;
    }
    if (flux_kvs_txn_pack (txn, 0, key3, "I", walltime) < 0) {
        flux_log_error (h, "update %s", key3);
        goto done;
    }
    if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) {
        flux_log_error (h, "commit failed");
        goto done;
    }
    flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new resources.", j);
    rc = 0;
done:
    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);
    free (key1);
    free (key2);
    free (key3);

    return rc;
}
コード例 #3
0
ファイル: commit.c プロジェクト: trws/flux-core
void *thread (void *arg)
{
    thd_t *t = arg;
    char *key, *fence_name = NULL;
    int i, flags = 0;
    struct timespec t0;
    uint32_t rank;
    flux_future_t *f;
    flux_kvs_txn_t *txn;

    if (!(t->h = flux_open (NULL, 0))) {
        log_err ("%d: flux_open", t->n);
        goto done;
    }
    if (flux_get_rank (t->h, &rank) < 0) {
        log_err ("%d: flux_get_rank", t->n);
        goto done;
    }
    for (i = 0; i < count; i++) {
        if (!(txn = flux_kvs_txn_create ()))
            log_err_exit ("flux_kvs_txn_create");
        key = xasprintf ("%s.%"PRIu32".%d.%d", prefix, rank, t->n, i);
        if (fopt)
            fence_name = xasprintf ("%s-%d", prefix, i);
        if (sopt)
            monotime (&t0);
        if (flux_kvs_txn_pack (txn, 0, key, "i", 42) < 0)
            log_err_exit ("%s", key);
        if (nopt && (i % nopt_divisor) == 0)
            flags |= FLUX_KVS_NO_MERGE;
        else
            flags = 0;
        if (fopt) {
            if (!(f = flux_kvs_fence (t->h, flags, fence_name,
                                                   fence_nprocs, txn))
                    || flux_future_get (f, NULL) < 0)
                log_err_exit ("flux_kvs_fence");
            flux_future_destroy (f);
        } else {
            if (!(f = flux_kvs_commit (t->h, flags, txn))
                    || flux_future_get (f, NULL) < 0)
                log_err_exit ("flux_kvs_commit");
            flux_future_destroy (f);
        }
        if (sopt && zlist_append (t->perf, ddup (monotime_since (t0))) < 0)
            oom ();
        free (key);
        free (fence_name);
        flux_kvs_txn_destroy (txn);
    }
done:
    if (t->h)
        flux_close (t->h);
    return NULL;
}
コード例 #4
0
ファイル: transactionmerge.c プロジェクト: trws/flux-core
void *watchthread (void *arg)
{
    thd_t *t = arg;
    watch_count_t wc;
    flux_kvs_txn_t *txn;
    flux_future_t *f;
    flux_reactor_t *r;
    flux_watcher_t *pw = NULL;
    flux_watcher_t *tw = NULL;

    if (!(t->h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    /* Make sure key doesn't already exist, initial value may affect
     * test by chance (i.e. initial value = 0, commit 0 and thus no
     * change)
     */
    if (!(txn = flux_kvs_txn_create ()))
        log_err_exit ("flux_kvs_txn_create");
    if (flux_kvs_txn_unlink (txn, 0, key) < 0)
        log_err_exit ("flux_kvs_txn_unlink");
    if (!(f = flux_kvs_commit (t->h, 0, txn)) || flux_future_get (f, NULL) < 0)
        log_err_exit ("flux_kvs_commit");
    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);

    r = flux_get_reactor (t->h);

    if (flux_kvs_watch (t->h, key, watch_count_cb, t) < 0)
        log_err_exit ("flux_kvs_watch %s", key);

    pw = flux_prepare_watcher_create (r, watch_prepare_cb, NULL);

    wc.t = t;
    wc.lastcount = -1;

    /* So test won't hang if there's a bug */
    tw = flux_timer_watcher_create (r,
                                    WATCH_TIMEOUT,
                                    WATCH_TIMEOUT,
                                    watch_timeout_cb,
                                    &wc);

    flux_watcher_start (pw);
    flux_watcher_start (tw);

    if (flux_reactor_run (r, 0) < 0)
        log_err_exit ("flux_reactor_run");

    flux_watcher_destroy (pw);
    flux_watcher_destroy (tw);
    flux_close (t->h);
    return NULL;
}
コード例 #5
0
ファイル: jstatctl.c プロジェクト: trws/flux-core
static int update_rdl_alloc (flux_t *h, int64_t j, json_object *o)
{
    int i = 0;
    int rc = -1;
    int size = 0;
    json_object *ra_e = NULL;
    const char *key = NULL;
    zhash_t *rtab = NULL;
    int64_t *ncores = NULL;
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!(rtab = zhash_new ()))
        oom ();
    if (!Jget_ar_len (o, &size))
        goto done;

    for (i=0; i < (int) size; ++i) {
        if (!Jget_ar_obj (o, i, &ra_e))
            goto done;
        /* 'o' represents an array of per-node core count to use.
         * However, becasue the same rank can appear multiple times
         * in this array in emulation mode, update_hash_1ra is
         * used to determine the total core count per rank.
         */
        if ( (rc = update_hash_1ra (h, j, ra_e, rtab)) < 0)
            goto done;
    }

    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    FOREACH_ZHASH (rtab, key, ncores) {
        if ( (rc = flux_kvs_txn_pack (txn, 0, key, "I", *ncores)) < 0) {
            flux_log_error (h, "put %s", key);
            goto done;
        }
    }
    if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) {
        flux_log (h, LOG_ERR, "update_pdesc commit failed");
        goto done;
    }
    rc = 0;

done:
    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);
    zhash_destroy (&rtab);
    return rc;
}
コード例 #6
0
flux_future_t *commit_int (flux_t *h, const char *k, int v)
{
    flux_kvs_txn_t *txn;
    flux_future_t *f;

    if (!(txn = flux_kvs_txn_create ()))
        log_err_exit ("flux_kvs_txn_create");
    if (flux_kvs_txn_pack (txn, 0, k, "i", v) < 0)
        log_err_exit ("flux_kvs_txn_pack");
    if (!(f = flux_kvs_commit (h, ns, FLUX_KVS_NO_MERGE, txn)))
        log_err_exit ("flux_kvs_commit");
    flux_kvs_txn_destroy (txn);
    if (verbose)
        printf("> %s=%d\n", k, v);
    return f;
}
コード例 #7
0
ファイル: job-manager-dummy.c プロジェクト: grondo/flux-core
/* Given a JSON array of job records, add an eventlog
 * update for each job to a KVS transaction and return it.
 */
static flux_kvs_txn_t *create_eventlog_txn (json_t *jobs)
{
    flux_kvs_txn_t *txn;
    size_t index;
    json_t *job;

    if (!(txn = flux_kvs_txn_create ()))
        return NULL;
    json_array_foreach (jobs, index, job) {
        char *event = create_eventlog_entry (job);
        if (!event)
            goto error;
        if (flux_kvs_txn_put (txn, FLUX_KVS_APPEND, eventlog_path, event) < 0) {
            int saved_errno = errno;
            free (event);
            errno = saved_errno;
            goto error;
        }
        free (event);
    }
コード例 #8
0
ファイル: jstatctl.c プロジェクト: trws/flux-core
static int update_pdesc (flux_t *h, int64_t j, json_object *o)
{
    int i = 0;
    int rc = -1;
    int64_t size = 0;
    json_object *h_arr = NULL;
    json_object *e_arr = NULL;
    json_object *pd_arr = NULL;
    json_object *pde = NULL;
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!Jget_int64 (o, JSC_PDESC_SIZE, &size))
        goto done;
    if (!Jget_obj (o, JSC_PDESC_PDARRAY, &pd_arr))
        goto done;
    if (!Jget_obj (o, JSC_PDESC_HOSTNAMES, &h_arr))
        goto done;
    if (!Jget_obj (o, JSC_PDESC_EXECS, &e_arr))
        goto done;
    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    for (i=0; i < (int) size; ++i) {
        if (!Jget_ar_obj (pd_arr, i, &pde))
            goto done;
        if ( (rc = update_1pdesc (h, txn, i, j, pde, h_arr, e_arr)) < 0)
            goto done;
    }
    if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) {
        flux_log (h, LOG_ERR, "update_pdesc commit failed");
        goto done;
    }
    rc = 0;

done:
    flux_kvs_txn_destroy (txn);
    flux_future_destroy (f);
    return rc;
}
コード例 #9
0
ファイル: jstatctl.c プロジェクト: trws/flux-core
static int update_state (flux_t *h, int64_t j, json_object *o)
{
    int rc = -1;
    int64_t st = 0;
    char *key = NULL;
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &st))
        goto done;
    if ((st >= J_FOR_RENT) || (st < J_NULL))
        goto done;
    if (!(key = lwj_key (h, j, ".state")))
        goto done;
    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    if (flux_kvs_txn_pack (txn, 0, key, "s",
                           jsc_job_num2state ((job_state_t)st)) < 0) {
        flux_log_error (h, "update %s", key);
        goto done;
    }
    if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) {
        flux_log_error (h, "commit %s", key);
        goto done;
    }
    flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new state: %s", j,
          jsc_job_num2state ((job_state_t)st));
    rc = 0;

    if (send_state_event (h, st, j) < 0)
        flux_log_error (h, "send state event");

done:
    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);
    free (key);
    return rc;
}
コード例 #10
0
ファイル: transactionmerge.c プロジェクト: trws/flux-core
void *committhread (void *arg)
{
    thd_t *t = arg;
    flux_kvs_txn_t *txn;
    flux_future_t *f;

    if (!(t->h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    if (!(txn = flux_kvs_txn_create ()))
        log_err_exit ("flux_kvs_txn_create");
    if (flux_kvs_txn_pack (txn, 0, key, "i", t->n) < 0)
        log_err_exit ("%s", key);
    if (!(f = flux_kvs_commit (t->h, nopt ? FLUX_KVS_NO_MERGE : 0, txn))
            || flux_future_get (f, NULL) < 0)
        log_err_exit ("flux_kvs_commit");

    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);
    flux_close (t->h);
    return NULL;
}