A Query about rados read op API behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm not sure about the behavior of the function call rados_read_op_operate. 
I'm hoping someone on this list can clarify and confirm that what I'm seeing is 
expected behavior.

When I was first looking at this call I assumed that if one created a 
rados_read_op_t (shortened as "op" later) and populated it with "steps" you'd 
be able to call rados_read_op_operate with the op on more than one different 
object. However, this does not seem to be the case. When I call 
rados_read_op_operate a second time, the function returns but the items passed 
in to the "step" calls do not change, unlike the first time the function is 
called. 

I have attached a C file that tries to demonstrate what I mean. The function 
print_one_omap works as expected when called on two times on different objects. 
The function print_two_omaps is passed two objects to read but only data for 
the first is printed. (I also try to dump data but I was originally testing 
with omaps only - thus the function names. Also please excuse and bad C code, 
I don't usually write in C but wanted to confirm this behavior occurred when 
using the C api.)


What I'd like to ask is if this is intended behavior. If not, I'll be happy to 
file a bug, but from the code I skimmed and the function doc comments, its not 
clear to me what is supposed to happen.

If anyone on this list can shed some light on this I'd greatly appreciate it.

--John M.
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <rados/librados.h>

int set_omap(rados_t cluster, rados_ioctx_t ioctx, const char *oid) {
    int failed = 0;
    int ret;
    const char *keys[] = {"foo", "bar", "baz"};
    const char *vals[] = {"abc", "123", "456"};
    size_t lens[] = {3, 3, 3};

    printf("Setting omap on %s ...\n", oid);
    rados_write_op_t wr = rados_create_write_op();
    rados_write_op_create(wr, LIBRADOS_CREATE_IDEMPOTENT, NULL);
    rados_write_op_omap_set2(wr, keys, vals, lens, lens, 3);
    rados_write_op_write(wr, oid, 4, 0);
    rados_write_op_write(wr, "_FOO_BAR_BAZ", 11, 4);

    ret = rados_write_op_operate(wr, ioctx, oid, NULL, 0);
    if (ret != 0) {
        fprintf(stderr, "rados_write_op_operate failed. oid=%s\n", oid);
        failed = 1;
    }
    rados_release_write_op(wr);
    return failed;
}

int print_one_omap(rados_ioctx_t ioctx, const char *oid) {
    int failed = 0;
    int rval;
    int ret;
    rados_omap_iter_t iter;
    char *k;
    char *v;
    char b[32];
    size_t bread;

    rados_read_op_t rd = rados_create_read_op();
    rados_read_op_omap_get_vals2(rd, "", "", 1024, &iter, NULL, &rval);
    rados_read_op_read(rd, 0, 32, b, &bread, NULL);

    printf("Printing omap from %s:\n", oid);
    ret = rados_read_op_operate(rd, ioctx, oid, 0);
    if (ret != 0) {
        fprintf(stderr, "rados_read_op_operate failed. oid=%s\n", oid);
        failed = 1;
    } else if (rval != 0) {
        fprintf(stderr, "rval !=0. rval=%d\n", rval);
        failed = 1;
        rados_omap_get_end(iter);
    } else {
        while (1) {
            rados_omap_get_next2(iter, &k, &v, NULL, NULL);
            if (k == NULL) {
                break;
            }
            printf("  K:%s  V:%s\n", k, v);
        }
        rados_omap_get_end(iter);
    }
    if (bread > 0) {
        printf("  CONTENTS: %s\n", b);
    }
    return failed;
}

int print_two_omaps(rados_ioctx_t ioctx, const char *oid1, const char *oid2) {
    int failed = 0;
    int rval;
    int ret;
    rados_omap_iter_t iter;
    char *k;
    char *v;
    char b[32];
    size_t bread;

    rados_read_op_t rd = rados_create_read_op();
    rados_read_op_omap_get_vals2(rd, "", "", 1024, &iter, NULL, &rval);
    rados_read_op_read(rd, 0, 32, b, &bread, NULL);

    bread = 0;
    memset(b, 0, 32);
    printf("Printing omap from %s:\n", oid1);
    ret = rados_read_op_operate(rd, ioctx, oid1, LIBRADOS_OPERATION_IGNORE_CACHE);
    if (ret != 0) {
        fprintf(stderr, "rados_read_op_operate failed. oid=%s\n", oid1);
        failed = 1;
    } else if (rval != 0) {
        fprintf(stderr, "rval !=0. rval=%d\n", rval);
        failed = 1;
    } else {
        while (1) {
            rados_omap_get_next2(iter, &k, &v, NULL, NULL);
            if (k == NULL) {
                break;
            }
            printf("  K:%s  V:%s\n", k, v);
        }
    }
    if (bread > 0) {
        printf("  CONTENTS: %s\n", b);
    }

    bread = 0;
    memset(b, 0, 32);
    printf("Printing omap from %s:\n", oid2);
    ret = rados_read_op_operate(rd, ioctx, oid2, LIBRADOS_OPERATION_IGNORE_CACHE);
    if (ret != 0) {
        fprintf(stderr, "rados_read_op_operate failed. oid=%s\n", oid2);
        failed = 1;
    } else if (rval != 0) {
        fprintf(stderr, "rval !=0. rval=%d\n", rval);
        failed = 1;
    } else {
        while (1) {
            rados_omap_get_next2(iter, &k, &v, NULL, NULL);
            if (k == NULL) {
                break;
            }
            printf("  K:%s  V:%s\n", k, v);
        }
    }
    if (bread > 0) {
        printf("  CONTENTS: %s\n", b);
    }

    rados_omap_get_end(iter);
    return failed;
}

int omap_test(rados_t cluster) {
    char *pool_name = "testpool";
    int failed = 0;
    int ret;
    rados_ioctx_t ioctx;

    ret = rados_ioctx_create(cluster, pool_name, &ioctx);
    if (ret != 0) {
        fprintf(stderr, "rados_ioctx_create failed\n");
        return 1;
    }

    failed = set_omap(cluster, ioctx, "alpha");
    if (failed) {
        goto done;
    }
    failed = set_omap(cluster, ioctx, "beta");
    if (failed) {
        goto done;
    }

    failed = print_one_omap(ioctx, "alpha");
    if (failed) {
        goto done;
    }
    failed = print_one_omap(ioctx, "beta");
    if (failed) {
        goto done;
    }

    failed = print_two_omaps(ioctx, "beta", "alpha");
    if (failed) {
        goto done;
    }

done:
    rados_ioctx_destroy(ioctx);
    return failed;
}

int main(void) {
    rados_t cluster;
    int ret;
    int failed = 0;

    ret = rados_create(&cluster, NULL);
    if (ret != 0) {
        failed = 1;
        fprintf(stderr, "rados_create failed\n");
        goto done;
    }
    ret = rados_conf_read_file(cluster, NULL);
    if (ret != 0) {
        failed = 1;
        fprintf(stderr, "rados_conf_read_file failed\n");
        goto done;
    }
    ret = rados_connect(cluster);
    if (ret != 0) {
        failed = 1;
        fprintf(stderr, "rados_connect failed\n");
        goto done;
    }

    failed = omap_test(cluster);
    rados_shutdown(cluster);

done:
    return failed;
}
_______________________________________________
Dev mailing list -- dev@xxxxxxx
To unsubscribe send an email to dev-leave@xxxxxxx

[Index of Archives]     [CEPH Users]     [Ceph Devel]     [Ceph Large]     [Information on CEPH]     [Linux BTRFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux