From 5467d7a1169817a99ef8fe5fd145686c238a94c0 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Thu, 1 Dec 2016 10:00:56 -0800 Subject: [PATCH] Kill flashcache code in RocksDB Summary: Now that we have userspace persisted cache, we don't need flashcache anymore. Closes https://github.com/facebook/rocksdb/pull/1588 Differential Revision: D4245114 Pulled By: igorcanadi fbshipit-source-id: e2c1c72 --- CMakeLists.txt | 1 - HISTORY.md | 4 + include/rocksdb/utilities/flashcache.h | 25 ---- src.mk | 1 - third-party/flashcache/flashcache_ioctl.h | 55 --------- tools/db_bench_tool.cc | 36 +----- utilities/flashcache/flashcache.cc | 136 ---------------------- utilities/flashcache/flashcache.h | 18 --- 8 files changed, 6 insertions(+), 270 deletions(-) delete mode 100644 include/rocksdb/utilities/flashcache.h delete mode 100644 third-party/flashcache/flashcache_ioctl.h delete mode 100644 utilities/flashcache/flashcache.cc delete mode 100644 utilities/flashcache/flashcache.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 677fadc08..efbf4f50c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -391,7 +391,6 @@ set(SOURCES utilities/document/json_document_builder.cc utilities/env_mirror.cc utilities/env_registry.cc - utilities/flashcache/flashcache.cc utilities/geodb/geodb_impl.cc utilities/leveldb_options/leveldb_options.cc utilities/memory/memory_util.cc diff --git a/HISTORY.md b/HISTORY.md index b8cf02ced..b628e994d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,8 @@ # Rocksdb Change Log +## 4.13.4 +### Public API Change +* Removed flashcache support. + ## 4.13.0 (10/18/2016) ### Public API Change * DB::GetOptions() reflect dynamic changed options (i.e. through DB::SetOptions()) and return copy of options instead of reference. diff --git a/include/rocksdb/utilities/flashcache.h b/include/rocksdb/utilities/flashcache.h deleted file mode 100644 index b54d245f0..000000000 --- a/include/rocksdb/utilities/flashcache.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. - -#pragma once - -#include -#include "rocksdb/env.h" - -namespace rocksdb { - -// This API is experimental. We will mark it stable once we run it in production -// for a while. -// NewFlashcacheAwareEnv() creates and Env that blacklists all background -// threads (used for flush and compaction) from using flashcache to cache their -// reads. Reads from compaction thread don't need to be cached because they are -// going to be soon made obsolete (due to nature of compaction) -// Usually you would pass Env::Default() as base. -// cachedev_fd is a file descriptor of the flashcache device. Caller has to -// open flashcache device before calling this API. -extern std::unique_ptr NewFlashcacheAwareEnv( - Env* base, const int cachedev_fd); - -} // namespace rocksdb diff --git a/src.mk b/src.mk index 533b6c61d..35860ee2d 100644 --- a/src.mk +++ b/src.mk @@ -154,7 +154,6 @@ LIB_SOURCES = \ utilities/document/json_document.cc \ utilities/env_mirror.cc \ utilities/env_registry.cc \ - utilities/flashcache/flashcache.cc \ utilities/geodb/geodb_impl.cc \ utilities/leveldb_options/leveldb_options.cc \ utilities/memory/memory_util.cc \ diff --git a/third-party/flashcache/flashcache_ioctl.h b/third-party/flashcache/flashcache_ioctl.h deleted file mode 100644 index af111ab4d..000000000 --- a/third-party/flashcache/flashcache_ioctl.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * flashcache_ioctl.h - * FlashCache: Device mapper target for block-level disk caching - * - * Copyright 2010 Facebook, Inc. - * Author: Mohan Srinivasan (mohan@facebook.com) - * - * Based on DM-Cache: - * Copyright (C) International Business Machines Corp., 2006 - * Author: Ming Zhao (mingzhao@ufl.edu) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - ****************************************************************************/ - -#ifdef OS_LINUX -#ifndef FLASHCACHE_IOCTL_H -#define FLASHCACHE_IOCTL_H - -#include - -#define FLASHCACHE_IOCTL 0xfe - -enum { - FLASHCACHEADDNCPID_CMD=200, - FLASHCACHEDELNCPID_CMD, - FLASHCACHEDELNCALL_CMD, - FLASHCACHEADDWHITELIST_CMD, - FLASHCACHEDELWHITELIST_CMD, - FLASHCACHEDELWHITELISTALL_CMD, -}; - -#define FLASHCACHEADDNCPID _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDNCPID_CMD, pid_t) -#define FLASHCACHEDELNCPID _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCPID_CMD, pid_t) -#define FLASHCACHEDELNCALL _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELNCALL_CMD, pid_t) - -#define FLASHCACHEADDBLACKLIST FLASHCACHEADDNCPID -#define FLASHCACHEDELBLACKLIST FLASHCACHEDELNCPID -#define FLASHCACHEDELALLBLACKLIST FLASHCACHEDELNCALL - -#define FLASHCACHEADDWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEADDWHITELIST_CMD, pid_t) -#define FLASHCACHEDELWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELIST_CMD, pid_t) -#define FLASHCACHEDELALLWHITELIST _IOW(FLASHCACHE_IOCTL, FLASHCACHEDELWHITELISTALL_CMD, pid_t) - -#endif /* FLASHCACHE_IOCTL_H */ -#endif /* OS_LINUX */ diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index eb5a3b858..b582edb8e 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -48,7 +48,6 @@ #include "rocksdb/slice.h" #include "rocksdb/slice_transform.h" #include "rocksdb/utilities/env_registry.h" -#include "rocksdb/utilities/flashcache.h" #include "rocksdb/utilities/optimistic_transaction_db.h" #include "rocksdb/utilities/options_util.h" #include "rocksdb/utilities/sim_cache.h" @@ -573,8 +572,6 @@ DEFINE_string( "\t--row_cache_size\n" "\t--row_cache_numshardbits\n" "\t--enable_io_prio\n" - "\t--disable_flashcache_for_background_threads\n" - "\t--flashcache_dev\n" "\t--dump_malloc_stats\n" "\t--num_multi_db\n"); #endif // ROCKSDB_LITE @@ -769,11 +766,6 @@ DEFINE_string(compaction_fadvice, "NORMAL", static auto FLAGS_compaction_fadvice_e = rocksdb::Options().access_hint_on_compaction_start; -DEFINE_bool(disable_flashcache_for_background_threads, false, - "Disable flashcache for background threads"); - -DEFINE_string(flashcache_dev, "", "Path to flashcache device"); - DEFINE_bool(use_tailing_iterator, false, "Use tailing iterator to access a series of keys instead of get"); @@ -1739,7 +1731,6 @@ class Benchmark { int64_t readwrites_; int64_t merge_keys_; bool report_file_operations_; - int cachedev_fd_; bool SanityCheck() { if (FLAGS_compression_ratio > 1) { @@ -1995,8 +1986,7 @@ class Benchmark { ? FLAGS_num : ((FLAGS_writes > FLAGS_reads) ? FLAGS_writes : FLAGS_reads)), merge_keys_(FLAGS_merge_keys < 0 ? FLAGS_num : FLAGS_merge_keys), - report_file_operations_(FLAGS_report_file_operations), - cachedev_fd_(-1) { + report_file_operations_(FLAGS_report_file_operations) { // use simcache instead of cache if (FLAGS_simcache_size >= 0) { if (FLAGS_cache_numshardbits >= 1) { @@ -2055,11 +2045,6 @@ class Benchmark { // this will leak, but we're shutting down so nobody cares cache_->DisownData(); } - if (FLAGS_disable_flashcache_for_background_threads && cachedev_fd_ != -1) { - // Dtor for thiis env should run before cachedev_fd_ is closed - flashcache_aware_env_ = nullptr; - close(cachedev_fd_); - } } Slice AllocateKey(std::unique_ptr* key_guard) { @@ -2415,7 +2400,6 @@ class Benchmark { } private: - std::unique_ptr flashcache_aware_env_; std::shared_ptr timestamp_emulator_; struct ThreadArg { @@ -2994,23 +2978,7 @@ class Benchmark { FLAGS_env->LowerThreadPoolIOPriority(Env::LOW); FLAGS_env->LowerThreadPoolIOPriority(Env::HIGH); } - if (FLAGS_disable_flashcache_for_background_threads && cachedev_fd_ == -1) { - // Avoid creating the env twice when an use_existing_db is true - cachedev_fd_ = open(FLAGS_flashcache_dev.c_str(), O_RDONLY); - if (cachedev_fd_ < 0) { - fprintf(stderr, "Open flash device failed\n"); - exit(1); - } - flashcache_aware_env_ = NewFlashcacheAwareEnv(FLAGS_env, cachedev_fd_); - if (flashcache_aware_env_.get() == nullptr) { - fprintf(stderr, "Failed to open flashcache device at %s\n", - FLAGS_flashcache_dev.c_str()); - std::abort(); - } - options.env = flashcache_aware_env_.get(); - } else { - options.env = FLAGS_env; - } + options.env = FLAGS_env; if (FLAGS_num_multi_db <= 1) { OpenDb(options, FLAGS_db, &db_); diff --git a/utilities/flashcache/flashcache.cc b/utilities/flashcache/flashcache.cc deleted file mode 100644 index 3765300d3..000000000 --- a/utilities/flashcache/flashcache.cc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. - -#include "utilities/flashcache/flashcache.h" - -#include "rocksdb/utilities/flashcache.h" - -#ifdef OS_LINUX -#include -#include -#include -#include -#include - -#include "third-party/flashcache/flashcache_ioctl.h" -#endif - -namespace rocksdb { - -#if !defined(ROCKSDB_LITE) && defined(OS_LINUX) -// Most of the code that handles flashcache is copied from websql's branch of -// mysql-5.6 -class FlashcacheAwareEnv : public EnvWrapper { - public: - FlashcacheAwareEnv(Env* base, int cachedev_fd) - : EnvWrapper(base), cachedev_fd_(cachedev_fd) { - pid_t pid = getpid(); - /* cleanup previous whitelistings */ - if (ioctl(cachedev_fd_, FLASHCACHEDELALLWHITELIST, &pid) < 0) { - cachedev_fd_ = -1; - fprintf(stderr, "ioctl del-all-whitelist for flashcache failed\n"); - return; - } - if (ioctl(cachedev_fd_, FLASHCACHEADDWHITELIST, &pid) < 0) { - fprintf(stderr, "ioctl add-whitelist for flashcache failed\n"); - } - } - - ~FlashcacheAwareEnv() { - // cachedev_fd_ is -1 if it's unitialized - if (cachedev_fd_ != -1) { - pid_t pid = getpid(); - if (ioctl(cachedev_fd_, FLASHCACHEDELWHITELIST, &pid) < 0) { - fprintf(stderr, "ioctl del-whitelist for flashcache failed\n"); - } - } - } - - static int BlacklistCurrentThread(int cachedev_fd) { - pid_t pid = static_cast(syscall(SYS_gettid)); - return ioctl(cachedev_fd, FLASHCACHEADDNCPID, &pid); - } - - static int WhitelistCurrentThread(int cachedev_fd) { - pid_t pid = static_cast(syscall(SYS_gettid)); - return ioctl(cachedev_fd, FLASHCACHEDELNCPID, &pid); - } - - int GetFlashCacheFileDescriptor() { return cachedev_fd_; } - - struct Arg { - Arg(void (*f)(void* arg), void* a, int _cachedev_fd) - : original_function_(f), original_arg_(a), cachedev_fd(_cachedev_fd) {} - - void (*original_function_)(void* arg); - void* original_arg_; - int cachedev_fd; - }; - - static void BgThreadWrapper(void* a) { - Arg* arg = reinterpret_cast(a); - if (arg->cachedev_fd != -1) { - if (BlacklistCurrentThread(arg->cachedev_fd) < 0) { - fprintf(stderr, "ioctl add-nc-pid for flashcache failed\n"); - } - } - arg->original_function_(arg->original_arg_); - if (arg->cachedev_fd != -1) { - if (WhitelistCurrentThread(arg->cachedev_fd) < 0) { - fprintf(stderr, "ioctl del-nc-pid for flashcache failed\n"); - } - } - delete arg; - } - - int UnSchedule(void* arg, Priority pri) override { - // no unschedule for you - return 0; - } - - void Schedule(void (*f)(void* arg), void* a, Priority pri, - void* tag = nullptr, void (*u)(void* arg) = 0) override { - EnvWrapper::Schedule(&BgThreadWrapper, new Arg(f, a, cachedev_fd_), pri, - tag); - } - - private: - int cachedev_fd_; -}; - -std::unique_ptr NewFlashcacheAwareEnv(Env* base, - const int cachedev_fd) { - std::unique_ptr ret(new FlashcacheAwareEnv(base, cachedev_fd)); - return ret; -} - -int FlashcacheBlacklistCurrentThread(Env* flashcache_aware_env) { - int fd = dynamic_cast(flashcache_aware_env) - ->GetFlashCacheFileDescriptor(); - if (fd == -1) { - return -1; - } - return FlashcacheAwareEnv::BlacklistCurrentThread(fd); -} -int FlashcacheWhitelistCurrentThread(Env* flashcache_aware_env) { - int fd = dynamic_cast(flashcache_aware_env) - ->GetFlashCacheFileDescriptor(); - if (fd == -1) { - return -1; - } - return FlashcacheAwareEnv::WhitelistCurrentThread(fd); -} - -#else // !defined(ROCKSDB_LITE) && defined(OS_LINUX) -std::unique_ptr NewFlashcacheAwareEnv(Env* base, - const int cachedev_fd) { - return nullptr; -} -int FlashcacheBlacklistCurrentThread(Env* flashcache_aware_env) { return -1; } -int FlashcacheWhitelistCurrentThread(Env* flashcache_aware_env) { return -1; } - -#endif // !defined(ROCKSDB_LITE) && defined(OS_LINUX) - -} // namespace rocksdb diff --git a/utilities/flashcache/flashcache.h b/utilities/flashcache/flashcache.h deleted file mode 100644 index 94a3ed41f..000000000 --- a/utilities/flashcache/flashcache.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. -// This source code is licensed under the BSD-style license found in the -// LICENSE file in the root directory of this source tree. An additional grant -// of patent rights can be found in the PATENTS file in the same directory. - -#pragma once - -#include -#include "rocksdb/env.h" - -namespace rocksdb { - -// This is internal API that will make hacking on flashcache easier. Not sure if -// we need to expose this to public users, probably not -extern int FlashcacheBlacklistCurrentThread(Env* flashcache_aware_env); -extern int FlashcacheWhitelistCurrentThread(Env* flashcache_aware_env); - -} // namespace rocksdb