Skip to content

Commit

Permalink
fix checkpoint again (tikv#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabokie authored Jul 26, 2023
1 parent 14f36f8 commit 5b9cef9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions db/db_filesnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Status DBImpl::FlushForGetLiveFiles() {
Status status;
FlushOptions opts;
opts.allow_write_stall = true;
// In TiKV context: If tablet is to be destroyed, its background work will be
// paused. Manual flush can never make progress.
opts.check_if_compaction_disabled = true;
if (immutable_db_options_.atomic_flush) {
autovector<ColumnFamilyData*> cfds;
SelectColumnFamiliesForAtomicFlush(&cfds);
Expand Down
20 changes: 13 additions & 7 deletions db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Status DBImpl::ResumeImpl(DBRecoverContext context) {
FlushOptions flush_opts;
// We allow flush to stall write since we are trying to resume from error.
flush_opts.allow_write_stall = true;
flush_opts.check_if_compaction_disabled = true;
if (immutable_db_options_.atomic_flush) {
autovector<ColumnFamilyData*> cfds;
SelectColumnFamiliesForAtomicFlush(&cfds);
Expand Down Expand Up @@ -487,19 +488,21 @@ void DBImpl::CancelAllBackgroundWork(bool wait) {
if (!shutting_down_.load(std::memory_order_acquire) &&
has_unpersisted_data_.load(std::memory_order_relaxed) &&
!mutable_db_options_.avoid_flush_during_shutdown) {
auto flush_opts = FlushOptions();
flush_opts.allow_write_stall = true;
flush_opts.check_if_compaction_disabled = true;
if (immutable_db_options_.atomic_flush) {
autovector<ColumnFamilyData*> cfds;
SelectColumnFamiliesForAtomicFlush(&cfds);
mutex_.Unlock();
Status s =
AtomicFlushMemTables(cfds, FlushOptions(), FlushReason::kShutDown);
Status s = AtomicFlushMemTables(cfds, flush_opts, FlushReason::kShutDown);
s.PermitUncheckedError(); //**TODO: What to do on error?
mutex_.Lock();
} else {
for (auto cfd : versions_->GetRefedColumnFamilySet()) {
if (!cfd->IsDropped() && cfd->initialized() && !cfd->mem()->IsEmpty()) {
InstrumentedMutexUnlock u(&mutex_);
Status s = FlushMemTable(cfd, FlushOptions(), FlushReason::kShutDown);
Status s = FlushMemTable(cfd, flush_opts, FlushReason::kShutDown);
s.PermitUncheckedError(); //**TODO: What to do on error?
}
}
Expand Down Expand Up @@ -574,18 +577,20 @@ Status DBImpl::CloseHelper() {
if (immutable_db_options_.experimental_mempurge_threshold > 0.0) {
Status flush_ret;
mutex_.Unlock();
auto flush_opts = FlushOptions();
flush_opts.allow_write_stall = true;
flush_opts.check_if_compaction_disabled = true;
for (ColumnFamilyData* cf : *versions_->GetColumnFamilySet()) {
if (immutable_db_options_.atomic_flush) {
flush_ret = AtomicFlushMemTables({cf}, FlushOptions(),
FlushReason::kManualFlush);
flush_ret =
AtomicFlushMemTables({cf}, flush_opts, FlushReason::kManualFlush);
if (!flush_ret.ok()) {
ROCKS_LOG_INFO(
immutable_db_options_.info_log,
"Atomic flush memtables failed upon closing (mempurge).");
}
} else {
flush_ret =
FlushMemTable(cf, FlushOptions(), FlushReason::kManualFlush);
flush_ret = FlushMemTable(cf, flush_opts, FlushReason::kManualFlush);
if (!flush_ret.ok()) {
ROCKS_LOG_INFO(immutable_db_options_.info_log,
"Flush memtables failed upon closing (mempurge).");
Expand Down Expand Up @@ -4811,6 +4816,7 @@ Status DBImpl::IngestExternalFiles(
if (status.ok() && at_least_one_cf_need_flush) {
FlushOptions flush_opts;
flush_opts.allow_write_stall = true;
flush_opts.check_if_compaction_disabled = true;
if (immutable_db_options_.atomic_flush) {
autovector<ColumnFamilyData*> cfds_to_flush;
SelectColumnFamiliesForAtomicFlush(&cfds_to_flush);
Expand Down
1 change: 1 addition & 0 deletions db/db_impl/db_impl_compaction_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ Status DBImpl::CompactRangeInternal(const CompactRangeOptions& options,
if (s.ok() && flush_needed) {
FlushOptions fo;
fo.allow_write_stall = options.allow_write_stall;
fo.check_if_compaction_disabled = true;
if (immutable_db_options_.atomic_flush) {
autovector<ColumnFamilyData*> cfds;
mutex_.Lock();
Expand Down

0 comments on commit 5b9cef9

Please sign in to comment.