Commit 43c7b4d1 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

[t:4115] Candidate for #4115. Refs #4115.

git-svn-id: file:///svn/toku/tokudb@36795 c7de825b-a66e-492c-adef-691d508d4ae1
parent c94a0c04
...@@ -6810,6 +6810,7 @@ static int keyrange_compare (OMTVALUE lev, void *extra) { ...@@ -6810,6 +6810,7 @@ static int keyrange_compare (OMTVALUE lev, void *extra) {
static void keyrange_in_leaf_partition (BRT brt, BRTNODE node, DBT *key, int child_number, int estimated_row_size, static void keyrange_in_leaf_partition (BRT brt, BRTNODE node, DBT *key, int child_number, int estimated_row_size,
u_int64_t *less, u_int64_t *equal, u_int64_t *greater) u_int64_t *less, u_int64_t *equal, u_int64_t *greater)
// If the partition is in main memory then estimate the number // If the partition is in main memory then estimate the number
// If KEY==NULL then use an arbitrary key (leftmost or zero)
{ {
assert(node->height==0); // we are in a leaf assert(node->height==0); // we are in a leaf
if (BP_STATE(node, child_number) == PT_AVAIL) { if (BP_STATE(node, child_number) == PT_AVAIL) {
...@@ -6818,7 +6819,8 @@ static void keyrange_in_leaf_partition (BRT brt, BRTNODE node, DBT *key, int chi ...@@ -6818,7 +6819,8 @@ static void keyrange_in_leaf_partition (BRT brt, BRTNODE node, DBT *key, int chi
BASEMENTNODE bn = BLB(node, child_number); BASEMENTNODE bn = BLB(node, child_number);
OMTVALUE datav; OMTVALUE datav;
u_int32_t idx = 0; u_int32_t idx = 0;
int r = toku_omt_find_zero(bn->buffer, keyrange_compare, &s, &datav, &idx); // if key is NULL then set r==-1 and idx==0.
int r = key ? toku_omt_find_zero(bn->buffer, keyrange_compare, &s, &datav, &idx) : -1;
if (r==0) { if (r==0) {
*less = idx; *less = idx;
*equal = 1; *equal = 1;
...@@ -6865,7 +6867,8 @@ static int toku_brt_keyrange_internal (BRT brt, BRTNODE node, ...@@ -6865,7 +6867,8 @@ static int toku_brt_keyrange_internal (BRT brt, BRTNODE node,
// Implementation note: Assign values to less, equal, and greater, and then on the way out (returning up the stack) we add more values in. // Implementation note: Assign values to less, equal, and greater, and then on the way out (returning up the stack) we add more values in.
{ {
int r = 0; int r = 0;
int child_number = toku_brtnode_which_child (node, key, &brt->h->descriptor, brt->compare_fun); // if KEY is NULL then use the leftmost key.
int child_number = key ? toku_brtnode_which_child (node, key, &brt->h->descriptor, brt->compare_fun) : 0;
if (node->height==0) { if (node->height==0) {
// we are at the leaf. // we are at the leaf.
keyrange_in_leaf_partition(brt, node, key, child_number, estimated_row_size, less, equal, greater); keyrange_in_leaf_partition(brt, node, key, child_number, estimated_row_size, less, equal, greater);
...@@ -6914,6 +6917,7 @@ int toku_brt_keyrange (BRT brt, DBT *key, u_int64_t *less_p, u_int64_t *equal_p, ...@@ -6914,6 +6917,7 @@ int toku_brt_keyrange (BRT brt, DBT *key, u_int64_t *less_p, u_int64_t *equal_p,
// The values are an estimate. // The values are an estimate.
// If you perform a keyrange on two keys that are in the same in-memory leaf entry, you can the keys_right numbers (or the keys_left) numbers // If you perform a keyrange on two keys that are in the same in-memory leaf entry, you can the keys_right numbers (or the keys_left) numbers
// to get an exact number keys in the range. // to get an exact number keys in the range.
// If KEY is NULL then the system picks an arbitrary key and returns it.
{ {
try_again: try_again:
{ {
...@@ -6994,9 +6998,8 @@ int toku_brt_stat64 (BRT brt, TOKUTXN UU(txn), struct brtstat64_s *s) { ...@@ -6994,9 +6998,8 @@ int toku_brt_stat64 (BRT brt, TOKUTXN UU(txn), struct brtstat64_s *s) {
#else #else
// A hack for now. // A hack for now.
{ {
DBT key = {.size=0, .data=""};
u_int64_t less=0, equal=0, greater=0; u_int64_t less=0, equal=0, greater=0;
int r = toku_brt_keyrange(brt, &key, &less, &equal, &greater); int r = toku_brt_keyrange(brt, NULL, &less, &equal, &greater);
assert(r==0); assert(r==0);
s->nkeys = less + equal + greater; s->nkeys = less + equal + greater;
s->ndata = less + equal + greater; s->ndata = less + equal + greater;
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "$Id$"
#ident "Copyright (c) 2008 Tokutek Inc. All rights reserved."
// Test toku_brt_stat64 to make sure it works even if the comparison function won't allow an arbitrary prefix of the key to work.
#include "includes.h"
#include "test.h"
#include <unistd.h>
static TOKUTXN const null_txn = 0;
static DB * const null_db = 0;
char fname[]= __FILE__ ".brt";
CACHETABLE ct;
BRT t;
int keysize = 9;
static int dont_allow_prefix (DB *db __attribute__((__unused__)), const DBT *a, const DBT *b) {
assert(a->size==9 && b->size==9);
return toku_keycompare(a->data, a->size, b->data, b->size);
}
static void close_brt_and_ct (void) {
int r;
r = toku_close_brt(t, 0); assert(r==0);
r = toku_cachetable_close(&ct); assert(r==0);
}
static void open_brt_and_ct (bool unlink_old) {
int r;
if (unlink_old) unlink(fname);
r = toku_brt_create_cachetable(&ct, 0, ZERO_LSN, NULL_LOGGER); assert(r==0);
r = toku_open_brt(fname, 1, &t, 1<<12, 1<<9, ct, null_txn, toku_builtin_compare_fun, null_db); assert(r==0);
r = toku_brt_set_bt_compare(t, dont_allow_prefix);
}
static void test_4115 (void) {
u_int64_t limit=30000;
open_brt_and_ct(true);
for (u_int64_t i=0; i<limit; i++) {
char key[100],val[100];
snprintf(key, 100, "%08llu", (unsigned long long)2*i+1);
snprintf(val, 100, "%08llu", (unsigned long long)2*i+1);
DBT k,v;
int r = toku_brt_insert(t, toku_fill_dbt(&k, key, 1+strlen(key)), toku_fill_dbt(&v,val, 1+strlen(val)), null_txn);
assert(r == 0);
}
struct brtstat64_s s;
int r = toku_brt_stat64(t, NULL, &s);
assert(r==0);
assert(s.nkeys>0);
assert(s.dsize>0);
close_brt_and_ct();
}
int
test_main (int argc , const char *argv[]) {
default_parse_args(argc, argv);
test_4115();
if (verbose) printf("test ok\n");
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment