@ -118,28 +118,28 @@ void FileMetaData::UpdateBoundaries(const Slice& key, const Slice& value,
}
}
void VersionEdit : : Clear ( ) {
void VersionEdit : : Clear ( ) {
max_level_ = 0 ;
db_id_ . clear ( ) ;
db_id_ . clear ( ) ;
comparator_ . clear ( ) ;
comparator_ . clear ( ) ;
max_level_ = 0 ;
log_number_ = 0 ;
log_number_ = 0 ;
prev_log_number_ = 0 ;
prev_log_number_ = 0 ;
last_sequence_ = 0 ;
next_file_number_ = 0 ;
next_file_number_ = 0 ;
max_column_family_ = 0 ;
max_column_family_ = 0 ;
min_log_number_to_keep_ = 0 ;
min_log_number_to_keep_ = 0 ;
last_sequence_ = 0 ;
has_db_id_ = false ;
has_db_id_ = false ;
has_comparator_ = false ;
has_comparator_ = false ;
has_log_number_ = false ;
has_log_number_ = false ;
has_prev_log_number_ = false ;
has_prev_log_number_ = false ;
has_next_file_number_ = false ;
has_next_file_number_ = false ;
has_last_sequence_ = false ;
has_max_column_family_ = false ;
has_max_column_family_ = false ;
has_min_log_number_to_keep_ = false ;
has_min_log_number_to_keep_ = false ;
has_last_sequence_ = false ;
deleted_files_ . clear ( ) ;
deleted_files_ . clear ( ) ;
new_files_ . clear ( ) ;
new_files_ . clear ( ) ;
column_family_ = 0 ;
column_family_ = 0 ;
is_column_family_add_ = 0 ;
is_column_family_add_ = false ;
is_column_family_drop_ = 0 ;
is_column_family_drop_ = false ;
column_family_name_ . clear ( ) ;
column_family_name_ . clear ( ) ;
is_in_atomic_group_ = false ;
is_in_atomic_group_ = false ;
remaining_entries_ = 0 ;
remaining_entries_ = 0 ;
@ -163,12 +163,12 @@ bool VersionEdit::EncodeTo(std::string* dst) const {
if ( has_next_file_number_ ) {
if ( has_next_file_number_ ) {
PutVarint32Varint64 ( dst , kNextFileNumber , next_file_number_ ) ;
PutVarint32Varint64 ( dst , kNextFileNumber , next_file_number_ ) ;
}
}
if ( has_last_sequence_ ) {
PutVarint32Varint64 ( dst , kLastSequence , last_sequence_ ) ;
}
if ( has_max_column_family_ ) {
if ( has_max_column_family_ ) {
PutVarint32Varint32 ( dst , kMaxColumnFamily , max_column_family_ ) ;
PutVarint32Varint32 ( dst , kMaxColumnFamily , max_column_family_ ) ;
}
}
if ( has_last_sequence_ ) {
PutVarint32Varint64 ( dst , kLastSequence , last_sequence_ ) ;
}
for ( const auto & deleted : deleted_files_ ) {
for ( const auto & deleted : deleted_files_ ) {
PutVarint32Varint32Varint64 ( dst , kDeletedFile , deleted . first /* level */ ,
PutVarint32Varint32Varint64 ( dst , kDeletedFile , deleted . first /* level */ ,
deleted . second /* file number */ ) ;
deleted . second /* file number */ ) ;
@ -287,7 +287,7 @@ static bool GetInternalKey(Slice* input, InternalKey* dst) {
}
}
bool VersionEdit : : GetLevel ( Slice * input , int * level , const char * * /*msg*/ ) {
bool VersionEdit : : GetLevel ( Slice * input , int * level , const char * * /*msg*/ ) {
uint32_t v ;
uint32_t v = 0 ;
if ( GetVarint32 ( input , & v ) ) {
if ( GetVarint32 ( input , & v ) ) {
* level = v ;
* level = v ;
if ( max_level_ < * level ) {
if ( max_level_ < * level ) {
@ -301,13 +301,13 @@ bool VersionEdit::GetLevel(Slice* input, int* level, const char** /*msg*/) {
const char * VersionEdit : : DecodeNewFile4From ( Slice * input ) {
const char * VersionEdit : : DecodeNewFile4From ( Slice * input ) {
const char * msg = nullptr ;
const char * msg = nullptr ;
int level ;
int level = 0 ;
FileMetaData f ;
FileMetaData f ;
uint64_t number ;
uint64_t number = 0 ;
uint32_t path_id = 0 ;
uint32_t path_id = 0 ;
uint64_t file_size ;
uint64_t file_size = 0 ;
SequenceNumber smallest_seqno ;
SequenceNumber smallest_seqno = 0 ;
SequenceNumber largest_seqno ;
SequenceNumber largest_seqno = kMaxSequenceNumber ;
// Since this is the only forward-compatible part of the code, we hack new
// Since this is the only forward-compatible part of the code, we hack new
// extension into this record. When we do, we set this boolean to distinguish
// extension into this record. When we do, we set this boolean to distinguish
// the record from the normal NewFile records.
// the record from the normal NewFile records.
@ -318,7 +318,7 @@ const char* VersionEdit::DecodeNewFile4From(Slice* input) {
GetVarint64 ( input , & largest_seqno ) ) {
GetVarint64 ( input , & largest_seqno ) ) {
// See comments in VersionEdit::EncodeTo() for format of customized fields
// See comments in VersionEdit::EncodeTo() for format of customized fields
while ( true ) {
while ( true ) {
uint32_t custom_tag ;
uint32_t custom_tag = 0 ;
Slice field ;
Slice field ;
if ( ! GetVarint32 ( input , & custom_tag ) ) {
if ( ! GetVarint32 ( input , & custom_tag ) ) {
return " new-file4 custom field " ;
return " new-file4 custom field " ;
@ -389,10 +389,10 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
Clear ( ) ;
Clear ( ) ;
Slice input = src ;
Slice input = src ;
const char * msg = nullptr ;
const char * msg = nullptr ;
uint32_t tag ;
uint32_t tag = 0 ;
// Temporary storage for parsing
// Temporary storage for parsing
int level ;
int level = 0 ;
FileMetaData f ;
FileMetaData f ;
Slice str ;
Slice str ;
InternalKey key ;
InternalKey key ;
@ -439,14 +439,6 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
}
}
break ;
break ;
case kLastSequence :
if ( GetVarint64 ( & input , & last_sequence_ ) ) {
has_last_sequence_ = true ;
} else {
msg = " last sequence number " ;
}
break ;
case kMaxColumnFamily :
case kMaxColumnFamily :
if ( GetVarint32 ( & input , & max_column_family_ ) ) {
if ( GetVarint32 ( & input , & max_column_family_ ) ) {
has_max_column_family_ = true ;
has_max_column_family_ = true ;
@ -463,6 +455,14 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
}
}
break ;
break ;
case kLastSequence :
if ( GetVarint64 ( & input , & last_sequence_ ) ) {
has_last_sequence_ = true ;
} else {
msg = " last sequence number " ;
}
break ;
case kCompactPointer :
case kCompactPointer :
if ( GetLevel ( & input , & level , & msg ) & &
if ( GetLevel ( & input , & level , & msg ) & &
GetInternalKey ( & input , & key ) ) {
GetInternalKey ( & input , & key ) ) {
@ -477,7 +477,7 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
break ;
break ;
case kDeletedFile : {
case kDeletedFile : {
uint64_t number ;
uint64_t number = 0 ;
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) ) {
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) ) {
deleted_files_ . insert ( std : : make_pair ( level , number ) ) ;
deleted_files_ . insert ( std : : make_pair ( level , number ) ) ;
} else {
} else {
@ -489,8 +489,8 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
}
}
case kNewFile : {
case kNewFile : {
uint64_t number ;
uint64_t number = 0 ;
uint64_t file_size ;
uint64_t file_size = 0 ;
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
GetVarint64 ( & input , & file_size ) & &
GetVarint64 ( & input , & file_size ) & &
GetInternalKey ( & input , & f . smallest ) & &
GetInternalKey ( & input , & f . smallest ) & &
@ -505,10 +505,10 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
break ;
break ;
}
}
case kNewFile2 : {
case kNewFile2 : {
uint64_t number ;
uint64_t number = 0 ;
uint64_t file_size ;
uint64_t file_size = 0 ;
SequenceNumber smallest_seqno ;
SequenceNumber smallest_seqno = 0 ;
SequenceNumber largest_seqno ;
SequenceNumber largest_seqno = kMaxSequenceNumber ;
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
GetVarint64 ( & input , & file_size ) & &
GetVarint64 ( & input , & file_size ) & &
GetInternalKey ( & input , & f . smallest ) & &
GetInternalKey ( & input , & f . smallest ) & &
@ -527,11 +527,11 @@ Status VersionEdit::DecodeFrom(const Slice& src) {
}
}
case kNewFile3 : {
case kNewFile3 : {
uint64_t number ;
uint64_t number = 0 ;
uint32_t path_id ;
uint32_t path_id = 0 ;
uint64_t file_size ;
uint64_t file_size = 0 ;
SequenceNumber smallest_seqno ;
SequenceNumber smallest_seqno = 0 ;
SequenceNumber largest_seqno ;
SequenceNumber largest_seqno = kMaxSequenceNumber ;
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
if ( GetLevel ( & input , & level , & msg ) & & GetVarint64 ( & input , & number ) & &
GetVarint32 ( & input , & path_id ) & & GetVarint64 ( & input , & file_size ) & &
GetVarint32 ( & input , & path_id ) & & GetVarint64 ( & input , & file_size ) & &
GetInternalKey ( & input , & f . smallest ) & &
GetInternalKey ( & input , & f . smallest ) & &
@ -640,6 +640,10 @@ std::string VersionEdit::DebugString(bool hex_key) const {
r . append ( " \n NextFileNumber: " ) ;
r . append ( " \n NextFileNumber: " ) ;
AppendNumberTo ( & r , next_file_number_ ) ;
AppendNumberTo ( & r , next_file_number_ ) ;
}
}
if ( has_max_column_family_ ) {
r . append ( " \n MaxColumnFamily: " ) ;
AppendNumberTo ( & r , max_column_family_ ) ;
}
if ( has_min_log_number_to_keep_ ) {
if ( has_min_log_number_to_keep_ ) {
r . append ( " \n MinLogNumberToKeep: " ) ;
r . append ( " \n MinLogNumberToKeep: " ) ;
AppendNumberTo ( & r , min_log_number_to_keep_ ) ;
AppendNumberTo ( & r , min_log_number_to_keep_ ) ;
@ -648,13 +652,11 @@ std::string VersionEdit::DebugString(bool hex_key) const {
r . append ( " \n LastSeq: " ) ;
r . append ( " \n LastSeq: " ) ;
AppendNumberTo ( & r , last_sequence_ ) ;
AppendNumberTo ( & r , last_sequence_ ) ;
}
}
for ( DeletedFileSet : : const_iterator iter = deleted_files_ . begin ( ) ;
for ( const auto & deleted_file : deleted_files_ ) {
iter ! = deleted_files_ . end ( ) ;
+ + iter ) {
r . append ( " \n DeleteFile: " ) ;
r . append ( " \n DeleteFile: " ) ;
AppendNumberTo ( & r , iter - > first ) ;
AppendNumberTo ( & r , deleted_file . first ) ;
r . append ( " " ) ;
r . append ( " " ) ;
AppendNumberTo ( & r , iter - > second ) ;
AppendNumberTo ( & r , deleted_file . second ) ;
}
}
for ( size_t i = 0 ; i < new_files_ . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < new_files_ . size ( ) ; i + + ) {
const FileMetaData & f = new_files_ [ i ] . second ;
const FileMetaData & f = new_files_ [ i ] . second ;
@ -686,10 +688,6 @@ std::string VersionEdit::DebugString(bool hex_key) const {
if ( is_column_family_drop_ ) {
if ( is_column_family_drop_ ) {
r . append ( " \n ColumnFamilyDrop " ) ;
r . append ( " \n ColumnFamilyDrop " ) ;
}
}
if ( has_max_column_family_ ) {
r . append ( " \n MaxColumnFamily: " ) ;
AppendNumberTo ( & r , max_column_family_ ) ;
}
if ( is_in_atomic_group_ ) {
if ( is_in_atomic_group_ ) {
r . append ( " \n AtomicGroup: " ) ;
r . append ( " \n AtomicGroup: " ) ;
AppendNumberTo ( & r , remaining_entries_ ) ;
AppendNumberTo ( & r , remaining_entries_ ) ;
@ -718,6 +716,12 @@ std::string VersionEdit::DebugJSON(int edit_num, bool hex_key) const {
if ( has_next_file_number_ ) {
if ( has_next_file_number_ ) {
jw < < " NextFileNumber " < < next_file_number_ ;
jw < < " NextFileNumber " < < next_file_number_ ;
}
}
if ( has_max_column_family_ ) {
jw < < " MaxColumnFamily " < < max_column_family_ ;
}
if ( has_min_log_number_to_keep_ ) {
jw < < " MinLogNumberToKeep " < < min_log_number_to_keep_ ;
}
if ( has_last_sequence_ ) {
if ( has_last_sequence_ ) {
jw < < " LastSeq " < < last_sequence_ ;
jw < < " LastSeq " < < last_sequence_ ;
}
}
@ -726,12 +730,10 @@ std::string VersionEdit::DebugJSON(int edit_num, bool hex_key) const {
jw < < " DeletedFiles " ;
jw < < " DeletedFiles " ;
jw . StartArray ( ) ;
jw . StartArray ( ) ;
for ( DeletedFileSet : : const_iterator iter = deleted_files_ . begin ( ) ;
for ( const auto & deleted_file : deleted_files_ ) {
iter ! = deleted_files_ . end ( ) ;
+ + iter ) {
jw . StartArrayedObject ( ) ;
jw . StartArrayedObject ( ) ;
jw < < " Level " < < iter - > first ;
jw < < " Level " < < deleted_file . first ;
jw < < " FileNumber " < < iter - > second ;
jw < < " FileNumber " < < deleted_file . second ;
jw . EndArrayedObject ( ) ;
jw . EndArrayedObject ( ) ;
}
}
@ -767,12 +769,6 @@ std::string VersionEdit::DebugJSON(int edit_num, bool hex_key) const {
if ( is_column_family_drop_ ) {
if ( is_column_family_drop_ ) {
jw < < " ColumnFamilyDrop " < < column_family_name_ ;
jw < < " ColumnFamilyDrop " < < column_family_name_ ;
}
}
if ( has_max_column_family_ ) {
jw < < " MaxColumnFamily " < < max_column_family_ ;
}
if ( has_min_log_number_to_keep_ ) {
jw < < " MinLogNumberToKeep " < < min_log_number_to_keep_ ;
}
if ( is_in_atomic_group_ ) {
if ( is_in_atomic_group_ ) {
jw < < " AtomicGroup " < < remaining_entries_ ;
jw < < " AtomicGroup " < < remaining_entries_ ;
}
}