Commit 7961609a authored by Christian Rober's avatar Christian Rober Committed by Yoni Fogel

[t:4577] Backing out a bad commit.

git-svn-id: file:///svn/toku/tokudb@43765 c7de825b-a66e-492c-adef-691d508d4ae1
parent 1f55736f
...@@ -1168,11 +1168,10 @@ static void read_ftnode_header_from_fd_into_rbuf_if_small_enough (int fd, BLOCKN ...@@ -1168,11 +1168,10 @@ static void read_ftnode_header_from_fd_into_rbuf_if_small_enough (int fd, BLOCKN
// read the compressed partition into the sub_block, // read the compressed partition into the sub_block,
// validate the checksum of the compressed data // validate the checksum of the compressed data
// //
static int static enum deserialize_error_code
read_compressed_sub_block(struct rbuf *rb, struct sub_block *sb) read_compressed_sub_block(struct rbuf *rb, struct sub_block *sb)
{ {
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0;
sb->compressed_size = rbuf_int(rb); sb->compressed_size = rbuf_int(rb);
sb->uncompressed_size = rbuf_int(rb); sb->uncompressed_size = rbuf_int(rb);
bytevec* cp = (bytevec*)&sb->compressed_ptr; bytevec* cp = (bytevec*)&sb->compressed_ptr;
...@@ -1181,19 +1180,18 @@ read_compressed_sub_block(struct rbuf *rb, struct sub_block *sb) ...@@ -1181,19 +1180,18 @@ read_compressed_sub_block(struct rbuf *rb, struct sub_block *sb)
// let's check the checksum // let's check the checksum
u_int32_t actual_xsum = x1764_memory((char *)sb->compressed_ptr-8, 8+sb->compressed_size); u_int32_t actual_xsum = x1764_memory((char *)sb->compressed_ptr-8, 8+sb->compressed_size);
if (sb->xsum != actual_xsum) { if (sb->xsum != actual_xsum) {
r = TOKUDB_BAD_CHECKSUM; e = DS_XSUM_FAIL;
} }
return e;
return r;
} }
static int static enum deserialize_error_code
read_and_decompress_sub_block(struct rbuf *rb, struct sub_block *sb) read_and_decompress_sub_block(struct rbuf *rb, struct sub_block *sb)
{ {
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0;
r = read_compressed_sub_block(rb, sb); e = read_compressed_sub_block(rb, sb);
if (r == TOKUDB_BAD_CHECKSUM) { if (e != DS_OK) {
goto exit; goto exit;
} }
...@@ -1207,28 +1205,27 @@ read_and_decompress_sub_block(struct rbuf *rb, struct sub_block *sb) ...@@ -1207,28 +1205,27 @@ read_and_decompress_sub_block(struct rbuf *rb, struct sub_block *sb)
sb->compressed_size sb->compressed_size
); );
exit: exit:
return r; return e;
} }
// verify the checksum // verify the checksum
static int static enum deserialize_error_code
verify_ftnode_sub_block (struct sub_block *sb) verify_ftnode_sub_block (struct sub_block *sb)
{ {
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0;
// first verify the checksum // first verify the checksum
u_int32_t data_size = sb->uncompressed_size - 4; // checksum is 4 bytes at end u_int32_t data_size = sb->uncompressed_size - 4; // checksum is 4 bytes at end
u_int32_t stored_xsum = toku_dtoh32(*((u_int32_t *)((char *)sb->uncompressed_ptr + data_size))); u_int32_t stored_xsum = toku_dtoh32(*((u_int32_t *)((char *)sb->uncompressed_ptr + data_size)));
u_int32_t actual_xsum = x1764_memory(sb->uncompressed_ptr, data_size); u_int32_t actual_xsum = x1764_memory(sb->uncompressed_ptr, data_size);
if (stored_xsum != actual_xsum) { if (stored_xsum != actual_xsum) {
dump_bad_block(sb->uncompressed_ptr, sb->uncompressed_size); dump_bad_block(sb->uncompressed_ptr, sb->uncompressed_size);
r = TOKUDB_BAD_CHECKSUM; e = DS_XSUM_FAIL;
} }
return r; return e;
} }
// This function deserializes the data stored by serialize_ftnode_info // This function deserializes the data stored by serialize_ftnode_info
static int static enum deserialize_error_code
deserialize_ftnode_info( deserialize_ftnode_info(
struct sub_block *sb, struct sub_block *sb,
FTNODE node FTNODE node
...@@ -1238,10 +1235,9 @@ deserialize_ftnode_info( ...@@ -1238,10 +1235,9 @@ deserialize_ftnode_info(
// this function puts that information into node // this function puts that information into node
// first verify the checksum // first verify the checksum
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0; e = verify_ftnode_sub_block(sb);
r = verify_ftnode_sub_block(sb); if (e != DS_OK) {
if (r == TOKUDB_BAD_CHECKSUM) {
goto exit; goto exit;
} }
...@@ -1301,7 +1297,7 @@ deserialize_ftnode_info( ...@@ -1301,7 +1297,7 @@ deserialize_ftnode_info(
assert(FALSE); assert(FALSE);
} }
exit: exit:
return r; return e;
} }
static void static void
...@@ -1407,7 +1403,7 @@ static void setup_ftnode_partitions(FTNODE node, struct ftnode_fetch_extra* bfe, ...@@ -1407,7 +1403,7 @@ static void setup_ftnode_partitions(FTNODE node, struct ftnode_fetch_extra* bfe,
/* deserialize the partition from the sub-block's uncompressed buffer /* deserialize the partition from the sub-block's uncompressed buffer
* and destroy the uncompressed buffer * and destroy the uncompressed buffer
*/ */
static int static enum deserialize_error_code
deserialize_ftnode_partition( deserialize_ftnode_partition(
struct sub_block *sb, struct sub_block *sb,
FTNODE node, FTNODE node,
...@@ -1416,10 +1412,9 @@ deserialize_ftnode_partition( ...@@ -1416,10 +1412,9 @@ deserialize_ftnode_partition(
ft_compare_func cmp ft_compare_func cmp
) )
{ {
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0; e = verify_ftnode_sub_block(sb);
r = verify_ftnode_sub_block(sb); if (e != DS_OK) {
if (r == TOKUDB_BAD_CHECKSUM) {
goto exit; goto exit;
} }
u_int32_t data_size = sb->uncompressed_size - 4; // checksum is 4 bytes at end u_int32_t data_size = sb->uncompressed_size - 4; // checksum is 4 bytes at end
...@@ -1462,37 +1457,35 @@ deserialize_ftnode_partition( ...@@ -1462,37 +1457,35 @@ deserialize_ftnode_partition(
// destroy old omt (bn.buffer) that was created by toku_create_empty_bn(), so we can create a new one // destroy old omt (bn.buffer) that was created by toku_create_empty_bn(), so we can create a new one
toku_omt_destroy(&BLB_BUFFER(node, childnum)); toku_omt_destroy(&BLB_BUFFER(node, childnum));
r = toku_omt_create_steal_sorted_array(&BLB_BUFFER(node, childnum), &array, num_entries, num_entries); int r = toku_omt_create_steal_sorted_array(&BLB_BUFFER(node, childnum), &array, num_entries, num_entries);
invariant_zero(r); invariant_zero(r);
} }
assert(rb.ndone == rb.size); assert(rb.ndone == rb.size);
toku_free(sb->uncompressed_ptr); toku_free(sb->uncompressed_ptr);
exit: exit:
return r; return e;
} }
static int static enum deserialize_error_code
decompress_and_deserialize_worker(struct rbuf curr_rbuf, struct sub_block curr_sb, FTNODE node, int child, DESCRIPTOR desc, ft_compare_func cmp) decompress_and_deserialize_worker(struct rbuf curr_rbuf, struct sub_block curr_sb, FTNODE node, int child, DESCRIPTOR desc, ft_compare_func cmp)
{ {
//TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0; e = read_and_decompress_sub_block(&curr_rbuf, &curr_sb);
r = read_and_decompress_sub_block(&curr_rbuf, &curr_sb); if (e != DS_OK) {
if (r == TOKUDB_BAD_CHECKSUM) {
goto exit; goto exit;
} }
// at this point, sb->uncompressed_ptr stores the serialized node partition // at this point, sb->uncompressed_ptr stores the serialized node partition
r = deserialize_ftnode_partition(&curr_sb, node, child, desc, cmp); e = deserialize_ftnode_partition(&curr_sb, node, child, desc, cmp);
exit: exit:
return r; return e;
} }
static int static enum deserialize_error_code
check_and_copy_compressed_sub_block_worker(struct rbuf curr_rbuf, struct sub_block curr_sb, FTNODE node, int child) check_and_copy_compressed_sub_block_worker(struct rbuf curr_rbuf, struct sub_block curr_sb, FTNODE node, int child)
{ {
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
int r = 0; e = read_compressed_sub_block(&curr_rbuf, &curr_sb);
r = read_compressed_sub_block(&curr_rbuf, &curr_sb); if (e != DS_OK) {
if (r == TOKUDB_BAD_CHECKSUM) {
goto exit; goto exit;
} }
...@@ -1502,7 +1495,7 @@ check_and_copy_compressed_sub_block_worker(struct rbuf curr_rbuf, struct sub_blo ...@@ -1502,7 +1495,7 @@ check_and_copy_compressed_sub_block_worker(struct rbuf curr_rbuf, struct sub_blo
bp_sb->compressed_ptr = toku_xmalloc(bp_sb->compressed_size); bp_sb->compressed_ptr = toku_xmalloc(bp_sb->compressed_size);
memcpy(bp_sb->compressed_ptr, curr_sb.compressed_ptr, bp_sb->compressed_size); memcpy(bp_sb->compressed_ptr, curr_sb.compressed_ptr, bp_sb->compressed_size);
exit: exit:
return r; return e;
} }
static enum deserialize_error_code static enum deserialize_error_code
...@@ -2164,7 +2157,7 @@ deserialize_and_upgrade_ftnode(FTNODE node, ...@@ -2164,7 +2157,7 @@ deserialize_and_upgrade_ftnode(FTNODE node,
return r; return r;
} }
static int static enum deserialize_error_code
deserialize_ftnode_from_rbuf( deserialize_ftnode_from_rbuf(
FTNODE *ftnode, FTNODE *ftnode,
FTNODE_DISK_DATA* ndd, FTNODE_DISK_DATA* ndd,
...@@ -2178,7 +2171,7 @@ deserialize_ftnode_from_rbuf( ...@@ -2178,7 +2171,7 @@ deserialize_ftnode_from_rbuf(
// Effect: deserializes a ftnode that is in rb (with pointer of rb just past the magic) into a FTNODE. // Effect: deserializes a ftnode that is in rb (with pointer of rb just past the magic) into a FTNODE.
{ {
int r = 0; int r = 0;
// TODO: REMOVE: enum deserialize_error_code e = DS_OK; enum deserialize_error_code e = DS_OK;
FTNODE node = toku_xmalloc(sizeof(*node)); FTNODE node = toku_xmalloc(sizeof(*node));
struct sub_block sb_node_info; struct sub_block sb_node_info;
// fill in values that are known and not stored in rb // fill in values that are known and not stored in rb
...@@ -2249,14 +2242,14 @@ deserialize_ftnode_from_rbuf( ...@@ -2249,14 +2242,14 @@ deserialize_ftnode_from_rbuf(
//now we read and decompress the pivot and child information //now we read and decompress the pivot and child information
sub_block_init(&sb_node_info); sub_block_init(&sb_node_info);
r = read_and_decompress_sub_block(rb, &sb_node_info); e = read_and_decompress_sub_block(rb, &sb_node_info);
if (r == TOKUDB_BAD_CHECKSUM) { if (e != DS_OK) {
goto cleanup; goto cleanup;
} }
// at this point, sb->uncompressed_ptr stores the serialized node info // at this point, sb->uncompressed_ptr stores the serialized node info
r = deserialize_ftnode_info(&sb_node_info, node); e = deserialize_ftnode_info(&sb_node_info, node);
if (r == TOKUDB_BAD_CHECKSUM) { if (e != DS_OK) {
goto cleanup; goto cleanup;
} }
toku_free(sb_node_info.uncompressed_ptr); toku_free(sb_node_info.uncompressed_ptr);
...@@ -2306,15 +2299,15 @@ deserialize_ftnode_from_rbuf( ...@@ -2306,15 +2299,15 @@ deserialize_ftnode_from_rbuf(
switch (BP_STATE(node,i)) { switch (BP_STATE(node,i)) {
case PT_AVAIL: case PT_AVAIL:
// case where we read and decompress the partition // case where we read and decompress the partition
r = decompress_and_deserialize_worker(curr_rbuf, curr_sb, node, i, &bfe->h->cmp_descriptor, bfe->h->compare_fun); e = decompress_and_deserialize_worker(curr_rbuf, curr_sb, node, i, &bfe->h->cmp_descriptor, bfe->h->compare_fun);
if (r != 0) { if (e != DS_OK) {
goto cleanup; goto cleanup;
} }
continue; continue;
case PT_COMPRESSED: case PT_COMPRESSED:
// case where we leave the partition in the compressed state // case where we leave the partition in the compressed state
r = check_and_copy_compressed_sub_block_worker(curr_rbuf, curr_sb, node, i); e = check_and_copy_compressed_sub_block_worker(curr_rbuf, curr_sb, node, i);
if (r == TOKUDB_BAD_CHECKSUM) { if (e != DS_OK) {
goto cleanup; goto cleanup;
} }
continue; continue;
...@@ -2329,6 +2322,7 @@ deserialize_ftnode_from_rbuf( ...@@ -2329,6 +2322,7 @@ deserialize_ftnode_from_rbuf(
r = 0; r = 0;
cleanup: cleanup:
if (r != 0) { if (r != 0) {
e = DS_ERRNO;
// NOTE: Right now, callers higher in the stack will assert on // NOTE: Right now, callers higher in the stack will assert on
// failure, so this is OK for production. However, if we // failure, so this is OK for production. However, if we
// create tools that use this function to search for errors in // create tools that use this function to search for errors in
...@@ -2336,7 +2330,7 @@ deserialize_ftnode_from_rbuf( ...@@ -2336,7 +2330,7 @@ deserialize_ftnode_from_rbuf(
if (node) toku_free(node); if (node) toku_free(node);
} }
return r; return e;
} }
enum deserialize_error_code enum deserialize_error_code
......
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