From f3dab446fc8e58b3b3d9334b8c38722e73881b9e Mon Sep 17 00:00:00 2001 From: David Zafman Date: Tue, 18 Nov 2014 13:00:15 -0800 Subject: [PATCH] ceph_objectstore_tool: Add feature called set-allow-sharded-objects Uses --op set-allow-sharded-objects option This operation will be rejected if on the target OSD's osdmap there is at least one OSD which does not support ERASURE CODES. Prompt the user that they could import if sharded state allowed Prompt the user to use new feature if sharded state found inconsistent Fixes: #10077 Signed-off-by: David Zafman --- src/tools/ceph_objectstore_tool.cc | 93 ++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 2d3d229b27463..684d7af151df0 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -55,6 +55,7 @@ enum { //#define INTERNAL_TEST //#define INTERNAL_TEST2 +//#define INTERNAL_TEST3 #ifdef INTERNAL_TEST CompatSet get_test_compat_set() { @@ -1384,8 +1385,17 @@ int do_import(ObjectStore *store, OSDSuperblock& sb) pgb.superblock.compat_features.incompat.remove(CEPH_OSD_FEATURE_INCOMPAT_SHARDS); if (sb.compat_features.compare(pgb.superblock.compat_features) == -1) { - cerr << "Export has incompatible features set " - << pgb.superblock.compat_features << std::endl; + CompatSet unsupported = sb.compat_features.unsupported(pgb.superblock.compat_features); + + cerr << "Export has incompatible features set " << unsupported << std::endl; + + // If shards setting the issue, then inform user what they can do about it. + if (unsupported.incompat.contains(CEPH_OSD_FEATURE_INCOMPAT_SHARDS)) { + cerr << std::endl; + cerr << "OSD requires sharding to be enabled" << std::endl; + cerr << std::endl; + cerr << "If you wish to import, first do 'ceph_objectstore_tool...--op set-allow-sharded-objects'" << std::endl; + } return 1; } @@ -1836,7 +1846,7 @@ int main(int argc, char **argv) ("pgid", po::value(&pgidstr), "PG id, mandatory except for import, list-lost, fix-lost") ("op", po::value(&op), - "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals]") + "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects]") ("file", po::value(&file), "path of file to export or import") ("debug", "Enable diagnostic output to stderr") @@ -1942,7 +1952,7 @@ int main(int argc, char **argv) usage(desc); } if (op != "import" && op != "list-lost" && op != "fix-lost" - && op != "list-pgs" && !vm.count("pgid")) { + && op != "list-pgs" && op != "set-allow-sharded-objects" && !vm.count("pgid")) { cerr << "Must provide pgid" << std::endl; usage(desc); } @@ -2125,6 +2135,79 @@ int main(int argc, char **argv) goto out; } + if (op == "set-allow-sharded-objects") { + // This could only happen if we backport changes to an older release + if (!supported.incompat.contains(CEPH_OSD_FEATURE_INCOMPAT_SHARDS)) { + cerr << "Can't enable sharded objects in this release" << std::endl; + ret = 1; + goto out; + } + if (superblock.compat_features.incompat.contains(CEPH_OSD_FEATURE_INCOMPAT_SHARDS) && + fs_sharded_objects) { + cerr << "Sharded objects already fully enabled" << std::endl; + ret = 0; + goto out; + } + OSDMap curmap; + ret = get_osdmap(fs, superblock.current_epoch, curmap); + if (ret) { + cerr << "Can't find local OSDMap" << std::endl; + goto out; + } + + // Based on OSDMonitor::check_cluster_features() + // XXX: The up state of osds in the last map isn't + // as important from a non-running osd. I'm using + // get_all_osds() instead. An osd which was never + // upgraded and never removed would be flagged here. + stringstream unsupported_ss; + int unsupported_count = 0; + uint64_t features = CEPH_FEATURE_OSD_ERASURE_CODES; + set all_osds; + curmap.get_all_osds(all_osds); + for (set::iterator it = all_osds.begin(); + it != all_osds.end(); ++it) { + const osd_xinfo_t &xi = curmap.get_xinfo(*it); +#ifdef INTERNAL_TEST3 + // Force one of the OSDs to not have support for erasure codes + if (unsupported_count == 0) + ((osd_xinfo_t &)xi).features &= ~features; +#endif + if ((xi.features & features) != features) { + if (unsupported_count > 0) + unsupported_ss << ", "; + unsupported_ss << "osd." << *it; + unsupported_count ++; + } + } + + if (unsupported_count > 0) { + cerr << "ERASURE_CODES feature unsupported by: " + << unsupported_ss.str() << std::endl; + ret = 1; + goto out; + } + + superblock.compat_features.incompat.insert(CEPH_OSD_FEATURE_INCOMPAT_SHARDS); + ObjectStore::Transaction t; + bufferlist bl; + ::encode(superblock, bl); + t.write(META_COLL, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl); + r = fs->apply_transaction(t); + if (r < 0) { + cerr << "Error writing OSD superblock: " << cpp_strerror(r) << std::endl; + ret = 1; + goto out; + } + + fs->set_allow_sharded_objects(); + + cout << "Enabled on-disk sharded objects" << std::endl; + + ret = 0; + goto out; + } + // If there was a crash as an OSD was transitioning to sharded objects // and hadn't completed a set_allow_sharded_objects(). // This utility does not want to attempt to finish that transition. @@ -2135,6 +2218,8 @@ int main(int argc, char **argv) cerr << "FileStore sharded but OSD not set, Corruption?" << std::endl; else cerr << "Found incomplete transition to sharded objects" << std::endl; + cerr << std::endl; + cerr << "Use --op set-allow-sharded-objects to repair" << std::endl; ret = EINVAL; goto out; } -- 2.39.5