/* program to test omap writes of very large lists of key-value pairs * to compile & link: * # cc -g -o rados-omap rados-omap.c -lrados * to run: * # ./rados-omap */ #include #include #include #include #include #define NULLCP ((char * )0L) #define NULL_DELIM ((char )0) static rados_t cluster; static int cluster_exists = 0; static rados_ioctx_t io; static int io_exists = 0; enum omap_optype { omap_read = 0, omap_write = 1 }; enum int_parse_type { signed_int=0, non_negative=1, positive=2 }; static char * op_type_strs[] = { "read", "write" }; /* you can put your fprintf statement as first parameter */ static void cleanup(int fprintf_result) { if (io_exists) rados_ioctx_destroy(io); if (cluster_exists) rados_shutdown(cluster); fprintf(stderr, "\nusage: rados-omap --operation read|write --kvpairs-per-call --total-kvpairs --value-size \n"); exit(EXIT_FAILURE); } int parse_int( const char * v, const char * msg, enum int_parse_type parse_type ) { int result = atoi(v); if (result == 0 && strcmp(v, "0")) cleanup( fprintf(stderr, "%s: not an integer", v)); if (parse_type == non_negative) { if (result >= 0) return result; } else if (parse_type == positive) { if (result > 0) return result; } else return result; cleanup( fprintf(stderr, "%s: not a positive integer value", v)); return -5; } /* construct the key-value pairs to input to librados */ void mk_kvpairs(const int kvpair_num, const int starting_key, const int value_size, char ***keys_out, char ***values_out, size_t **lens_out ) { const int safety_margin = 10; /* allocate a little more than you need */ char ** keys = (char ** )calloc(kvpair_num+1, sizeof(char * )); char ** vals = (char ** )calloc(kvpair_num+1, sizeof(char * )); size_t * lens = (size_t * )calloc(kvpair_num+1, sizeof(size_t)); int i, k; if (!keys || !vals || !lens) cleanup(fprintf(stderr, "could not allocate %d key-value pair arrays", kvpair_num)); for (i=0; i