Commit 77639084 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get rid of ERANGE in favor of EINVAL. And fix up a couple of test cases. Addresses #855, #856.

git-svn-id: file:///svn/tokudb@4333 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9185a854
...@@ -331,7 +331,7 @@ static inline void insert_internal(OMT omt, node_idx *n_idxp, OMTVALUE value, u_ ...@@ -331,7 +331,7 @@ static inline void insert_internal(OMT omt, node_idx *n_idxp, OMTVALUE value, u_
int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index) { int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index) {
int r; int r;
invalidate_cursors(omt); invalidate_cursors(omt);
if (index>nweight(omt, omt->root)) return ERANGE; if (index>nweight(omt, omt->root)) return EINVAL;
if ((r=maybe_resize_and_rebuild(omt, 1+nweight(omt, omt->root), MAYBE_REBUILD))) return r; if ((r=maybe_resize_and_rebuild(omt, 1+nweight(omt, omt->root), MAYBE_REBUILD))) return r;
node_idx* rebalance_idx = NULL; node_idx* rebalance_idx = NULL;
insert_internal(omt, &omt->root, value, index, &rebalance_idx); insert_internal(omt, &omt->root, value, index, &rebalance_idx);
...@@ -352,7 +352,7 @@ static inline void set_at_internal(OMT omt, node_idx n_idx, OMTVALUE v, u_int32_ ...@@ -352,7 +352,7 @@ static inline void set_at_internal(OMT omt, node_idx n_idx, OMTVALUE v, u_int32_
} }
int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index) { int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index) {
if (index>=nweight(omt, omt->root)) return ERANGE; if (index>=nweight(omt, omt->root)) return EINVAL;
set_at_internal(omt, omt->root, value, index); set_at_internal(omt, omt->root, value, index);
return 0; return 0;
} }
...@@ -400,7 +400,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index) { ...@@ -400,7 +400,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index) {
OMTVALUE v; OMTVALUE v;
int r; int r;
invalidate_cursors(omt); invalidate_cursors(omt);
if (index>=nweight(omt, omt->root)) return ERANGE; if (index>=nweight(omt, omt->root)) return EINVAL;
if ((r=maybe_resize_and_rebuild(omt, -1+nweight(omt, omt->root), MAYBE_REBUILD))) return r; if ((r=maybe_resize_and_rebuild(omt, -1+nweight(omt, omt->root), MAYBE_REBUILD))) return r;
node_idx* rebalance_idx = NULL; node_idx* rebalance_idx = NULL;
delete_internal(omt, &omt->root, index, &v, &rebalance_idx); delete_internal(omt, &omt->root, index, &v, &rebalance_idx);
...@@ -420,7 +420,7 @@ static inline void fetch_internal(OMT V, node_idx idx, u_int32_t i, OMTVALUE *v) ...@@ -420,7 +420,7 @@ static inline void fetch_internal(OMT V, node_idx idx, u_int32_t i, OMTVALUE *v)
} }
int toku_omt_fetch(OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c) { int toku_omt_fetch(OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c) {
if (i>=nweight(V, V->root)) return ERANGE; if (i>=nweight(V, V->root)) return EINVAL;
fetch_internal(V, V->root, i, v); fetch_internal(V, V->root, i, v);
if (c) { if (c) {
associate(V,c); associate(V,c);
...@@ -562,7 +562,7 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi ...@@ -562,7 +562,7 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi
} else { } else {
r = find_internal_plus( V, V->root, h, extra, value, index); r = find_internal_plus( V, V->root, h, extra, value, index);
} }
if (c) { if (c && r==0) {
associate(V,c); associate(V,c);
c->index=*index; c->index=*index;
} }
...@@ -574,7 +574,7 @@ int toku_omt_split_at(OMT omt, OMT *newomtp, u_int32_t index) { ...@@ -574,7 +574,7 @@ int toku_omt_split_at(OMT omt, OMT *newomtp, u_int32_t index) {
OMT newomt = NULL; OMT newomt = NULL;
OMTVALUE *tmp_values = NULL; OMTVALUE *tmp_values = NULL;
invalidate_cursors(omt); invalidate_cursors(omt);
if (index>nweight(omt, omt->root)) { r = ERANGE; goto cleanup; } if (index>nweight(omt, omt->root)) { r = EINVAL; goto cleanup; }
u_int32_t newsize = nweight(omt, omt->root)-index; u_int32_t newsize = nweight(omt, omt->root)-index;
if ((r = omt_create_internal(&newomt, newsize))) goto cleanup; if ((r = omt_create_internal(&newomt, newsize))) goto cleanup;
MALLOC_N(nweight(omt, omt->root), tmp_values); MALLOC_N(nweight(omt, omt->root), tmp_values);
......
...@@ -227,7 +227,7 @@ int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index); ...@@ -227,7 +227,7 @@ int toku_omt_insert_at(OMT omt, OMTVALUE value, u_int32_t index);
// //
// Returns: // Returns:
// 0 success // 0 success
// ERANGE if index>toku_omt_size(omt) // EINVAL if index>toku_omt_size(omt)
// ENOMEM // ENOMEM
// On error, omt is unchanged. // On error, omt is unchanged.
// Performance: time=O(\log N) amortized time. // Performance: time=O(\log N) amortized time.
...@@ -237,7 +237,7 @@ int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index); ...@@ -237,7 +237,7 @@ int toku_omt_set_at (OMT omt, OMTVALUE value, u_int32_t index);
// Effect: Replaces the item at index with value. // Effect: Replaces the item at index with value.
// Returns: // Returns:
// 0 success // 0 success
// ERANGE if index>=toku_omt_size(omt) // EINVAL if index>=toku_omt_size(omt)
// On error, omt i sunchanged. // On error, omt i sunchanged.
// Performance: time=O(\log N) // Performance: time=O(\log N)
// Rationale: The BRT needs to be able to replace a value with another copy of the same value (allocated in a different location) // Rationale: The BRT needs to be able to replace a value with another copy of the same value (allocated in a different location)
...@@ -265,7 +265,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index); ...@@ -265,7 +265,7 @@ int toku_omt_delete_at(OMT omt, u_int32_t index);
// Decreases indexes of all items at slot >= index by 1. // Decreases indexes of all items at slot >= index by 1.
// Returns // Returns
// 0 success // 0 success
// ERANGE if index>=toku_omt_size(omt) // EINVAL if index>=toku_omt_size(omt)
// On error, omt is unchanged. // On error, omt is unchanged.
// Rationale: To delete an item, first find its index using toku_omt_find, then delete it. // Rationale: To delete an item, first find its index using toku_omt_find, then delete it.
// Performance: time=O(\log N) amortized. // Performance: time=O(\log N) amortized.
...@@ -277,7 +277,7 @@ int toku_omt_fetch (OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c); ...@@ -277,7 +277,7 @@ int toku_omt_fetch (OMT V, u_int32_t i, OMTVALUE *v, OMTCURSOR c);
// Requires: v != NULL // Requires: v != NULL
// Returns // Returns
// 0 success // 0 success
// ERANGE if index>=toku_omt_size(omt) // EINVAL if index>=toku_omt_size(omt)
// On nonzero return, *v is unchanged, and c (if nonnull) is either // On nonzero return, *v is unchanged, and c (if nonnull) is either
// invalidated or unchanged. // invalidated or unchanged.
// Performance: time=O(\log N) // Performance: time=O(\log N)
...@@ -304,7 +304,8 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi ...@@ -304,7 +304,8 @@ int toku_omt_find(OMT V, int (*h)(OMTVALUE, void*extra), void*extra, int directi
// Returns // Returns
// 0 success // 0 success
// DB_NOTFOUND no such value is found. // DB_NOTFOUND no such value is found.
// On nonzero return, *value and *index are unchanged. // On nonzero return, *value and *index are unchanged, and c (if nonnull) is either invalidated
// or unchanged.
// Performance: time=O(\log N) // Performance: time=O(\log N)
// Rationale: // Rationale:
// Here's how to use the find function to find various things // Here's how to use the find function to find various things
...@@ -360,7 +361,7 @@ int toku_omt_split_at(OMT omt, OMT *newomt, u_int32_t index); ...@@ -360,7 +361,7 @@ int toku_omt_split_at(OMT omt, OMT *newomt, u_int32_t index);
// Requires: newomt != NULL // Requires: newomt != NULL
// Returns // Returns
// 0 success, // 0 success,
// ERANGE if index > toku_omt_size(omt) // EINVAL if index > toku_omt_size(omt)
// ENOMEM // ENOMEM
// On nonzero return, omt and *newomt are unmodified. // On nonzero return, omt and *newomt are unmodified.
// Performance: time=O(n) // Performance: time=O(n)
......
...@@ -172,9 +172,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) { ...@@ -172,9 +172,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) {
test_create(KEEP_WHEN_DONE); test_create(KEEP_WHEN_DONE);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
for (i = 0; i < length/2; i++) { for (i = 0; i < length/2; i++) {
assert(size==toku_omt_size(omt)); assert(size==toku_omt_size(omt));
r = toku_omt_insert_at(omt, values[i], i); r = toku_omt_insert_at(omt, values[i], i);
...@@ -185,9 +185,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) { ...@@ -185,9 +185,9 @@ void test_create_insert_at_almost_random(enum close_when_done close) {
assert(++size==toku_omt_size(omt)); assert(++size==toku_omt_size(omt));
} }
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
assert(size==toku_omt_size(omt)); assert(size==toku_omt_size(omt));
test_close(close); test_close(close);
} }
...@@ -199,9 +199,9 @@ void test_create_insert_at_sequential(enum close_when_done close) { ...@@ -199,9 +199,9 @@ void test_create_insert_at_sequential(enum close_when_done close) {
test_create(KEEP_WHEN_DONE); test_create(KEEP_WHEN_DONE);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
assert(size==toku_omt_size(omt)); assert(size==toku_omt_size(omt));
r = toku_omt_insert_at(omt, values[i], i); r = toku_omt_insert_at(omt, values[i], i);
...@@ -209,9 +209,9 @@ void test_create_insert_at_sequential(enum close_when_done close) { ...@@ -209,9 +209,9 @@ void test_create_insert_at_sequential(enum close_when_done close) {
assert(++size==toku_omt_size(omt)); assert(++size==toku_omt_size(omt));
} }
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+1);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2); r = toku_omt_insert_at(omt, values[0], toku_omt_size(omt)+2);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
assert(size==toku_omt_size(omt)); assert(size==toku_omt_size(omt));
test_close(close); test_close(close);
} }
...@@ -324,11 +324,11 @@ void test_fetch_verify (OMT omtree, TESTVALUE* val, u_int32_t len ) { ...@@ -324,11 +324,11 @@ void test_fetch_verify (OMT omtree, TESTVALUE* val, u_int32_t len ) {
for (i = len; i < len*2; i++) { for (i = len; i < len*2; i++) {
v = oldv; v = oldv;
r = toku_omt_fetch(omtree, i, &v, NULL); r = toku_omt_fetch(omtree, i, &v, NULL);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
assert(v == oldv); assert(v == oldv);
v = NULL; v = NULL;
r = toku_omt_fetch(omtree, i, &v, c); r = toku_omt_fetch(omtree, i, &v, c);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
assert(v == NULL); assert(v == NULL);
} }
...@@ -421,9 +421,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo ...@@ -421,9 +421,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo
test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE); test_create_from_sorted_array(create_choice, KEEP_WHEN_DONE);
int r; int r;
r = toku_omt_set_at (omt, values[0], length); r = toku_omt_set_at (omt, values[0], length);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
r = toku_omt_set_at (omt, values[0], length+1); r = toku_omt_set_at (omt, values[0], length+1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
u_int32_t choice = perm[i]; u_int32_t choice = perm[i];
values[choice] = &nums[choice]; values[choice] = &nums[choice];
...@@ -434,9 +434,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo ...@@ -434,9 +434,9 @@ void test_create_set_at(enum create_type create_choice, enum close_when_done clo
test_fetch_verify(omt, values, length); test_fetch_verify(omt, values, length);
} }
r = toku_omt_set_at (omt, values[0], length); r = toku_omt_set_at (omt, values[0], length);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
r = toku_omt_set_at (omt, values[0], length+1); r = toku_omt_set_at (omt, values[0], length+1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
toku_free(perm); toku_free(perm);
toku_free(old_values); toku_free(old_values);
...@@ -515,10 +515,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done ...@@ -515,10 +515,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done
assert(length == toku_omt_size(omt)); assert(length == toku_omt_size(omt));
r = toku_omt_delete_at(omt, length); r = toku_omt_delete_at(omt, length);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
assert(length == toku_omt_size(omt)); assert(length == toku_omt_size(omt));
r = toku_omt_delete_at(omt, length+1); r = toku_omt_delete_at(omt, length+1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
while (length > 0) { while (length > 0) {
assert(length == toku_omt_size(omt)); assert(length == toku_omt_size(omt));
u_int32_t index_to_delete = random()%length; u_int32_t index_to_delete = random()%length;
...@@ -534,10 +534,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done ...@@ -534,10 +534,10 @@ void test_create_delete_at(enum create_type create_choice, enum close_when_done
assert(length == 0); assert(length == 0);
assert(length == toku_omt_size(omt)); assert(length == toku_omt_size(omt));
r = toku_omt_delete_at(omt, length); r = toku_omt_delete_at(omt, length);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
assert(length == toku_omt_size(omt)); assert(length == toku_omt_size(omt));
r = toku_omt_delete_at(omt, length+1); r = toku_omt_delete_at(omt, length+1);
CKERR2(r, ERANGE); CKERR2(r, EINVAL);
test_close(close); test_close(close);
} }
...@@ -550,9 +550,9 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close ...@@ -550,9 +550,9 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close
for (i = 0; i <= length; i++) { for (i = 0; i <= length; i++) {
r = toku_omt_split_at(omt, &right_split, length+1); r = toku_omt_split_at(omt, &right_split, length+1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
r = toku_omt_split_at(omt, &right_split, length+2); r = toku_omt_split_at(omt, &right_split, length+2);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
// //
// test successful split // test successful split
...@@ -571,19 +571,19 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close ...@@ -571,19 +571,19 @@ void test_split_merge(enum create_type create_choice, enum close_when_done close
// verify that new OMT's cannot do bad splits // verify that new OMT's cannot do bad splits
// //
r = toku_omt_split_at(left_split, &omt, i+1); r = toku_omt_split_at(left_split, &omt, i+1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
assert(toku_omt_size(left_split) == i); assert(toku_omt_size(left_split) == i);
assert(toku_omt_size(right_split) == length - i); assert(toku_omt_size(right_split) == length - i);
r = toku_omt_split_at(left_split, &omt, i+2); r = toku_omt_split_at(left_split, &omt, i+2);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
assert(toku_omt_size(left_split) == i); assert(toku_omt_size(left_split) == i);
assert(toku_omt_size(right_split) == length - i); assert(toku_omt_size(right_split) == length - i);
r = toku_omt_split_at(right_split, &omt, length - i + 1); r = toku_omt_split_at(right_split, &omt, length - i + 1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
assert(toku_omt_size(left_split) == i); assert(toku_omt_size(left_split) == i);
assert(toku_omt_size(right_split) == length - i); assert(toku_omt_size(right_split) == length - i);
r = toku_omt_split_at(right_split, &omt, length - i + 1); r = toku_omt_split_at(right_split, &omt, length - i + 1);
CKERR2(r,ERANGE); CKERR2(r,EINVAL);
assert(toku_omt_size(left_split) == i); assert(toku_omt_size(left_split) == i);
assert(toku_omt_size(right_split) == length - i); assert(toku_omt_size(right_split) == length - i);
...@@ -792,7 +792,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) { ...@@ -792,7 +792,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) {
heavy_extra(&extra, 0, 0); heavy_extra(&extra, 0, 0);
test_find_dir(-1, &extra, test_heaviside, DB_NOTFOUND, FALSE, 0, 0, FALSE); test_find_dir(-1, &extra, test_heaviside, DB_NOTFOUND, FALSE, 0, 0, FALSE);
test_find_dir(+1, &extra, test_heaviside, 0, TRUE, 0, 0, TRUE); test_find_dir(+1, &extra, test_heaviside, 0, TRUE, 0, 0, TRUE);
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, 0, 0, TRUE); test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, 0, 0, FALSE);
/* /*
0...0 0...0
...@@ -828,7 +828,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) { ...@@ -828,7 +828,7 @@ void test_find(enum create_type create_choice, enum close_when_done close) {
heavy_extra(&extra, length/2, length/2); heavy_extra(&extra, length/2, length/2);
test_find_dir(-1, &extra, test_heaviside, 0, TRUE, length/2-1, length/2-1, TRUE); test_find_dir(-1, &extra, test_heaviside, 0, TRUE, length/2-1, length/2-1, TRUE);
test_find_dir(+1, &extra, test_heaviside, 0, TRUE, length/2, length/2, TRUE); test_find_dir(+1, &extra, test_heaviside, 0, TRUE, length/2, length/2, TRUE);
test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, length/2, length/2, TRUE); test_find_dir(0, &extra, test_heaviside, DB_NOTFOUND, TRUE, length/2, length/2, FALSE);
/* /*
-...-0...0+...+ -...-0...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