]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cosd,OSD: Improve filestore upgrade path
authorSamuel Just <samuel.just@dreamhost.com>
Tue, 30 Aug 2011 22:34:18 +0000 (15:34 -0700)
committerSamuel Just <samuel.just@dreamhost.com>
Tue, 30 Aug 2011 22:35:51 +0000 (15:35 -0700)
Previously, fsconverter was required to update an osd filestore to the
most recent version.  cosd will now handle that automatically on
startup.  cosd --convert-filestore will also update the FileStore
to the most recent version.

Signed-off-by: Samuel Just <samuel.just@dreamhost.com>
src/Makefile.am
src/cosd.cc
src/fsconverter.cc [deleted file]
src/osd/OSD.cc
src/osd/OSD.h

index f9561e77100f536b9ad060da7a2d3bae4dc9f8f8..fec53138dfab57512caaca00d6040ccfbd35fd60 100644 (file)
@@ -97,10 +97,6 @@ osdmaptool_SOURCES = osdmaptool.cc
 osdmaptool_LDADD = $(LIBGLOBAL_LDA)
 bin_PROGRAMS += monmaptool crushtool osdmaptool
 
-fsconverter_SOURCES = fsconverter.cc
-fsconverter_LDADD = libos.la $(LIBGLOBAL_LDA)
-bin_PROGRAMS += fsconverter
-
 mount_ceph_SOURCES = mount/mount.ceph.c common/armor.c common/safe_io.c common/secret.c include/addr_parsing.c
 mount_ceph_LDADD = -lkeyutils
 sbin_PROGRAMS += mount.ceph
@@ -118,7 +114,7 @@ csyn_SOURCES = csyn.cc client/SyntheticClient.cc
 csyn_LDADD = libclient.la libosdc.la $(LIBGLOBAL_LDA)
 bin_PROGRAMS += csyn
 
-core: cmon cosd cmds ceph cephfs librados-config cconf monmaptool osdmaptool crushtool csyn fsconverter
+core: cmon cosd cmds ceph cephfs librados-config cconf monmaptool osdmaptool crushtool csyn
 
 
 # fuse targets?
@@ -1356,7 +1352,7 @@ noinst_HEADERS = \
        test/rados-api/test.h
 
 all_sources = $(cmon_SOURCES) $(ceph_SOURCES) $(cephfs_SOURCES) $(librados_config_SOURCES) $(cauthtool_SOURCES) $(monmaptool_SOURCES) \
-       $(fsconverter_SOURCES) $(crushtool_SOURCES) $(osdmaptool_SOURCES) $(cconf_SOURCES) $(mount_ceph_SOURCES) $(cmds_SOURCES) \
+       $(crushtool_SOURCES) $(osdmaptool_SOURCES) $(cconf_SOURCES) $(mount_ceph_SOURCES) $(cmds_SOURCES) \
        $(cosd_SOURCES) $(dupstore_SOURCES) $(store_test_SOURCES) $(streamtest_SOURCES) $(csyn_SOURCES)  \
        $(testmsgr_SOURCES) $(cfuse_SOURCES) $(fakefuse_SOURCES) $(psim_SOURCES) \
        $(libcommon_files) $(libmon_la_SOURCES) $(libmds_a_SOURCES) \
index 18351f787859106dc16f2057cb3a3938d41ccfc6..7ff132723a371a713a1c6a784984cf59f706b62e 100644 (file)
@@ -43,7 +43,7 @@ using namespace std;
 void usage() 
 {
   derr << "usage: cosd -i osdid [--osd-data=path] [--osd-journal=path] "
-       << "[--mkfs] [--mkjournal]" << dendl;
+       << "[--mkfs] [--mkjournal] [--convert-filestore]" << dendl;
   derr << "   --debug_osd N   set debug level (e.g. 10)" << dendl;
   generic_server_usage();
 }
@@ -64,6 +64,7 @@ int main(int argc, const char **argv)
   bool mkjournal = false;
   bool mkkey = false;
   bool flushjournal = false;
+  bool convertfilestore = false;
   char *dump_pg_log = 0;
   FOR_EACH_ARG(args) {
     if (CEPH_ARGPARSE_EQ("mkfs", '\0')) {
@@ -74,6 +75,8 @@ int main(int argc, const char **argv)
       mkkey = true;
     } else if (CEPH_ARGPARSE_EQ("flush-journal", '\0')) {
       flushjournal = true;
+    } else if (CEPH_ARGPARSE_EQ("convert-filestore", '\0')) {
+      convertfilestore = true;
     } else if (CEPH_ARGPARSE_EQ("dump-pg-log", '\0')) {
       CEPH_ARGPARSE_SET_ARG_VAL(&dump_pg_log, OPT_STR);
     } else {
@@ -189,6 +192,17 @@ int main(int argc, const char **argv)
         << dendl;
     exit(0);
   }
+
+  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);
+  }
+  if (convertfilestore) {
+    derr << "Converted Filestore " << g_conf->osd_data << dendl;
+    exit(0);
+  }
   
   string magic;
   ceph_fsid_t fsid;
