From 661e4c92671a4e9564a32243290f4c10e5dae2bb Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 15 Nov 2016 15:18:56 -0800 Subject: [PATCH] DeleteRange unsupported in non-block-based tables Summary: Return an error from DeleteRange() (or Write() if the user is using the low-level WriteBatch API) if an unsupported table type is configured. Closes https://github.com/facebook/rocksdb/pull/1519 Differential Revision: D4185933 Pulled By: ajkr fbshipit-source-id: abcdf84 --- db/column_family.cc | 3 +++ db/column_family.h | 4 ++++ db/write_batch.cc | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/db/column_family.cc b/db/column_family.cc index bbdc3027d..80417b71b 100644 --- a/db/column_family.cc +++ b/db/column_family.cc @@ -27,6 +27,7 @@ #include "db/version_set.h" #include "db/write_controller.h" #include "memtable/hash_skiplist_rep.h" +#include "table/block_based_table_factory.h" #include "util/autovector.h" #include "util/compression.h" #include "util/options_helper.h" @@ -359,6 +360,8 @@ ColumnFamilyData::ColumnFamilyData( initial_cf_options_(SanitizeOptions(db_options, cf_options)), ioptions_(db_options, initial_cf_options_), mutable_cf_options_(initial_cf_options_), + is_delete_range_supported_(strcmp(cf_options.table_factory->Name(), + BlockBasedTableFactory().Name()) == 0), write_buffer_manager_(write_buffer_manager), mem_(nullptr), imm_(ioptions_.min_write_buffer_number_to_merge, diff --git a/db/column_family.h b/db/column_family.h index 6353e9237..5bf951e3a 100644 --- a/db/column_family.h +++ b/db/column_family.h @@ -220,6 +220,8 @@ class ColumnFamilyData { // options. ColumnFamilyOptions GetLatestCFOptions() const; + bool is_delete_range_supported() { return is_delete_range_supported_; } + #ifndef ROCKSDB_LITE // REQUIRES: DB mutex held Status SetOptions( @@ -354,6 +356,8 @@ class ColumnFamilyData { const ImmutableCFOptions ioptions_; MutableCFOptions mutable_cf_options_; + const bool is_delete_range_supported_; + std::unique_ptr table_cache_; std::unique_ptr internal_stats_; diff --git a/db/write_batch.cc b/db/write_batch.cc index 9546ae053..435c621e2 100644 --- a/db/write_batch.cc +++ b/db/write_batch.cc @@ -48,6 +48,7 @@ #include "util/coding.h" #include "util/perf_context_imp.h" #include "util/statistics.h" +#include "util/string_util.h" namespace rocksdb { @@ -973,6 +974,19 @@ class MemTableInserter : public WriteBatch::Handler { ++sequence_; return seek_status; } + if (db_ != nullptr) { + auto cf_handle = cf_mems_->GetColumnFamilyHandle(); + if (cf_handle == nullptr) { + cf_handle = db_->DefaultColumnFamily(); + } + auto* cfd = reinterpret_cast(cf_handle)->cfd(); + if (!cfd->is_delete_range_supported()) { + return Status::NotSupported( + std::string("DeleteRange not supported for table type ") + + cfd->ioptions()->table_factory->Name() + " in CF " + + cfd->GetName()); + } + } return DeleteImpl(column_family_id, begin_key, end_key, kTypeRangeDeletion); }