Revision 9a449865e3963e7cff0bc7fc7f0731d3dea459de authored by Paul O'Shannessy on 30 August 2019, 06:19:10 UTC, committed by Facebook Github Bot on 30 August 2019, 06:21:01 UTC
Summary:
In order to foster healthy open source communities, we're adopting the
[Contributor Covenant](https://www.contributor-covenant.org/). It has been
built by open source community members and represents a shared understanding of
what is expected from a healthy community.

Reviewed By: josephsavona, danobi, rdzhabarov

Differential Revision: D17104640

fbshipit-source-id: d210000de686c5f0d97d602b50472d5869bc6a49
1 parent a281822
Raw File
trim_history_scheduler.cc
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
//  This source code is licensed under both the GPLv2 (found in the
//  COPYING file in the root directory) and Apache 2.0 License
//  (found in the LICENSE.Apache file in the root directory).

#include "db/trim_history_scheduler.h"

#include <cassert>

#include "db/column_family.h"

namespace rocksdb {

void TrimHistoryScheduler::ScheduleWork(ColumnFamilyData* cfd) {
  std::lock_guard<std::mutex> lock(checking_mutex_);
  cfd->Ref();
  cfds_.push_back(cfd);
  is_empty_.store(false, std::memory_order_relaxed);
}

ColumnFamilyData* TrimHistoryScheduler::TakeNextColumnFamily() {
  std::lock_guard<std::mutex> lock(checking_mutex_);
  while (true) {
    if (cfds_.empty()) {
      return nullptr;
    }
    ColumnFamilyData* cfd = cfds_.back();
    cfds_.pop_back();
    if (cfds_.empty()) {
      is_empty_.store(true, std::memory_order_relaxed);
    }

    if (!cfd->IsDropped()) {
      // success
      return cfd;
    }
    if (cfd->Unref()) {
      // no longer relevant, retry
      delete cfd;
    }
  }
}

bool TrimHistoryScheduler::Empty() {
  bool is_empty = is_empty_.load(std::memory_order_relaxed);
  return is_empty;
}

void TrimHistoryScheduler::Clear() {
  ColumnFamilyData* cfd;
  while ((cfd = TakeNextColumnFamily()) != nullptr) {
    if (cfd->Unref()) {
      delete cfd;
    }
  }
  assert(Empty());
}

}  // namespace rocksdb
back to top