@ -9,6 +9,7 @@
# include "table/block_based_table_reader.h"
# include <algorithm>
# include <array>
# include <limits>
# include <string>
# include <utility>
@ -663,51 +664,71 @@ bool IsFeatureSupported(const TableProperties& table_properties,
return true ;
}
SequenceNumber GetGlobalSequenceNumber ( const TableProperties & table_properties ,
Logger * info_log ) {
auto & props = table_properties . user_collected_properties ;
auto version_pos = props . find ( ExternalSstFilePropertyNames : : kVersion ) ;
auto seqno_pos = props . find ( ExternalSstFilePropertyNames : : kGlobalSeqno ) ;
// Caller has to ensure seqno is not nullptr.
Status GetGlobalSequenceNumber ( const TableProperties & table_properties ,
SequenceNumber largest_seqno ,
SequenceNumber * seqno ) {
const auto & props = table_properties . user_collected_properties ;
const auto version_pos = props . find ( ExternalSstFilePropertyNames : : kVersion ) ;
const auto seqno_pos = props . find ( ExternalSstFilePropertyNames : : kGlobalSeqno ) ;
* seqno = kDisableGlobalSequenceNumber ;
if ( version_pos = = props . end ( ) ) {
if ( seqno_pos ! = props . end ( ) ) {
std : : array < char , 200 > msg_buf ;
// This is not an external sst file, global_seqno is not supported.
assert ( false ) ;
ROCKS_LOG_ERROR (
info_log ,
snprintf (
msg_buf . data ( ) , msg_buf . max_size ( ) ,
" A non-external sst file have global seqno property with value %s " ,
seqno_pos - > second . c_str ( ) ) ;
return Status : : Corruption ( msg_buf . data ( ) ) ;
}
return kDisableGlobalSequenceNumber ;
return Status : : OK ( ) ;
}
uint32_t version = DecodeFixed32 ( version_pos - > second . c_str ( ) ) ;
if ( version < 2 ) {
if ( seqno_pos ! = props . end ( ) | | version ! = 1 ) {
std : : array < char , 200 > msg_buf ;
// This is a v1 external sst file, global_seqno is not supported.
assert ( false ) ;
ROCKS_LOG_ERROR (
info_log ,
" An external sst file with version %u have global seqno property "
" with value %s " ,
version , seqno_pos - > second . c_str ( ) ) ;
snprintf ( msg_buf . data ( ) , msg_buf . max_size ( ) ,
" An external sst file with version %u have global seqno "
" property with value %s " ,
version , seqno_pos - > second . c_str ( ) ) ;
return Status : : Corruption ( msg_buf . data ( ) ) ;
}
return kDisableGlobalSequenceNumber ;
return Status : : OK ( ) ;
}
SequenceNumber global_seqno = DecodeFixed64 ( seqno_pos - > second . c_str ( ) ) ;
// Since we have a plan to deprecate global_seqno, we do not return failure
// if seqno_pos == props.end(). We rely on version_pos to detect whether the
// SST is external.
SequenceNumber global_seqno ( 0 ) ;
if ( seqno_pos ! = props . end ( ) ) {
global_seqno = DecodeFixed64 ( seqno_pos - > second . c_str ( ) ) ;
}
if ( global_seqno ! = 0 & & global_seqno ! = largest_seqno ) {
std : : array < char , 200 > msg_buf ;
snprintf ( msg_buf . data ( ) , msg_buf . max_size ( ) ,
" An external sst file with version %u have global seqno property "
" with value %s, while largest seqno in the file is %llu " ,
version , seqno_pos - > second . c_str ( ) ,
static_cast < unsigned long long > ( largest_seqno ) ) ;
return Status : : Corruption ( msg_buf . data ( ) ) ;
}
global_seqno = largest_seqno ;
* seqno = largest_seqno ;
if ( global_seqno > kMaxSequenceNumber ) {
assert ( false ) ;
ROCKS_LOG_ERROR (
info_log ,
" An external sst file with version %u have global seqno property "
" with value %llu, which is greater than kMaxSequenceNumber " ,
version , global_seqno ) ;
std : : array < char , 200 > msg_buf ;
snprintf ( msg_buf . data ( ) , msg_buf . max_size ( ) ,
" An external sst file with version %u have global seqno property "
" with value %llu, which is greater than kMaxSequenceNumber " ,
version , static_cast < unsigned long long > ( global_seqno ) ) ;
return Status : : Corruption ( msg_buf . data ( ) ) ;
}
return global_seqno ;
return Status : : OK ( ) ;
}
} // namespace
@ -734,6 +755,7 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
const bool prefetch_index_and_filter_in_cache ,
const bool skip_filters , const int level ,
const bool immortal_table ,
const SequenceNumber largest_seqno ,
TailPrefetchStats * tail_prefetch_stats ) {
table_reader - > reset ( ) ;
@ -936,8 +958,12 @@ Status BlockBasedTable::Open(const ImmutableCFOptions& ioptions,
* ( rep - > table_properties ) ,
BlockBasedTablePropertyNames : : kPrefixFiltering , rep - > ioptions . info_log ) ;
rep - > global_seqno = GetGlobalSequenceNumber ( * ( rep - > table_properties ) ,
rep - > ioptions . info_log ) ;
s = GetGlobalSequenceNumber ( * ( rep - > table_properties ) , largest_seqno ,
& ( rep - > global_seqno ) ) ;
if ( ! s . ok ( ) ) {
ROCKS_LOG_ERROR ( rep - > ioptions . info_log , " %s " , s . ToString ( ) . c_str ( ) ) ;
return s ;
}
}
// Read the range del meta block