From ff151132b39b7f3db67ba786c47bb1841adb4a2a Mon Sep 17 00:00:00 2001 From: Kai Liu Date: Fri, 28 Feb 2014 20:37:32 -0800 Subject: [PATCH] Fix the unit test failure in devbox Summary: My last diff was developed in MacOS but in devserver environment error occurs. I dug into the problem and found the way we calcuate approximate data size is pretty out-of-date. We can use table properties to get more accurate results. Test Plan: ran ./table_test and passed Reviewers: igor, dhruba, haobo, sdong CC: leveldb Differential Revision: https://reviews.facebook.net/D16509 --- table/block_based_table_reader.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index dd8d739f7..4fb7c308a 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -1025,10 +1025,14 @@ uint64_t BlockBasedTable::ApproximateOffsetOf(const Slice& key) { result = rep_->metaindex_handle.offset(); } } else { - // key is past the last key in the file. Approximate the offset - // by returning the offset of the metaindex block (which is - // right near the end of the file). - result = rep_->metaindex_handle.offset(); + // key is past the last key in the file. If table_properties is not + // available, approximate the offset by returning the offset of the + // metaindex block (which is right near the end of the file). + result = rep_->table_properties->data_size; + // table_properties is not present in the table. + if (result == 0) { + result = rep_->metaindex_handle.offset(); + } } return result; }