+// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "utilities/ttl/db_ttl_impl.h"
#include "db/write_batch_internal.h"
+#include "file/filename.h"
#include "rocksdb/convenience.h"
#include "rocksdb/env.h"
#include "rocksdb/iterator.h"
#include "rocksdb/utilities/db_ttl.h"
#include "util/coding.h"
-#include "util/filename.h"
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
void DBWithTTLImpl::SanitizeOptions(int32_t ttl, ColumnFamilyOptions* options,
Env* env) {
}
// Open the db inside DBWithTTLImpl because options needs pointer to its ttl
-DBWithTTLImpl::DBWithTTLImpl(DB* db) : DBWithTTL(db) {}
+DBWithTTLImpl::DBWithTTLImpl(DB* db) : DBWithTTL(db), closed_(false) {}
DBWithTTLImpl::~DBWithTTLImpl() {
- // Need to stop background compaction before getting rid of the filter
- CancelAllBackgroundWork(db_, /* wait = */ true);
- delete GetOptions().compaction_filter;
+ if (!closed_) {
+ Close();
+ }
+}
+
+Status DBWithTTLImpl::Close() {
+ Status ret = Status::OK();
+ if (!closed_) {
+ Options default_options = GetOptions();
+ // Need to stop background compaction before getting rid of the filter
+ CancelAllBackgroundWork(db_, /* wait = */ true);
+ ret = db_->Close();
+ delete default_options.compaction_filter;
+ closed_ = true;
+ }
+ return ret;
}
Status UtilityDB::OpenTtlDB(const Options& options, const std::string& dbname,
const DBOptions& db_options, const std::string& dbname,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DBWithTTL** dbptr,
- std::vector<int32_t> ttls, bool read_only) {
-
+ const std::vector<int32_t>& ttls, bool read_only) {
if (ttls.size() != column_families.size()) {
return Status::InvalidArgument(
"ttls size has to be the same as number of column families");
explicit Handler(Env* env) : env_(env) {}
WriteBatch updates_ttl;
Status batch_rewrite_status;
- virtual Status PutCF(uint32_t column_family_id, const Slice& key,
- const Slice& value) override {
+ Status PutCF(uint32_t column_family_id, const Slice& key,
+ const Slice& value) override {
std::string value_with_ts;
Status st = AppendTS(value, &value_with_ts, env_);
if (!st.ok()) {
}
return Status::OK();
}
- virtual Status MergeCF(uint32_t column_family_id, const Slice& key,
- const Slice& value) override {
+ Status MergeCF(uint32_t column_family_id, const Slice& key,
+ const Slice& value) override {
std::string value_with_ts;
Status st = AppendTS(value, &value_with_ts, env_);
if (!st.ok()) {
}
return Status::OK();
}
- virtual Status DeleteCF(uint32_t column_family_id,
- const Slice& key) override {
+ Status DeleteCF(uint32_t column_family_id, const Slice& key) override {
WriteBatchInternal::Delete(&updates_ttl, column_family_id, key);
return Status::OK();
}
- virtual void LogData(const Slice& blob) override {
- updates_ttl.PutLogData(blob);
- }
+ void LogData(const Slice& blob) override { updates_ttl.PutLogData(blob); }
private:
Env* env_;
filter->SetTtl(ttl);
}
-} // namespace rocksdb
+} // namespace ROCKSDB_NAMESPACE
#endif // ROCKSDB_LITE