Пример #1
0
// ---------------------------------------------------------------------
//  debugging_dump
// ---------------------------------------------------------------------
void debugging_dump(sorter* h, int dump_sorter_flag,
                    dc_profile *start, dc_profile *end) {

#if VERBOSE == 1
    int num_leaves, leaves_depth;

#if DEBUG > 0
    if (dump_sorter_flag) _sorter(dump)(h);
#endif

#if TREE_DUMP > 0
    if (dump_sorter_flag) _sorter(tree_dump)(h);
#endif

    dc_dump_profile_diff(stdout, start, end);
    printf("max sorter depth = %d\n",
           _sorter(depth)(h,&num_leaves,&leaves_depth));
    printf("avg sorter depth = %.3f\n",1.0*leaves_depth/num_leaves);
#endif
}
Пример #2
0
// ---------------------------------------------------------------------
//  test_small 3
// ---------------------------------------------------------------------
void test_small(unsigned long long* count) {

    dc_profile init, start, end;
    rlist* in  = rlist_new_rand(N, MAX_VAL);
    rlist* out = rlist_new();

    printf("list length=%d\n", rlist_length(in));

    puts("--initial list in/out");
    dump(in, out, count);

    puts("--making sorter");
    sorter* h = _sorter(new)(in, out);
    if (h == NULL) {
        printf("error: cannot initialize sorter\n");
        exit(0);
    }
    dump(in, out, count);
#if DEBUG > 0
    _sorter(dump)(h);
#endif

    puts("\n--making rnd insert operations on input list");
    dc_fetch_profile_info(&init);
    int val;

    rnode *prev;
    size_t num_update, i, j;
    int updates[UPD];

    srand(17);
    for (i=0; i<UPD; i++) updates[i] = rand();

    for (num_update=0; num_update<UPD; num_update++) {
        i = updates[num_update] % rlist_length(in);

        if (i==0) {
            val = rand() % MAX_VAL;
            printf("\n--update %u: insert value %u in position %u\n",
                   num_update+1, val, i+1);
            dc_fetch_profile_info(&start);
            rlist_insert_first(in, val);
            dc_fetch_profile_info(&end);
            debugging_dump(h, 1, &start, &end);
            check_correctness(in, out);
            continue;
        }

        // i>0: update is not on the first item
        prev = rlist_first(in);
        for (j=1; j<i; j++) prev = rlist_next(prev);

        val = rand() % MAX_VAL;
        printf("\n--update %u: insert value %u in position %u\n",
               num_update+1, val, i+1);
        dc_fetch_profile_info(&start);
        rlist_insert_next(in, prev, val);
        dc_fetch_profile_info(&end);
        debugging_dump(h, 1, &start, &end);
        check_correctness(in, out);
    }

    dc_fetch_profile_info(&end);
    printf("\n--sequence report\n");
    debugging_dump(h, 0, &init, &end);
    check_correctness(in, out);

    puts("\n--disposing of sorter");
    _sorter(delete)(h);
    dump(in, out, count);

    puts("\n--deleting lists");
    rlist_delete(in);
    rlist_delete(out);
}
Пример #3
0
// ---------------------------------------------------------------------
//  test_small 1
// ---------------------------------------------------------------------
void test_small(unsigned long long* count) {

    dc_profile init, start, end;
    rlist* in  = rlist_new_rand(N, MAX_VAL);
    rlist* out = rlist_new();

    printf("list length=%d\n", rlist_length(in));

    puts("--initial list in/out");
    dump(in, out, count);

    puts("--making sorter");
    dc_fetch_profile_info(&init);
    sorter* h = _sorter(new)(in, out);
    if (h == NULL) {
        printf("error: cannot initialize sorter\n");
        exit(0);
    }
    dump(in, out, count);
    dc_fetch_profile_info(&end);
    debugging_dump(h, 1, &init, &end);
    check_correctness(in, out);
#if DEBUG > 0
    _sorter(dump)(h);
#endif

    puts("\n--making ins/rem operations on input list");
    size_t num_updates = 0, i = 1;
    dc_fetch_profile_info(&init);
    int val;

    printf("\n--remove item %u of %u\n", i, N);
    dc_fetch_profile_info(&start);
    val = rlist_val(rlist_first(in));
    rlist_remove_first(in);
#if DUMP == 1
    dump(in, out, count);
#endif
    dc_fetch_profile_info(&end);
    debugging_dump(h, 1, &start, &end);
    check_correctness(in, out);

    printf("\n--re-insert %u of %u\n", i, N);
    dc_fetch_profile_info(&start);
    rlist_insert_first(in, val);
#if DUMP == 1
    dump(in, out, count);
#endif
    dc_fetch_profile_info(&end);
    debugging_dump(h, 1, &start, &end);
    check_correctness(in, out);

    rnode *prev;
    i++;
    for (prev = rlist_first(in);
            prev != NULL && rlist_next(prev) != NULL;
            prev = rlist_next(prev), i++) {

        val = rlist_val(rlist_next(prev));

        printf("\n--remove item %u of %u\n", i, N);
        dc_fetch_profile_info(&start);
        rlist_remove_next(in, prev);
#if DUMP == 1
        dump(in, out, count);
#endif
        dc_fetch_profile_info(&end);
        debugging_dump(h, 1, &start, &end);
        check_correctness(in, out);

        printf("\n--re-insert %u of %u\n", i, N);
        dc_fetch_profile_info(&start);
        rlist_insert_next(in, prev, val);
#if DUMP == 1
        dump(in, out, count);
#endif
        dc_fetch_profile_info(&end);
        debugging_dump(h, 1, &start, &end);
        check_correctness(in, out);

        num_updates += 2;
    }

    dc_fetch_profile_info(&end);
    printf("\n--sequence report\n");
    debugging_dump(h, 0, &init, &end);
    check_correctness(in, out);

    puts("\n--disposing of sorter");
    _sorter(delete)(h);
    dump(in, out, count);

    puts("\n--deleting lists");
    rlist_delete(in);
    rlist_delete(out);
}
Пример #4
0
GError*
meta1_backend_services_relink(struct meta1_backend_s *m1,
                              struct oio_url_s *url, const char *kept, const char *replaced,
                              gboolean dryrun, gchar ***out)
{
    GError *err = NULL;
    struct meta1_service_url_s **ukept = NULL, **urepl = NULL;
    /* fields to be prefetched */
    struct grid_lb_iterator_s *iterator = NULL;
    struct compound_type_s ct;

    memset (&ct, 0, sizeof(ct));
    ukept = __parse_and_expand (kept);
    urepl = __parse_and_expand (replaced);

    /* Sanity checks: we must receive at least one service */
    if ((!ukept || !*ukept) && (!urepl || !*urepl)) {
        err = NEWERROR (CODE_BAD_REQUEST, "Missing URL set");
        goto out;
    }
    /* Sanity check : all the services must have the same <seq,type> */
    struct meta1_service_url_s *ref = ukept && *ukept ? *ukept : *urepl;
    for (struct meta1_service_url_s **p = ukept; p && *p ; ++p) {
        if (0 != _sorter(p, &ref)) {
            err = NEWERROR(CODE_BAD_REQUEST, "Mismatch in URL set (%s)", "kept");
            goto out;
        }
    }
    for (struct meta1_service_url_s **p = urepl; p && *p ; ++p) {
        if (0 != _sorter(p, &ref)) {
            err = NEWERROR(CODE_BAD_REQUEST, "Mismatch in URL set (%s)", "kept");
            goto out;
        }
    }

    /* prefetch some fields from the backend: the compound type (so it is
     * parsed only once), the iterator (so we can already poll services, out
     * of the sqlite3 transaction) */
    if (NULL != (err = compound_type_parse(&ct, ref->srvtype))) {
        err = NEWERROR(CODE_BAD_REQUEST, "Invalid service type");
        goto out;
    }
    if (NULL != (err = _get_iterator (m1, &ct, &iterator))) {
        err = NEWERROR(CODE_BAD_REQUEST, "Service type not managed");
        goto out;
    }

    /* Call the backend logic now */
    struct sqlx_sqlite3_s *sq3 = NULL;
    struct sqlx_repctx_s *repctx = NULL;
    if (!(err = _open_and_lock(m1, url, M1V2_OPENBASE_MASTERONLY, &sq3))) {
        if (!(err = sqlx_transaction_begin(sq3, &repctx))) {
            if (!(err = __info_user(sq3, url, FALSE, NULL))) {
                struct m1v2_relink_input_s in = {
                    .m1 = m1, .sq3 = sq3, .url = url,
                    .iterator = iterator, .ct = &ct,
                    .kept = ukept, .replaced = urepl,
                    .dryrun = dryrun
                };
                err = __relink_container_services(&in, out);
            }
            if (!(err = sqlx_transaction_end(repctx, err))) {
                if (!dryrun)
                    __notify_services_by_cid(m1, sq3, url);
            }
        }
        sqlx_repository_unlock_and_close_noerror(sq3);
    }

out:
    meta1_service_url_cleanv (ukept);
    meta1_service_url_cleanv (urepl);
    grid_lb_iterator_clean (iterator);
    compound_type_clean (&ct);
    return err;
}