@@ -288,7 +302,7 @@ int main(int argc, const char **argv)
                     messenger_hbin, messenger_hbout,
                     &mc,
                     g_conf->osd_data, g_conf->osd_journal);
-  int err = osd->pre_init();
+  err = osd->pre_init();
   if (err < 0) {
     derr << TEXT_RED << " ** ERROR: initializing osd failed: " << cpp_strerror(-err)
         << TEXT_NORMAL << dendl;
diff --git a/src/fsconverter.cc b/src/fsconverter.cc
deleted file mode 100644 (file)
index 7d4c571..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-#include <iostream>
-#include "os/FileStore.h"
-#include "common/ceph_argparse.h"
-#include "global/global_init.h"
-#include <boost/scoped_ptr.hpp>
-
-#include <ext/hash_map>
-using __gnu_cxx::hash_map;
-
-void usage() {
-  cerr << "usage: fsconverter filestore_path journal_path" << std::endl;
-  exit(0);
-}
-
-int convert_collection(ObjectStore *store, coll_t cid) {
-  vector<hobject_t> objects;
-  int r = store->collection_list(cid, objects);
-  if (r < 0)
-    return r;
-  string temp_name("temp");
-  map<string, bufferptr> aset;
-  r = store->collection_getattrs(cid, aset);
-  if (r < 0)
-    return r;
-  while (store->collection_exists(coll_t(temp_name)))
-    temp_name = "_" + temp_name;
-  coll_t temp(temp_name);
-  
-  ObjectStore::Transaction t;
-  t.collection_rename(cid, temp);
-  t.create_collection(cid);
-  for (vector<hobject_t>::iterator obj = objects.begin();
-       obj != objects.end();
-       ++obj) {
-    t.collection_add(cid, temp, *obj);
-    t.collection_remove(temp, *obj);
-  }
-  for (map<string,bufferptr>::iterator i = aset.begin();
-       i != aset.end();
-       ++i) {
-    bufferlist bl;
-    bl.append(i->second);
-    t.collection_setattr(cid, i->first, bl);
-  }
-  t.remove_collection(temp);
-  r = store->apply_transaction(t);
-  if (r < 0)
-    return r;
-  store->sync_and_flush();
-  store->sync();
-  return 0;
-}
-
-int main(int argc, const char **argv) {
-  vector<const char*> args;
-  argv_to_vec(argc, argv, args);
-  env_to_vec(args);
-
-  global_init(args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
-  common_init_finish(g_ceph_context);
-
-  // args
-  if (args.size() != 2) 
-    usage();
-
-  boost::scoped_ptr<ObjectStore> store(new FileStore(args[0], args[1]));
-  g_ceph_context->_conf->filestore_update_collections = true;;
-  g_ceph_context->_conf->debug_filestore = 20;
-  int r = store->mount();
-  if (r < 0)
-    return -r;
-
-  uint32_t version;
-  r = store->version_stamp_is_valid(&version);
-  if (r < 0)
-    return -r;
-  if (r == -1) {
-    cerr << "FileStore is up to date." << std::endl;
-    store->umount();
-    return 0;
-  } else {
-    cerr << "FileStore is old at version " << version << ".  Updating..." 
-        << std::endl;
-  }
-
-  cerr << "Getting collections" << std::endl;
-  vector<coll_t> collections;
-  r = store->list_collections(collections);
-  if (r < 0)
-    return -r;
-
-  cerr << collections.size() << " to process." << std::endl;
-  int processed = 0;
-  for (vector<coll_t>::iterator i = collections.begin();
-       i != collections.end();
-       ++i, ++processed) {
-    cerr << processed << "/" << collections.size() << " processed" << std::endl;
-    uint32_t collection_version;
-    r = store->collection_version_current(*i, &collection_version);
-    if (r < 0) {
-      return r;
-    } else if (r == 1) {
-      cerr << "Collection " << *i << " is up to date" << std::endl;
-    } else {
-      cerr << "Updating collection " << *i << " current version is " << collection_version << std::endl;
-      r = convert_collection(store.get(), *i);
-      if (r < 0)
-       return r;
-      cerr << "collection " << *i << " updated" << std::endl;
-    }
-  }
-  cerr << "All collections up to date, updating version stamp..." << std::endl;
-  r = store->update_version_stamp();
-  if (r < 0)
-    return r;
-  store->sync_and_flush();
-  store->sync();
-  cerr << "Version stamp updated, done!" << std::endl;
-  store->umount();
-  return 0;
-}
index cffdcbb0437a6858bb5acea1e203eb245dee510f..1c6bd3991c57ca3c9ce17789a6361388d2baf92a 100644 (file)
@@ -91,6 +91,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <signal.h>
+#include <boost/scoped_ptr.hpp>
 
 #ifdef DARWIN
 #include <sys/param.h>
@@ -148,6 +149,108 @@ create_object_store(const std::string &dev, const std::string &jdev)
 #undef dout_prefix
 #define dout_prefix *_dout
 
+static int convert_collection(ObjectStore *store, coll_t cid) {
+  vector<hobject_t> objects;
+  int r = store->collection_list(cid, objects);
+  if (r < 0)
+    return r;
+  string temp_name("temp");
+  map<string, bufferptr> aset;
+  r = store->collection_getattrs(cid, aset);
+  if (r < 0)
+    return r;
+  while (store->collection_exists(coll_t(temp_name)))
+    temp_name = "_" + temp_name;
+  coll_t temp(temp_name);
+  
+  ObjectStore::Transaction t;
+  t.collection_rename(cid, temp);
+  t.create_collection(cid);
+  for (vector<hobject_t>::iterator obj = objects.begin();
+       obj != objects.end();
+       ++obj) {
+    t.collection_add(cid, temp, *obj);
+    t.collection_remove(temp, *obj);
+  }
+  for (map<string,bufferptr>::iterator i = aset.begin();
+       i != aset.end();
+       ++i) {
+    bufferlist bl;
+    bl.append(i->second);
+    t.collection_setattr(cid, i->first, bl);
+  }
+  t.remove_collection(temp);
+  r = store->apply_transaction(t);
+  if (r < 0)
+    return r;
+  store->sync_and_flush();
+  store->sync();
+  return 0;
+}
+
+static int do_convertfs(ObjectStore *store) {
+  g_ceph_context->_conf->filestore_update_collections = true;
+  int r = store->mount();
+  if (r < 0)
+    return -r;
+
+  uint32_t version;
+  r = store->version_stamp_is_valid(&version);
+  if (r < 0)
+    return -r;
+  if (r == 1) {
+    derr << "FileStore is up to date." << dendl;
+    store->umount();
+    return 0;
+  } else {
+    derr << "FileStore is old at version " << version << ".  Updating..." 
+        << dendl;
+  }
+
+  derr << "Getting collections" << dendl;
+  vector<coll_t> collections;
+  r = store->list_collections(collections);
+  if (r < 0)
+    return -r;
+
+  derr << collections.size() << " to process." << dendl;
+  int processed = 0;
+  for (vector<coll_t>::iterator i = collections.begin();
+       i != collections.end();
+       ++i, ++processed) {
+    derr << processed << "/" << collections.size() << " processed" << dendl;
+    uint32_t collection_version;
+    r = store->collection_version_current(*i, &collection_version);
+    if (r < 0) {
+      return r;
+    } else if (r == 1) {
+      derr << "Collection " << *i << " is up to date" << dendl;
+    } else {
+      derr << "Updating collection " << *i << " current version is " 
+          << collection_version << dendl;
+      r = convert_collection(store, *i);
+      if (r < 0)
+       return r;
+      derr << "collection " << *i << " updated" << dendl;
+    }
+  }
+  cerr << "All collections up to date, updating version stamp..." << std::endl;
+  r = store->update_version_stamp();
+  if (r < 0)
+    return r;
+  store->sync_and_flush();
+  store->sync();
+  cerr << "Version stamp updated, done!" << std::endl;
+  store->umount();
+  return 0;
+}
+
+int OSD::convertfs(const std::string &dev, const std::string &jdev)
+{
+  boost::scoped_ptr<ObjectStore> store(new FileStore(dev, jdev));
+  return do_convertfs(store.get());
+}
+
 int OSD::mkfs(const std::string &dev, const std::string &jdev, ceph_fsid_t fsid, int whoami)
 {
   int ret;
index 135834d53bdd4c547ceace47ec791ece8eef9695..29c78a6f2d4ca52063830d945b976add89742460 100644 (file)
@@ -973,6 +973,7 @@ protected:
   // static bits
   static int find_osd_dev(char *result, int whoami);
   static ObjectStore *create_object_store(const std::string &dev, const std::string &jdev);
+  static int convertfs(const std::string &dev, const std::string &jdev);
   static int mkfs(const std::string &dev, const std::string &jdev,
                  ceph_fsid_t fsid, int whoami);
   static int mkjournal(const std::string &dev, const std::string &jdev);