@ -54,6 +54,7 @@ class SstFileReader {
Status ReadTableProperties ( uint64_t table_magic_number ,
RandomAccessFile * file , uint64_t file_size ) ;
Status SetTableOptionsByMagicNumber ( uint64_t table_magic_number ) ;
Status SetOldTableOptions ( ) ;
std : : string file_name_ ;
uint64_t read_num_ ;
@ -112,9 +113,11 @@ Status SstFileReader::NewTableReader(const std::string& file_path) {
options_ . env - > NewRandomAccessFile ( file_path , & file_ , soptions_ ) ;
}
options_ . comparator = & internal_comparator_ ;
s = ReadTableProperties ( magic_number , file_ . get ( ) , file_size ) ;
if ( s . ok ( ) ) {
s = SetTableOptionsByMagicNumber ( magic_number ) ;
// For old sst format, ReadTableProperties might fail but file can be read
if ( ReadTableProperties ( magic_number , file_ . get ( ) , file_size ) . ok ( ) ) {
SetTableOptionsByMagicNumber ( magic_number ) ;
} else {
SetOldTableOptions ( ) ;
}
}
@ -129,11 +132,15 @@ Status SstFileReader::NewTableReader(const std::string& file_path) {
Status SstFileReader : : ReadTableProperties ( uint64_t table_magic_number ,
RandomAccessFile * file ,
uint64_t file_size ) {
TableProperties * table_properties ;
TableProperties * table_properties = nullptr ;
Status s = rocksdb : : ReadTableProperties ( file , file_size , table_magic_number ,
options_ . env , options_ . info_log . get ( ) ,
& table_properties ) ;
table_properties_ . reset ( table_properties ) ;
if ( s . ok ( ) ) {
table_properties_ . reset ( table_properties ) ;
} else {
fprintf ( stdout , " Not able to read table properties \n " ) ;
}
return s ;
}
@ -180,6 +187,14 @@ Status SstFileReader::SetTableOptionsByMagicNumber(
return Status : : OK ( ) ;
}
Status SstFileReader : : SetOldTableOptions ( ) {
assert ( table_properties_ = = nullptr ) ;
options_ . table_factory = std : : make_shared < BlockBasedTableFactory > ( ) ;
fprintf ( stdout , " Sst file format: block-based(old version) \n " ) ;
return Status : : OK ( ) ;
}
Status SstFileReader : : ReadSequential ( bool print_kv ,
uint64_t read_num ,
bool has_from ,