@ -69,6 +69,7 @@ void EvictAllVersionsCompactionListener::InternalListener::OnCompaction(
int level , const Slice & key ,
int level , const Slice & key ,
CompactionEventListener : : CompactionListenerValueType value_type ,
CompactionEventListener : : CompactionListenerValueType value_type ,
const Slice & existing_value , const SequenceNumber & sn , bool is_new ) {
const Slice & existing_value , const SequenceNumber & sn , bool is_new ) {
assert ( impl_ - > bdb_options_ . enable_garbage_collection ) ;
if ( ! is_new & &
if ( ! is_new & &
value_type = =
value_type = =
CompactionEventListener : : CompactionListenerValueType : : kValue ) {
CompactionEventListener : : CompactionListenerValueType : : kValue ) {
@ -213,12 +214,14 @@ void BlobDBImpl::StartBackgroundTasks() {
std : : bind ( & BlobDBImpl : : ReclaimOpenFiles , this , std : : placeholders : : _1 ) ) ;
std : : bind ( & BlobDBImpl : : ReclaimOpenFiles , this , std : : placeholders : : _1 ) ) ;
tqueue_ . add ( kGCCheckPeriodMillisecs ,
tqueue_ . add ( kGCCheckPeriodMillisecs ,
std : : bind ( & BlobDBImpl : : RunGC , this , std : : placeholders : : _1 ) ) ;
std : : bind ( & BlobDBImpl : : RunGC , this , std : : placeholders : : _1 ) ) ;
tqueue_ . add (
if ( bdb_options_ . enable_garbage_collection ) {
kDeleteCheckPeriodMillisecs ,
tqueue_ . add (
std : : bind ( & BlobDBImpl : : EvictDeletions , this , std : : placeholders : : _1 ) ) ;
kDeleteCheckPeriodMillisecs ,
tqueue_ . add (
std : : bind ( & BlobDBImpl : : EvictDeletions , this , std : : placeholders : : _1 ) ) ;
kDeleteCheckPeriodMillisecs ,
tqueue_ . add (
std : : bind ( & BlobDBImpl : : EvictCompacted , this , std : : placeholders : : _1 ) ) ;
kDeleteCheckPeriodMillisecs ,
std : : bind ( & BlobDBImpl : : EvictCompacted , this , std : : placeholders : : _1 ) ) ;
}
tqueue_ . add (
tqueue_ . add (
kDeleteObsoleteFilesPeriodMillisecs ,
kDeleteObsoleteFilesPeriodMillisecs ,
std : : bind ( & BlobDBImpl : : DeleteObsoleteFiles , this , std : : placeholders : : _1 ) ) ;
std : : bind ( & BlobDBImpl : : DeleteObsoleteFiles , this , std : : placeholders : : _1 ) ) ;
@ -659,8 +662,10 @@ Status BlobDBImpl::Delete(const WriteOptions& options, const Slice& key) {
SequenceNumber lsn = db_impl_ - > GetLatestSequenceNumber ( ) ;
SequenceNumber lsn = db_impl_ - > GetLatestSequenceNumber ( ) ;
Status s = db_ - > Delete ( options , key ) ;
Status s = db_ - > Delete ( options , key ) ;
// add deleted key to list of keys that have been deleted for book-keeping
if ( bdb_options_ . enable_garbage_collection ) {
delete_keys_q_ . enqueue ( { DefaultColumnFamily ( ) , key . ToString ( ) , lsn } ) ;
// add deleted key to list of keys that have been deleted for book-keeping
delete_keys_q_ . enqueue ( { DefaultColumnFamily ( ) , key . ToString ( ) , lsn } ) ;
}
return s ;
return s ;
}
}
@ -780,11 +785,13 @@ Status BlobDBImpl::Write(const WriteOptions& options, WriteBatch* updates) {
SequenceNumber sequence_ ;
SequenceNumber sequence_ ;
} ;
} ;
// add deleted key to list of keys that have been deleted for book-keeping
if ( bdb_options_ . enable_garbage_collection ) {
DeleteBookkeeper delete_bookkeeper ( this , current_seq ) ;
// add deleted key to list of keys that have been deleted for book-keeping
updates - > Iterate ( & delete_bookkeeper ) ;
DeleteBookkeeper delete_bookkeeper ( this , current_seq ) ;
s = updates - > Iterate ( & delete_bookkeeper ) ;
}
return Status : : OK ( ) ;
return s ;
}
}
Status BlobDBImpl : : GetLiveFiles ( std : : vector < std : : string > & ret ,
Status BlobDBImpl : : GetLiveFiles ( std : : vector < std : : string > & ret ,
@ -1318,6 +1325,7 @@ bool BlobDBImpl::FileDeleteOk_SnapshotCheckLocked(
bool BlobDBImpl : : FindFileAndEvictABlob ( uint64_t file_number , uint64_t key_size ,
bool BlobDBImpl : : FindFileAndEvictABlob ( uint64_t file_number , uint64_t key_size ,
uint64_t blob_offset ,
uint64_t blob_offset ,
uint64_t blob_size ) {
uint64_t blob_size ) {
assert ( bdb_options_ . enable_garbage_collection ) ;
( void ) blob_offset ;
( void ) blob_offset ;
std : : shared_ptr < BlobFile > bfile ;
std : : shared_ptr < BlobFile > bfile ;
{
{
@ -1340,6 +1348,7 @@ bool BlobDBImpl::FindFileAndEvictABlob(uint64_t file_number, uint64_t key_size,
}
}
bool BlobDBImpl : : MarkBlobDeleted ( const Slice & key , const Slice & index_entry ) {
bool BlobDBImpl : : MarkBlobDeleted ( const Slice & key , const Slice & index_entry ) {
assert ( bdb_options_ . enable_garbage_collection ) ;
BlobIndex blob_index ;
BlobIndex blob_index ;
Status s = blob_index . DecodeFrom ( index_entry ) ;
Status s = blob_index . DecodeFrom ( index_entry ) ;
if ( ! s . ok ( ) ) {
if ( ! s . ok ( ) ) {
@ -1354,6 +1363,7 @@ bool BlobDBImpl::MarkBlobDeleted(const Slice& key, const Slice& index_entry) {
}
}
std : : pair < bool , int64_t > BlobDBImpl : : EvictCompacted ( bool aborted ) {
std : : pair < bool , int64_t > BlobDBImpl : : EvictCompacted ( bool aborted ) {
assert ( bdb_options_ . enable_garbage_collection ) ;
if ( aborted ) return std : : make_pair ( false , - 1 ) ;
if ( aborted ) return std : : make_pair ( false , - 1 ) ;
override_packet_t packet ;
override_packet_t packet ;
@ -1377,6 +1387,7 @@ std::pair<bool, int64_t> BlobDBImpl::EvictCompacted(bool aborted) {
}
}
std : : pair < bool , int64_t > BlobDBImpl : : EvictDeletions ( bool aborted ) {
std : : pair < bool , int64_t > BlobDBImpl : : EvictDeletions ( bool aborted ) {
assert ( bdb_options_ . enable_garbage_collection ) ;
if ( aborted ) return std : : make_pair ( false , - 1 ) ;
if ( aborted ) return std : : make_pair ( false , - 1 ) ;
ColumnFamilyHandle * last_cfh = nullptr ;
ColumnFamilyHandle * last_cfh = nullptr ;
@ -1882,10 +1893,12 @@ bool BlobDBImpl::ShouldGCFile(std::shared_ptr<BlobFile> bfile, uint64_t now,
ReadLock lockbfile_r ( & bfile - > mutex_ ) ;
ReadLock lockbfile_r ( & bfile - > mutex_ ) ;
if ( ( bfile - > deleted_size_ * 100.0 / bfile - > file_size_ . load ( ) ) >
if ( bdb_options_ . enable_garbage_collection ) {
kPartialExpirationPercentage ) {
if ( ( bfile - > deleted_size_ * 100.0 / bfile - > file_size_ . load ( ) ) >
* reason = " deleted simple blobs beyond threshold " ;
kPartialExpirationPercentage ) {
return true ;
* reason = " deleted simple blobs beyond threshold " ;
return true ;
}
}
}
// if we haven't reached limits of disk space, don't DELETE
// if we haven't reached limits of disk space, don't DELETE