@ -3180,18 +3180,16 @@ Status BlockBasedTable::GetKVPairsFromDataBlocks(
}
}
Status BlockBasedTable : : DumpTable ( WritableFile * out_file ) {
Status BlockBasedTable : : DumpTable ( WritableFile * out_file ) {
auto out_file_wrapper = WritableFileStringStreamAdapter ( out_file ) ;
std : : ostream out_stream ( & out_file_wrapper ) ;
// Output Footer
// Output Footer
out_file - > Append (
out_stream < < " Footer Details: \n "
" Footer Details: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n "
out_stream < < " " < < rep_ - > footer . ToString ( ) < < " \n " ;
" " ) ;
out_file - > Append ( rep_ - > footer . ToString ( ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
// Output MetaIndex
// Output MetaIndex
out_file - > Append (
out_stream < < " Metaindex Details: \n "
" Metaindex Details: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n " ) ;
std : : unique_ptr < Block > metaindex ;
std : : unique_ptr < Block > metaindex ;
std : : unique_ptr < InternalIterator > metaindex_iter ;
std : : unique_ptr < InternalIterator > metaindex_iter ;
ReadOptions ro ;
ReadOptions ro ;
@ -3204,27 +3202,22 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
return s ;
return s ;
}
}
if ( metaindex_iter - > key ( ) = = ROCKSDB_NAMESPACE : : kPropertiesBlock ) {
if ( metaindex_iter - > key ( ) = = kPropertiesBlock ) {
out_file - > Append ( " Properties block handle: " ) ;
out_stream < < " Properties block handle: "
out_file - > Append ( metaindex_iter - > value ( ) . ToString ( true ) . c_str ( ) ) ;
< < metaindex_iter - > value ( ) . ToString ( true ) < < " \n " ;
out_file - > Append ( " \n " ) ;
} else if ( metaindex_iter - > key ( ) = = kCompressionDictBlock ) {
} else if ( metaindex_iter - > key ( ) = =
out_stream < < " Compression dictionary block handle: "
ROCKSDB_NAMESPACE : : kCompressionDictBlock ) {
< < metaindex_iter - > value ( ) . ToString ( true ) < < " \n " ;
out_file - > Append ( " Compression dictionary block handle: " ) ;
out_file - > Append ( metaindex_iter - > value ( ) . ToString ( true ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
} else if ( strstr ( metaindex_iter - > key ( ) . ToString ( ) . c_str ( ) ,
} else if ( strstr ( metaindex_iter - > key ( ) . ToString ( ) . c_str ( ) ,
" filter.rocksdb. " ) ! = nullptr ) {
" filter.rocksdb. " ) ! = nullptr ) {
out_file - > Append ( " Filter block handle: " ) ;
out_stream < < " Filter block handle: "
out_file - > Append ( metaindex_iter - > value ( ) . ToString ( true ) . c_str ( ) ) ;
< < metaindex_iter - > value ( ) . ToString ( true ) < < " \n " ;
out_file - > Append ( " \n " ) ;
} else if ( metaindex_iter - > key ( ) = = kRangeDelBlock ) {
} else if ( metaindex_iter - > key ( ) = = ROCKSDB_NAMESPACE : : kRangeDelBlock ) {
out_stream < < " Range deletion block handle: "
out_file - > Append ( " Range deletion block handle: " ) ;
< < metaindex_iter - > value ( ) . ToString ( true ) < < " \n " ;
out_file - > Append ( metaindex_iter - > value ( ) . ToString ( true ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
}
}
}
}
out_file - > Append ( " \n " ) ;
out_stream < < " \n " ;
} else {
} else {
return s ;
return s ;
}
}
@ -3234,25 +3227,19 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
table_properties = rep_ - > table_properties . get ( ) ;
table_properties = rep_ - > table_properties . get ( ) ;
if ( table_properties ! = nullptr ) {
if ( table_properties ! = nullptr ) {
out_file - > Append (
out_stream < < " Table Properties: \n "
" Table Properties: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n "
out_stream < < " " < < table_properties - > ToString ( " \n " , " : " ) < < " \n " ;
" " ) ;
out_file - > Append ( table_properties - > ToString ( " \n " , " : " ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
}
}
if ( rep_ - > filter ) {
if ( rep_ - > filter ) {
out_file - > Append (
out_stream < < " Filter Details: \n "
" Filter Details: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n "
out_stream < < " " < < rep_ - > filter - > ToString ( ) < < " \n " ;
" " ) ;
out_file - > Append ( rep_ - > filter - > ToString ( ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
}
}
// Output Index block
// Output Index block
s = DumpIndexBlock ( out_file ) ;
s = DumpIndexBlock ( out_stream ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
return s ;
return s ;
}
}
@ -3271,15 +3258,10 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
assert ( uncompression_dict . GetValue ( ) ) ;
assert ( uncompression_dict . GetValue ( ) ) ;
const Slice & raw_dict = uncompression_dict . GetValue ( ) - > GetRawDict ( ) ;
const Slice & raw_dict = uncompression_dict . GetValue ( ) - > GetRawDict ( ) ;
out_file - > Append (
out_stream < < " Compression Dictionary: \n "
" Compression Dictionary: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n " ) ;
out_stream < < " size (bytes): " < < raw_dict . size ( ) < < " \n \n " ;
out_file - > Append ( " size (bytes): " ) ;
out_stream < < " HEX " < < raw_dict . ToString ( true ) < < " \n \n " ;
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( raw_dict . size ( ) ) ) ;
out_file - > Append ( " \n \n " ) ;
out_file - > Append ( " HEX " ) ;
out_file - > Append ( raw_dict . ToString ( true ) . c_str ( ) ) ;
out_file - > Append ( " \n \n " ) ;
}
}
// Output range deletions block
// Output range deletions block
@ -3287,39 +3269,44 @@ Status BlockBasedTable::DumpTable(WritableFile* out_file) {
if ( range_del_iter ! = nullptr ) {
if ( range_del_iter ! = nullptr ) {
range_del_iter - > SeekToFirst ( ) ;
range_del_iter - > SeekToFirst ( ) ;
if ( range_del_iter - > Valid ( ) ) {
if ( range_del_iter - > Valid ( ) ) {
out_file - > Append (
out_stream < < " Range deletions: \n "
" Range deletions: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n "
" " ) ;
for ( ; range_del_iter - > Valid ( ) ; range_del_iter - > Next ( ) ) {
for ( ; range_del_iter - > Valid ( ) ; range_del_iter - > Next ( ) ) {
DumpKeyValue ( range_del_iter - > key ( ) , range_del_iter - > value ( ) , out_file ) ;
DumpKeyValue ( range_del_iter - > key ( ) , range_del_iter - > value ( ) ,
out_stream ) ;
}
}
out_file - > Append ( " \n " ) ;
out_stream < < " \n " ;
}
}
delete range_del_iter ;
delete range_del_iter ;
}
}
// Output Data blocks
// Output Data blocks
s = DumpDataBlocks ( out_file ) ;
s = DumpDataBlocks ( out_stream ) ;
return s ;
if ( ! s . ok ( ) ) {
return s ;
}
if ( ! out_stream . good ( ) ) {
return Status : : IOError ( " Failed to write to output file " ) ;
}
return Status : : OK ( ) ;
}
}
Status BlockBasedTable : : DumpIndexBlock ( WritableFile * out_file ) {
Status BlockBasedTable : : DumpIndexBlock ( std : : ostream & out_stream ) {
out_file - > Append (
out_stream < < " Index Details: \n "
" Index Details: \n "
" -------------------------------------- \n " ;
" -------------------------------------- \n " ) ;
std : : unique_ptr < InternalIteratorBase < IndexValue > > blockhandles_iter (
std : : unique_ptr < InternalIteratorBase < IndexValue > > blockhandles_iter (
NewIndexIterator ( ReadOptions ( ) , /*need_upper_bound_check=*/ false ,
NewIndexIterator ( ReadOptions ( ) , /*need_upper_bound_check=*/ false ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_contex=*/ nullptr ) ) ;
/*lookup_contex=*/ nullptr ) ) ;
Status s = blockhandles_iter - > status ( ) ;
Status s = blockhandles_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
out_file - > Append ( " Can not read Index Block \n \n " ) ;
out_stream < < " Can not read Index Block \n \n " ;
return s ;
return s ;
}
}
out_file - > Append ( " Block key hex dump: Data block handle \n " ) ;
out_stream < < " Block key hex dump: Data block handle \n " ;
out_file - > Append ( " Block key ascii \n \n " ) ;
out_stream < < " Block key ascii \n \n " ;
for ( blockhandles_iter - > SeekToFirst ( ) ; blockhandles_iter - > Valid ( ) ;
for ( blockhandles_iter - > SeekToFirst ( ) ; blockhandles_iter - > Valid ( ) ;
blockhandles_iter - > Next ( ) ) {
blockhandles_iter - > Next ( ) ) {
s = blockhandles_iter - > status ( ) ;
s = blockhandles_iter - > status ( ) ;
@ -3336,13 +3323,10 @@ Status BlockBasedTable::DumpIndexBlock(WritableFile* out_file) {
user_key = ikey . user_key ( ) ;
user_key = ikey . user_key ( ) ;
}
}
out_file - > Append ( " HEX " ) ;
out_stream < < " HEX " < < user_key . ToString ( true ) < < " : "
out_file - > Append ( user_key . ToString ( true ) . c_str ( ) ) ;
< < blockhandles_iter - > value ( ) . ToString ( true ,
out_file - > Append ( " : " ) ;
rep_ - > index_has_first_key )
out_file - > Append ( blockhandles_iter - > value ( )
< < " \n " ;
. ToString ( true , rep_ - > index_has_first_key )
. c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
std : : string str_key = user_key . ToString ( ) ;
std : : string str_key = user_key . ToString ( ) ;
std : : string res_key ( " " ) ;
std : : string res_key ( " " ) ;
@ -3351,22 +3335,21 @@ Status BlockBasedTable::DumpIndexBlock(WritableFile* out_file) {
res_key . append ( & str_key [ i ] , 1 ) ;
res_key . append ( & str_key [ i ] , 1 ) ;
res_key . append ( 1 , cspace ) ;
res_key . append ( 1 , cspace ) ;
}
}
out_file - > Append ( " ASCII " ) ;
out_stream < < " ASCII " < < res_key < < " \n " ;
out_file - > Append ( res_key . c_str ( ) ) ;
out_stream < < " ------ \n " ;
out_file - > Append ( " \n ------ \n " ) ;
}
}
out_file - > Append ( " \n " ) ;
out_stream < < " \n " ;
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
Status BlockBasedTable : : DumpDataBlocks ( WritableFile * out_file ) {
Status BlockBasedTable : : DumpDataBlocks ( std : : ostream & out_stream ) {
std : : unique_ptr < InternalIteratorBase < IndexValue > > blockhandles_iter (
std : : unique_ptr < InternalIteratorBase < IndexValue > > blockhandles_iter (
NewIndexIterator ( ReadOptions ( ) , /*need_upper_bound_check=*/ false ,
NewIndexIterator ( ReadOptions ( ) , /*need_upper_bound_check=*/ false ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr ,
/*input_iter=*/ nullptr , /*get_context=*/ nullptr ,
/*lookup_contex=*/ nullptr ) ) ;
/*lookup_contex=*/ nullptr ) ) ;
Status s = blockhandles_iter - > status ( ) ;
Status s = blockhandles_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
out_file - > Append ( " Can not read Index Block \n \n " ) ;
out_stream < < " Can not read Index Block \n \n " ;
return s ;
return s ;
}
}
@ -3388,12 +3371,9 @@ Status BlockBasedTable::DumpDataBlocks(WritableFile* out_file) {
datablock_size_max = std : : max ( datablock_size_max , datablock_size ) ;
datablock_size_max = std : : max ( datablock_size_max , datablock_size ) ;
datablock_size_sum + = datablock_size ;
datablock_size_sum + = datablock_size ;
out_file - > Append ( " Data Block # " ) ;
out_stream < < " Data Block # " < < block_id < < " @ "
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( block_id ) ) ;
< < blockhandles_iter - > value ( ) . handle . ToString ( true ) < < " \n " ;
out_file - > Append ( " @ " ) ;
out_stream < < " -------------------------------------- \n " ;
out_file - > Append ( blockhandles_iter - > value ( ) . handle . ToString ( true ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
out_file - > Append ( " -------------------------------------- \n " ) ;
std : : unique_ptr < InternalIterator > datablock_iter ;
std : : unique_ptr < InternalIterator > datablock_iter ;
datablock_iter . reset ( NewDataBlockIterator < DataBlockIter > (
datablock_iter . reset ( NewDataBlockIterator < DataBlockIter > (
@ -3404,7 +3384,7 @@ Status BlockBasedTable::DumpDataBlocks(WritableFile* out_file) {
s = datablock_iter - > status ( ) ;
s = datablock_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
out_file - > Append ( " Error reading the block - Skipped \n \n " ) ;
out_stream < < " Error reading the block - Skipped \n \n " ;
continue ;
continue ;
}
}
@ -3412,44 +3392,37 @@ Status BlockBasedTable::DumpDataBlocks(WritableFile* out_file) {
datablock_iter - > Next ( ) ) {
datablock_iter - > Next ( ) ) {
s = datablock_iter - > status ( ) ;
s = datablock_iter - > status ( ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
out_file - > Append ( " Error reading the block - Skipped \n " ) ;
out_stream < < " Error reading the block - Skipped \n " ;
break ;
break ;
}
}
DumpKeyValue ( datablock_iter - > key ( ) , datablock_iter - > value ( ) , out_file ) ;
DumpKeyValue ( datablock_iter - > key ( ) , datablock_iter - > value ( ) , out_stream ) ;
}
}
out_file - > Append ( " \n " ) ;
out_stream < < " \n " ;
}
}
uint64_t num_datablocks = block_id - 1 ;
uint64_t num_datablocks = block_id - 1 ;
if ( num_datablocks ) {
if ( num_datablocks ) {
double datablock_size_avg =
double datablock_size_avg =
static_cast < double > ( datablock_size_sum ) / num_datablocks ;
static_cast < double > ( datablock_size_sum ) / num_datablocks ;
out_file - > Append ( " Data Block Summary: \n " ) ;
out_stream < < " Data Block Summary: \n " ;
out_file - > Append ( " -------------------------------------- " ) ;
out_stream < < " -------------------------------------- \n " ;
out_file - > Append ( " \n # data blocks: " ) ;
out_stream < < " # data blocks: " < < num_datablocks < < " \n " ;
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( num_datablocks ) ) ;
out_stream < < " min data block size: " < < datablock_size_min < < " \n " ;
out_file - > Append ( " \n min data block size: " ) ;
out_stream < < " max data block size: " < < datablock_size_max < < " \n " ;
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( datablock_size_min ) ) ;
out_stream < < " avg data block size: " < < ToString ( datablock_size_avg )
out_file - > Append ( " \n max data block size: " ) ;
< < " \n " ;
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( datablock_size_max ) ) ;
out_file - > Append ( " \n avg data block size: " ) ;
out_file - > Append ( ROCKSDB_NAMESPACE : : ToString ( datablock_size_avg ) ) ;
out_file - > Append ( " \n " ) ;
}
}
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
void BlockBasedTable : : DumpKeyValue ( const Slice & key , const Slice & value ,
void BlockBasedTable : : DumpKeyValue ( const Slice & key , const Slice & value ,
WritableFile * out_file ) {
std : : ostream & out_stream ) {
InternalKey ikey ;
InternalKey ikey ;
ikey . DecodeFrom ( key ) ;
ikey . DecodeFrom ( key ) ;
out_file - > Append ( " HEX " ) ;
out_stream < < " HEX " < < ikey . user_key ( ) . ToString ( true ) < < " : "
out_file - > Append ( ikey . user_key ( ) . ToString ( true ) . c_str ( ) ) ;
< < value . ToString ( true ) < < " \n " ;
out_file - > Append ( " : " ) ;
out_file - > Append ( value . ToString ( true ) . c_str ( ) ) ;
out_file - > Append ( " \n " ) ;
std : : string str_key = ikey . user_key ( ) . ToString ( ) ;
std : : string str_key = ikey . user_key ( ) . ToString ( ) ;
std : : string str_value = value . ToString ( ) ;
std : : string str_value = value . ToString ( ) ;
@ -3472,11 +3445,8 @@ void BlockBasedTable::DumpKeyValue(const Slice& key, const Slice& value,
res_value . append ( 1 , cspace ) ;
res_value . append ( 1 , cspace ) ;
}
}
out_file - > Append ( " ASCII " ) ;
out_stream < < " ASCII " < < res_key < < " : " < < res_value < < " \n " ;
out_file - > Append ( res_key . c_str ( ) ) ;
out_stream < < " ------ \n " ;
out_file - > Append ( " : " ) ;
out_file - > Append ( res_value . c_str ( ) ) ;
out_file - > Append ( " \n ------ \n " ) ;
}
}
} // namespace ROCKSDB_NAMESPACE
} // namespace ROCKSDB_NAMESPACE