diff --git a/db/db_impl/db_impl_write.cc b/db/db_impl/db_impl_write.cc index 8065f0a79..c74511a47 100644 --- a/db/db_impl/db_impl_write.cc +++ b/db/db_impl/db_impl_write.cc @@ -1518,12 +1518,14 @@ Status DBImpl::TrimMemtableHistory(WriteContext* context) { for (auto& cfd : cfds) { autovector to_delete; cfd->imm()->TrimHistory(&to_delete, cfd->mem()->ApproximateMemoryUsage()); - for (auto m : to_delete) { - delete m; + if (!to_delete.empty()) { + for (auto m : to_delete) { + delete m; + } + context->superversion_context.NewSuperVersion(); + assert(context->superversion_context.new_superversion.get() != nullptr); + cfd->InstallSuperVersion(&context->superversion_context, &mutex_); } - context->superversion_context.NewSuperVersion(); - assert(context->superversion_context.new_superversion.get() != nullptr); - cfd->InstallSuperVersion(&context->superversion_context, &mutex_); if (cfd->UnrefAndTryDelete()) { cfd = nullptr;