@ -486,108 +486,108 @@ void WriteBatchWithIndex::Rep::AddNewEntry(uint32_t column_family_id) {
ReadKeyFromWriteBatchEntry ( & entry_ptr , & key , column_family_id ! = 0 ) ;
assert ( success ) ;
auto * mem = arena . Allocate ( sizeof ( WriteBatchIndexEntry ) ) ;
auto * index_entry =
new ( mem ) WriteBatchIndexEntry ( last_entry_offset , column_family_id ,
key . data ( ) - wb_data . data ( ) , key . size ( ) ) ;
skip_list . Insert ( index_entry ) ;
}
void WriteBatchWithIndex : : Rep : : Clear ( ) {
write_batch . Clear ( ) ;
ClearIndex ( ) ;
}
auto * mem = arena . Allocate ( sizeof ( WriteBatchIndexEntry ) ) ;
auto * index_entry =
new ( mem ) WriteBatchIndexEntry ( last_entry_offset , column_family_id ,
key . data ( ) - wb_data . data ( ) , key . size ( ) ) ;
skip_list . Insert ( index_entry ) ;
}
void WriteBatchWithIndex : : Rep : : ClearIndex ( ) {
skip_list . ~ WriteBatchEntrySkipList ( ) ;
arena . ~ Arena ( ) ;
new ( & arena ) Arena ( ) ;
new ( & skip_list ) WriteBatchEntrySkipList ( comparator , & arena ) ;
last_entry_offset = 0 ;
}
void WriteBatchWithIndex : : Rep : : Clear ( ) {
write_batch . Clear ( ) ;
ClearIndex ( ) ;
}
Status WriteBatchWithIndex : : Rep : : ReBuildIndex ( ) {
Status s ;
void WriteBatchWithIndex : : Rep : : ClearIndex ( ) {
skip_list . ~ WriteBatchEntrySkipList ( ) ;
arena . ~ Arena ( ) ;
new ( & arena ) Arena ( ) ;
new ( & skip_list ) WriteBatchEntrySkipList ( comparator , & arena ) ;
last_entry_offset = 0 ;
}
ClearIndex ( ) ;
Status WriteBatchWithIndex : : Rep : : ReBuildIndex ( ) {
Status s ;
if ( write_batch . Count ( ) = = 0 ) {
// Nothing to re-index
return s ;
}
ClearIndex ( ) ;
size_t offset = WriteBatchInternal : : GetFirstOffset ( & write_batch ) ;
if ( write_batch . Count ( ) = = 0 ) {
// Nothing to re-index
return s ;
}
Slice input ( write_batch . Data ( ) ) ;
input . remove_prefix ( offset ) ;
size_t offset = WriteBatchInternal : : GetFirstOffset ( & write_batch ) ;
// Loop through all entries in Rep and add each one to the index
int found = 0 ;
while ( s . ok ( ) & & ! input . empty ( ) ) {
Slice key , value , blob , xid ;
uint32_t column_family_id = 0 ; // default
char tag = 0 ;
Slice input ( write_batch . Data ( ) ) ;
input . remove_prefix ( offset ) ;
// set offset of current entry for call to AddNewEntry()
last_entry_offset = input . data ( ) - write_batch . Data ( ) . data ( ) ;
// Loop through all entries in Rep and add each one to the index
int found = 0 ;
while ( s . ok ( ) & & ! input . empty ( ) ) {
Slice key , value , blob , xid ;
uint32_t column_family_id = 0 ; // default
char tag = 0 ;
s = ReadRecordFromWriteBatch ( & input , & tag , & column_family_id , & key ,
& value , & blob , & xid ) ;
if ( ! s . ok ( ) ) {
break ;
}
// set offset of current entry for call to AddNewEntry()
last_entry_offset = input . data ( ) - write_batch . Data ( ) . data ( ) ;
switch ( tag ) {
case kTypeColumnFamilyValue :
case kTypeValue :
case kTypeColumnFamilyDeletion :
case kTypeDeletion :
case kTypeColumnFamilySingleDeletion :
case kTypeSingleDeletion :
case kTypeColumnFamilyMerge :
case kTypeMerge :
found + + ;
if ( ! UpdateExistingEntryWithCfId ( column_family_id , key ) ) {
AddNewEntry ( column_family_id ) ;
}
break ;
case kTypeLogData :
case kTypeBeginPrepareXID :
case kTypeBeginPersistedPrepareXID :
case kTypeEndPrepareXID :
case kTypeCommitXID :
case kTypeRollbackXID :
case kTypeNoop :
break ;
default :
return Status : : Corruption ( " unknown WriteBatch tag in ReBuildIndex " ,
ToString ( static_cast < unsigned int > ( tag ) ) ) ;
}
s = ReadRecordFromWriteBatch ( & input , & tag , & column_family_id , & key ,
& value , & blob , & xid ) ;
if ( ! s . ok ( ) ) {
break ;
}
if ( s . ok ( ) & & found ! = write_batch . Count ( ) ) {
s = Status : : Corruption ( " WriteBatch has wrong count " ) ;
switch ( tag ) {
case kTypeColumnFamilyValue :
case kTypeValue :
case kTypeColumnFamilyDeletion :
case kTypeDeletion :
case kTypeColumnFamilySingleDeletion :
case kTypeSingleDeletion :
case kTypeColumnFamilyMerge :
case kTypeMerge :
found + + ;
if ( ! UpdateExistingEntryWithCfId ( column_family_id , key ) ) {
AddNewEntry ( column_family_id ) ;
}
break ;
case kTypeLogData :
case kTypeBeginPrepareXID :
case kTypeBeginPersistedPrepareXID :
case kTypeEndPrepareXID :
case kTypeCommitXID :
case kTypeRollbackXID :
case kTypeNoop :
break ;
default :
return Status : : Corruption ( " unknown WriteBatch tag in ReBuildIndex " ,
ToString ( static_cast < unsigned int > ( tag ) ) ) ;
}
}
return s ;
if ( s . ok ( ) & & found ! = write_batch . Count ( ) ) {
s = Status : : Corruption ( " WriteBatch has wrong count " ) ;
}
WriteBatchWithIndex : : WriteBatchWithIndex (
const Comparator * default_index_comparator , size_t reserved_bytes ,
bool overwrite_key , size_t max_bytes )
: rep ( new Rep ( default_index_comparator , reserved_bytes , max_bytes ,
overwrite_key ) ) { }
return s ;
}
WriteBatchWithIndex : : WriteBatchWithIndex (
const Comparator * default_index_comparator , size_t reserved_bytes ,
bool overwrite_key , size_t max_bytes )
: rep ( new Rep ( default_index_comparator , reserved_bytes , max_bytes ,
overwrite_key ) ) { }
WriteBatchWithIndex : : ~ WriteBatchWithIndex ( ) { }
WriteBatchWithIndex : : ~ WriteBatchWithIndex ( ) { }
WriteBatch * WriteBatchWithIndex : : GetWriteBatch ( ) { return & rep - > write_batch ; }
WriteBatch * WriteBatchWithIndex : : GetWriteBatch ( ) { return & rep - > write_batch ; }
bool WriteBatchWithIndex : : HasDuplicateKeys ( ) {
return rep - > obsolete_offsets . size ( ) > 0 ;
}
bool WriteBatchWithIndex : : HasDuplicateKeys ( ) {
return rep - > obsolete_offsets . size ( ) > 0 ;
}
WBWIIterator * WriteBatchWithIndex : : NewIterator ( ) {
return new WBWIIteratorImpl ( 0 , & ( rep - > skip_list ) , & rep - > write_batch ) ;
WBWIIterator * WriteBatchWithIndex : : NewIterator ( ) {
return new WBWIIteratorImpl ( 0 , & ( rep - > skip_list ) , & rep - > write_batch ) ;
}
WBWIIterator * WriteBatchWithIndex : : NewIterator (