From 56cf461e45a23c3055d452e04b72a81278ae6f62 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 30 May 2012 16:01:38 -0700 Subject: [PATCH] OSD,FileStore: clean up filestore convsersion Previously, we messed with the filestore_update_collections config option to enable upgrades in the filestore. We now pass that in as a parameter to the FileStore,IndexManager constructors. Further, the user must now specify the version to which to update in order to prevent accidental updates. Signed-off-by: Samuel Just --- src/ceph_osd.cc | 7 +++++-- src/common/config_opts.h | 3 +-- src/os/DBObjectMap.cc | 3 ++- src/os/FileStore.cc | 13 +++++++------ src/os/FileStore.h | 6 ++++-- src/os/IndexManager.cc | 2 +- src/os/IndexManager.h | 4 +++- src/osd/OSD.cc | 13 +++---------- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index 9e6429d5b1f..484bf942eaf 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -23,6 +23,7 @@ using namespace std; #include "osd/OSD.h" +#include "os/FileStore.h" #include "include/ceph_features.h" #include "common/config.h" @@ -252,14 +253,16 @@ int main(int argc, const char **argv) } - if (convertfilestore) { + if (convertfilestore || + g_conf->filestore_update_to >= (int)FileStore::on_disk_version) { int err = OSD::convertfs(g_conf->osd_data, g_conf->osd_journal); if (err < 0) { derr << TEXT_RED << " ** ERROR: error converting store " << g_conf->osd_data << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl; exit(1); } - exit(0); + if (convertfilestore) + exit(0); } string magic; diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 50f45767010..4cf7d1868f6 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -362,8 +362,7 @@ OPTION(filestore_commit_timeout, OPT_FLOAT, 600) OPTION(filestore_fiemap_threshold, OPT_INT, 4096) OPTION(filestore_merge_threshold, OPT_INT, 10) OPTION(filestore_split_multiple, OPT_INT, 2) -OPTION(filestore_update_collections, OPT_BOOL, false) -OPTION(filestore_update_omap, OPT_BOOL, false) +OPTION(filestore_update_to, OPT_INT, 0) OPTION(filestore_blackhole, OPT_BOOL, false) // drop any new transactions on the floor OPTION(filestore_dump_file, OPT_STR, "") // file onto which store transaction dumps OPTION(filestore_kill_at, OPT_INT, 0) // inject a failure at the n'th opportunity diff --git a/src/os/DBObjectMap.cc b/src/os/DBObjectMap.cc index da2f3cd938d..4852b2aac76 100644 --- a/src/os/DBObjectMap.cc +++ b/src/os/DBObjectMap.cc @@ -998,7 +998,8 @@ int DBObjectMap::init(bool do_upgrade) state.decode(bliter); if (state.v < 1) { // Needs upgrade if (!do_upgrade) { - dout(1) << "DOBjbectMap requires an upgrade, set filestore_update_omap" + dout(1) << "DOBjbectMap requires an upgrade," + << " set filestore_update_to" << dendl; return -ENOTSUP; } else { diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 540ecdcdaa3..3faaa76f6ab 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -659,7 +659,7 @@ done: return r; } -FileStore::FileStore(const std::string &base, const std::string &jdev, const char *name) : +FileStore::FileStore(const std::string &base, const std::string &jdev, const char *name, bool do_update) : internal_name(name), basedir(base), journalpath(jdev), btrfs(false), @@ -673,6 +673,7 @@ FileStore::FileStore(const std::string &base, const std::string &jdev, const cha ioctl_fiemap(false), fsid_fd(-1), op_fd(-1), basedir_fd(-1), current_fd(-1), + index_manager(do_update), ondisk_finisher(g_ceph_context), lock("FileStore::lock"), force_sync(false), sync_epoch(0), @@ -701,7 +702,7 @@ FileStore::FileStore(const std::string &base, const std::string &jdev, const cha m_filestore_flusher_max_fds(g_conf->filestore_flusher_max_fds), m_filestore_max_sync_interval(g_conf->filestore_max_sync_interval), m_filestore_min_sync_interval(g_conf->filestore_min_sync_interval), - m_filestore_update_collections(g_conf->filestore_update_collections), + do_update(do_update), m_journal_dio(g_conf->journal_dio), m_journal_aio(g_conf->journal_aio), m_osd_rollback_to_cluster_snap(g_conf->osd_rollback_to_cluster_snap), @@ -1672,10 +1673,10 @@ int FileStore::mount() << cpp_strerror(ret) << dendl; goto close_fsid_fd; } else if (ret == 0) { - if (m_filestore_update_collections) { + if (do_update) { derr << "FileStore::mount : stale version stamp detected: " << version_stamp - << ". Proceeding, m_filestore_update_collections " + << ". Proceeding, do_update " << "is set, DO NOT USE THIS OPTION IF YOU DO NOT KNOW WHAT IT DOES." << " More details can be found on the wiki." << dendl; @@ -1683,7 +1684,7 @@ int FileStore::mount() ret = -EINVAL; derr << "FileStore::mount : stale version stamp " << version_stamp << ". Please run the FileStore update script before starting the " - << "OSD." + << "OSD, or set filestore_update_to to " << on_disk_version << dendl; goto close_fsid_fd; } @@ -1882,7 +1883,7 @@ int FileStore::mount() goto close_current_fd; } DBObjectMap *dbomap = new DBObjectMap(omap_store); - ret = dbomap->init(m_filestore_update_collections); + ret = dbomap->init(do_update); if (ret < 0) { derr << "Error initializing DBObjectMap: " << ret << dendl; goto close_current_fd; diff --git a/src/os/FileStore.h b/src/os/FileStore.h index ef9bc7bde0f..ba333adbb56 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -47,7 +47,9 @@ using namespace __gnu_cxx; class FileStore : public JournalingObjectStore, public md_config_obs_t { +public: static const uint32_t on_disk_version = 3; +private: string internal_name; ///< internal name, used to name the perfcounter instance string basedir, journalpath; std::string current_fn; @@ -283,7 +285,7 @@ public: int lfn_unlink(coll_t cid, const hobject_t& o); public: - FileStore(const std::string &base, const std::string &jdev, const char *internal_name = "filestore"); + FileStore(const std::string &base, const std::string &jdev, const char *internal_name = "filestore", bool update_to=false); ~FileStore(); int _test_fiemap(); @@ -475,7 +477,7 @@ private: int m_filestore_flusher_max_fds; double m_filestore_max_sync_interval; double m_filestore_min_sync_interval; - bool m_filestore_update_collections; + int do_update; bool m_journal_dio, m_journal_aio; std::string m_osd_rollback_to_cluster_snap; bool m_osd_use_stale_snap; diff --git a/src/os/IndexManager.cc b/src/os/IndexManager.cc index a9343dbdb46..82120ebf7b0 100644 --- a/src/os/IndexManager.cc +++ b/src/os/IndexManager.cc @@ -83,7 +83,7 @@ int IndexManager::init_index(coll_t c, const char *path, uint32_t version) { int IndexManager::build_index(coll_t c, const char *path, Index *index) { int r; - if (g_conf->filestore_update_collections) { + if (upgrade) { // Need to check the collection generation uint32_t version = 0; r = get_version(path, &version); diff --git a/src/os/IndexManager.h b/src/os/IndexManager.h index a630eba6a69..43de7ee49c8 100644 --- a/src/os/IndexManager.h +++ b/src/os/IndexManager.h @@ -47,6 +47,7 @@ typedef std::tr1::shared_ptr Index; class IndexManager { Mutex lock; ///< Lock for Index Manager Cond cond; ///< Cond for waiters on col_indices + bool upgrade; /// Currently in use CollectionIndices map > col_indices; @@ -84,7 +85,8 @@ class IndexManager { int build_index(coll_t c, const char *path, Index *index); public: /// Constructor - IndexManager() : lock("IndexManager lock") {} + IndexManager(bool upgrade) : lock("IndexManager lock"), + upgrade(upgrade) {} /** * Reserve and return index for c diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 9feec158c6b..01c63c4ec28 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -246,17 +246,10 @@ static int do_convertfs(ObjectStore *store) int OSD::convertfs(const std::string &dev, const std::string &jdev) { - // N.B. at some point we should rewrite this to avoid playing games with - // g_conf here - char buf[16] = { 0 }; - char *b = buf; - g_ceph_context->_conf->get_val("filestore_update_collections", &b, sizeof(buf)); - g_ceph_context->_conf->set_val_or_die("filestore_update_collections", "true"); - g_ceph_context->_conf->apply_changes(NULL); - boost::scoped_ptr store(new FileStore(dev, jdev)); + boost::scoped_ptr store( + new FileStore(dev, jdev, "filestore", + true)); int r = do_convertfs(store.get()); - g_ceph_context->_conf->set_val_or_die("filestore_update_collections", buf); - g_ceph_context->_conf->apply_changes(NULL); return r; }