@ -503,7 +503,7 @@ Status MemTableList::TryInstallMemtableFlushResults(
cfd - > GetName ( ) . c_str ( ) , m - > file_number_ , mem_id ) ;
cfd - > GetName ( ) . c_str ( ) , m - > file_number_ , mem_id ) ;
assert ( m - > file_number_ > 0 ) ;
assert ( m - > file_number_ > 0 ) ;
current_ - > Remove ( m , to_delete ) ;
current_ - > Remove ( m , to_delete ) ;
UpdateMemoryUsageExcludingLast ( ) ;
UpdateCachedValuesFromMemTableListVersion ( ) ;
ResetTrimHistoryNeeded ( ) ;
ResetTrimHistoryNeeded ( ) ;
+ + mem_id ;
+ + mem_id ;
}
}
@ -544,14 +544,14 @@ void MemTableList::Add(MemTable* m, autovector<MemTable*>* to_delete) {
if ( num_flush_not_started_ = = 1 ) {
if ( num_flush_not_started_ = = 1 ) {
imm_flush_needed . store ( true , std : : memory_order_release ) ;
imm_flush_needed . store ( true , std : : memory_order_release ) ;
}
}
UpdateMemoryUsageExcludingLast ( ) ;
UpdateCachedValuesFromMemTableListVersion ( ) ;
ResetTrimHistoryNeeded ( ) ;
ResetTrimHistoryNeeded ( ) ;
}
}
void MemTableList : : TrimHistory ( autovector < MemTable * > * to_delete , size_t usage ) {
void MemTableList : : TrimHistory ( autovector < MemTable * > * to_delete , size_t usage ) {
InstallNewVersion ( ) ;
InstallNewVersion ( ) ;
current_ - > TrimHistory ( to_delete , usage ) ;
current_ - > TrimHistory ( to_delete , usage ) ;
UpdateMemoryUsageExcludingLast ( ) ;
UpdateCachedValuesFromMemTableListVersion ( ) ;
ResetTrimHistoryNeeded ( ) ;
ResetTrimHistoryNeeded ( ) ;
}
}
@ -567,17 +567,24 @@ size_t MemTableList::ApproximateUnflushedMemTablesMemoryUsage() {
size_t MemTableList : : ApproximateMemoryUsage ( ) { return current_memory_usage_ ; }
size_t MemTableList : : ApproximateMemoryUsage ( ) { return current_memory_usage_ ; }
size_t MemTableList : : ApproximateMemoryUsageExcludingLast ( ) const {
size_t MemTableList : : ApproximateMemoryUsageExcludingLast ( ) const {
size_t usage =
const size_t usage =
current_memory_usage_excluding_last_ . load ( std : : memory_order_relaxed ) ;
current_memory_usage_excluding_last_ . load ( std : : memory_order_relaxed ) ;
return usage ;
return usage ;
}
}
// Update current_memory_usage_excluding_last_, need to call whenever state
bool MemTableList : : HasHistory ( ) const {
// changes for MemtableListVersion (whenever InstallNewVersion() is called)
const bool has_history = current_has_history_ . load ( std : : memory_order_relaxed ) ;
void MemTableList : : UpdateMemoryUsageExcludingLast ( ) {
return has_history ;
size_t total_memtable_size = current_ - > ApproximateMemoryUsageExcludingLast ( ) ;
}
void MemTableList : : UpdateCachedValuesFromMemTableListVersion ( ) {
const size_t total_memtable_size =
current_ - > ApproximateMemoryUsageExcludingLast ( ) ;
current_memory_usage_excluding_last_ . store ( total_memtable_size ,
current_memory_usage_excluding_last_ . store ( total_memtable_size ,
std : : memory_order_relaxed ) ;
std : : memory_order_relaxed ) ;
const bool has_history = current_ - > HasHistory ( ) ;
current_has_history_ . store ( has_history , std : : memory_order_relaxed ) ;
}
}
uint64_t MemTableList : : ApproximateOldestKeyTime ( ) const {
uint64_t MemTableList : : ApproximateOldestKeyTime ( ) const {
@ -707,7 +714,7 @@ Status InstallMemtableAtomicFlushResults(
cfds [ i ] - > GetName ( ) . c_str ( ) , m - > GetFileNumber ( ) ,
cfds [ i ] - > GetName ( ) . c_str ( ) , m - > GetFileNumber ( ) ,
mem_id ) ;
mem_id ) ;
imm - > current_ - > Remove ( m , to_delete ) ;
imm - > current_ - > Remove ( m , to_delete ) ;
imm - > UpdateMemoryUsageExcludingLast ( ) ;
imm - > UpdateCachedValuesFromMemTableListVersion ( ) ;
imm - > ResetTrimHistoryNeeded ( ) ;
imm - > ResetTrimHistoryNeeded ( ) ;
}
}
}
}
@ -757,7 +764,7 @@ void MemTableList::RemoveOldMemTables(uint64_t log_number,
}
}
}
}
UpdateMemoryUsageExcludingLast ( ) ;
UpdateCachedValuesFromMemTableListVersion ( ) ;
ResetTrimHistoryNeeded ( ) ;
ResetTrimHistoryNeeded ( ) ;
}
}