CTEST(basement, insert_and_lookup) { int i; int ret; int R = 1000; char kbuf[KEY_SIZE]; char vbuf[VAL_SIZE]; struct basement_iter iter; struct basement *bsm = basement_new(); struct msg **msgs = xcalloc(R, sizeof(*msgs)); struct txnid_pair xidpair = { .child_xid = TXNID_NONE, .parent_xid = TXNID_NONE }; MSN msn = 0U; _random_key(vbuf, VAL_SIZE); for (i = 0; i < R; i++) { memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-%d", i); struct msg k = {.data = kbuf, .size = KEY_SIZE}; struct msg v = {.data = vbuf, .size = VAL_SIZE}; msgs[i] = msgdup(&k); basement_put(bsm, msn++, MSG_INSERT, &k, &v, &xidpair ); } basement_iter_init(&iter, bsm); basement_iter_seektolast(&iter); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); for (i = 0; i < R; i++) { basement_iter_seek(&iter, msgs[i]); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); ret = msg_key_compare(msgs[i], &iter.key); ASSERT_EQUAL(0, ret); } /* do msg free */ for (i = 0; i < R; i++) { xfree(msgs[i]->data); xfree(msgs[i]); } xfree(msgs); basement_free(bsm); xcheck_all_free(); }
void _write_test(long int count) { int i; double cost; long long start, end; struct slice sk, sv; struct index *idx; char key[KSIZE]; char val[VSIZE]; idx = _get_idx(); printf("count : %ld, idx : %p\n", count, idx); start = _ustime(); for (i = 0; i < count; i++) { _random_key(key, KSIZE); snprintf(val, VSIZE, "val:%d", i); sk.len = KSIZE; sk.data = key; sv.len = VSIZE; sv.data = val; index_add(idx, &sk, &sv); if ((i % 10000) == 0) { fprintf(stderr, "random write finished %d ops%30s\r", i, ""); fflush(stderr); } } index_free(idx); end = _ustime(); cost = end - start; printf(LINE); printf("|Random-Write (done:%ld): %.6f sec/op; %.1f writes/sec(estimates); cost:%.3f(sec)\n", count, (double)(cost / count), (double)(count / cost), cost); }
void _read_test(long int count) { int hint_count = 0; int i; int ret; double cost; char key[KSIZE]; long long start, end; struct slice sk; struct slice sv; struct index *idx; idx = _get_idx(); start = _ustime(); for(i = 0; i < count; i++) { _random_key(key, KSIZE); sk.len = KSIZE; sk.data = key; ret = index_get(idx, &sk, &sv); if(ret) { hint_count++; free(sv.data); } if((i%10000) == 0) { fprintf(stderr, "random read finished %d ops%30s\r", i, ""); fflush(stderr); } } index_free(idx); end = _ustime(); cost = end - start; printf(LINE); printf("|Random-Read (done:%ld): %.6f sec/op; %.1f reads/sec(estimated); cost:%.3f(sec)\n", count, (double)(cost/count), (double)(count/cost), cost); printf("hint_count : %d\n", hint_count ); }
CTEST(basement, multiversion) { int i; int ret; int R = 123; char kbuf[KEY_SIZE]; char vbuf[VAL_SIZE]; struct basement_iter iter; struct basement *bsm = basement_new(); struct txnid_pair xidpair = { .child_xid = TXNID_NONE, .parent_xid = TXNID_NONE }; _random_key(vbuf, VAL_SIZE); MSN msn = 0U; for (i = 0; i < R; i++) { memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-%d", i); struct msg k = {.data = kbuf, .size = KEY_SIZE}; struct msg v = {.data = vbuf, .size = VAL_SIZE}; basement_put(bsm, msn++, MSG_INSERT, &k, &v, &xidpair ); } /* 3 versions of key-66 */ R = 3; for (i = 0; i < R; i++) { memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-66"); struct msg k = {.data = kbuf, .size = KEY_SIZE}; struct msg v = {.data = vbuf, .size = VAL_SIZE}; basement_put(bsm, msn++, MSG_INSERT, &k, &v, &xidpair ); } /* 5 versions of key-88 */ R = 5; for (i = 0; i < R; i++) { memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-88"); struct msg k = {.data = kbuf, .size = KEY_SIZE}; struct msg v = {.data = vbuf, .size = VAL_SIZE}; basement_put(bsm, msn++, MSG_INSERT, &k, &v, &xidpair ); } /* key-66 */ memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-66"); struct msg k1 = {.data = kbuf, .size = KEY_SIZE}; basement_iter_init(&iter, bsm); basement_iter_seek(&iter, &k1); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); ASSERT_EQUAL(66, iter.msn); basement_iter_next(&iter); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); ASSERT_EQUAL(123, iter.msn); /* less than valid */ ret = basement_iter_valid_lessorequal(&iter, &k1); ASSERT_EQUAL(1, ret); memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-67"); k1.size = KEY_SIZE; k1.data = kbuf; ret = basement_iter_valid_lessorequal(&iter, &k1); ASSERT_EQUAL(1, ret); memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-65"); k1.size = KEY_SIZE; k1.data = kbuf; ret = basement_iter_valid_lessorequal(&iter, &k1); ASSERT_EQUAL(0, ret); /* key-88 */ memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-88"); struct msg k2 = {.data = kbuf, .size = KEY_SIZE}; basement_iter_seek(&iter, &k2); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); ASSERT_EQUAL(88, iter.msn); basement_iter_next(&iter); basement_iter_next(&iter); ret = basement_iter_valid(&iter); ASSERT_EQUAL(1, ret); ASSERT_EQUAL(127, iter.msn); /* next&prev diff key */ /* key-87 */ memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-87"); struct msg k3 = {.data = kbuf, .size = KEY_SIZE}; basement_iter_prev_diff_key(&iter); ret = msg_key_compare(&k3, &iter.key); ASSERT_EQUAL(0, ret); /* key-88 */ basement_iter_next(&iter); memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-88"); struct msg k22 = {.data = kbuf, .size = KEY_SIZE}; ret = msg_key_compare(&k22, &iter.key); ASSERT_EQUAL(0, ret); /* key-89 */ memset(kbuf, 0, KEY_SIZE); snprintf(kbuf, KEY_SIZE, "key-89"); struct msg k4 = {.data = kbuf, .size = KEY_SIZE}; basement_iter_next_diff_key(&iter); ret = msg_key_compare(&k4, &iter.key); ASSERT_EQUAL(0, ret); basement_free(bsm); xcheck_all_free(); }