@ -280,12 +280,10 @@ Status SstFileReader::SetOldTableOptions() {
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
Status SstFileReader : : ReadSequential ( bool print_kv ,
Status SstFileReader : : ReadSequential ( bool print_kv , uint64_t read_num ,
uint64_t read_num ,
bool has_from , const std : : string & from_key ,
bool has_from ,
bool has_to , const std : : string & to_key ,
const std : : string & from_key ,
bool use_from_as_prefix ) {
bool has_to ,
const std : : string & to_key ) {
if ( ! table_reader_ ) {
if ( ! table_reader_ ) {
return init_result_ ;
return init_result_ ;
}
}
@ -315,6 +313,11 @@ Status SstFileReader::ReadSequential(bool print_kv,
continue ;
continue ;
}
}
// the key returned is not prefixed with out 'from' key
if ( use_from_as_prefix & & ! ikey . user_key . starts_with ( from_key ) ) {
break ;
}
// If end marker was specified, we stop before it
// If end marker was specified, we stop before it
if ( has_to & & BytewiseComparator ( ) - > Compare ( ikey . user_key , to_key ) > = 0 ) {
if ( has_to & & BytewiseComparator ( ) - > Compare ( ikey . user_key , to_key ) > = 0 ) {
break ;
break ;
@ -366,6 +369,10 @@ void print_help() {
- - to = < user_key >
- - to = < user_key >
Key to stop reading at when executing check | scan
Key to stop reading at when executing check | scan
- - prefix = < user_key >
Returns all keys with this prefix when executing check | scan
Cannot be used in conjunction with - - from
- - read_num = < num >
- - read_num = < num >
Maximum number of entries to read when executing check | scan
Maximum number of entries to read when executing check | scan
@ -406,6 +413,7 @@ int SSTDumpTool::Run(int argc, char** argv) {
bool input_key_hex = false ;
bool input_key_hex = false ;
bool has_from = false ;
bool has_from = false ;
bool has_to = false ;
bool has_to = false ;
bool use_from_as_prefix = false ;
bool show_properties = false ;
bool show_properties = false ;
bool show_compression_sizes = false ;
bool show_compression_sizes = false ;
bool show_summary = false ;
bool show_summary = false ;
@ -440,6 +448,9 @@ int SSTDumpTool::Run(int argc, char** argv) {
} else if ( strncmp ( argv [ i ] , " --to= " , 5 ) = = 0 ) {
} else if ( strncmp ( argv [ i ] , " --to= " , 5 ) = = 0 ) {
to_key = argv [ i ] + 5 ;
to_key = argv [ i ] + 5 ;
has_to = true ;
has_to = true ;
} else if ( strncmp ( argv [ i ] , " --prefix= " , 9 ) = = 0 ) {
from_key = argv [ i ] + 9 ;
use_from_as_prefix = true ;
} else if ( strcmp ( argv [ i ] , " --show_properties " ) = = 0 ) {
} else if ( strcmp ( argv [ i ] , " --show_properties " ) = = 0 ) {
show_properties = true ;
show_properties = true ;
} else if ( strcmp ( argv [ i ] , " --show_compression_sizes " ) = = 0 ) {
} else if ( strcmp ( argv [ i ] , " --show_compression_sizes " ) = = 0 ) {
@ -476,13 +487,19 @@ int SSTDumpTool::Run(int argc, char** argv) {
fprintf ( stdout , " key=%s \n " , ikey . DebugString ( true ) . c_str ( ) ) ;
fprintf ( stdout , " key=%s \n " , ikey . DebugString ( true ) . c_str ( ) ) ;
return retc ;
return retc ;
} else {
} else {
fprintf ( stderr , " Unrecognized argument '%s' \n \n " , argv [ i ] ) ;
print_help ( ) ;
print_help ( ) ;
exit ( 1 ) ;
exit ( 1 ) ;
}
}
}
}
if ( use_from_as_prefix & & has_from ) {
fprintf ( stderr , " Cannot specify --prefix and --from \n \n " ) ;
exit ( 1 ) ;
}
if ( input_key_hex ) {
if ( input_key_hex ) {
if ( has_from ) {
if ( has_from | | use_from_as_prefix ) {
from_key = rocksdb : : LDBCommand : : HexToString ( from_key ) ;
from_key = rocksdb : : LDBCommand : : HexToString ( from_key ) ;
}
}
if ( has_to ) {
if ( has_to ) {
@ -491,6 +508,7 @@ int SSTDumpTool::Run(int argc, char** argv) {
}
}
if ( dir_or_file = = nullptr ) {
if ( dir_or_file = = nullptr ) {
fprintf ( stderr , " file or directory must be specified. \n \n " ) ;
print_help ( ) ;
print_help ( ) ;
exit ( 1 ) ;
exit ( 1 ) ;
}
}
@ -554,10 +572,10 @@ int SSTDumpTool::Run(int argc, char** argv) {
// scan all files in give file path.
// scan all files in give file path.
if ( command = = " " | | command = = " scan " | | command = = " check " ) {
if ( command = = " " | | command = = " scan " | | command = = " check " ) {
st = reader . ReadSequential ( command = = " scan " ,
st = reader . ReadSequential (
read_num > 0 ? ( read_num - total_read ) :
command = = " scan " , read_num > 0 ? ( read_num - total_read ) : read_num ,
read_num ,
has_from | | use_from_as_prefix , from_key , has_to , to_key ,
has_from , from_key , has_to , to_key ) ;
use_from_as_prefix ) ;
if ( ! st . ok ( ) ) {
if ( ! st . ok ( ) ) {
fprintf ( stderr , " %s: %s \n " , filename . c_str ( ) ,
fprintf ( stderr , " %s: %s \n " , filename . c_str ( ) ,
st . ToString ( ) . c_str ( ) ) ;
st . ToString ( ) . c_str ( ) ) ;