summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoao Eduardo Luis <joao.luis@inktank.com>2013-04-19 17:28:37 +0100
committerJoao Eduardo Luis <joao.luis@inktank.com>2013-04-22 22:55:18 +0100
commit1164345a6ef51315a7b960feaea6a35fc4b7e571 (patch)
tree9ecc184a3c28bae30715075f19448967e042fe73
parent9ba32404aebb9c223ad3254d463df9b47352753f (diff)
downloadceph-1164345a6ef51315a7b960feaea6a35fc4b7e571.tar.gz
ceph-mon: Attempt to obtain monmap from several possible sources
In order of interest/priority: - our latest monmap version - a backup monmap version created during sync start, if the store appears to be in a post-aborted sync state - a mkfs monmap version If none of these are found, we should go ahead and try to build a monmap from ceph.conf to join an existing cluster. Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
-rw-r--r--src/ceph_mon.cc77
1 files changed, 58 insertions, 19 deletions
diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc
index 72354e18876..01072728db2 100644
--- a/src/ceph_mon.cc
+++ b/src/ceph_mon.cc
@@ -52,6 +52,53 @@ void handle_mon_signal(int signum)
mon->handle_signal(signum);
}
+
+int obtain_monmap(MonitorDBStore &store, bufferlist &bl)
+{
+ dout(10) << __func__ << dendl;
+ /*
+ * the monmap may be in one of three places:
+ * 'monmap:<latest_version_no>' - the monmap we'd really like to have
+ * 'mon_sync:latest_monmap' - last monmap backed up for the last sync
+ * 'mkfs:monmap' - a monmap resulting from mkfs
+ */
+
+ if (store.exists("monmap", "last_committed")) {
+ version_t latest_ver = store.get("monmap", "last_committed");
+ if (store.exists("monmap", latest_ver)) {
+ int err = store.get("monmap", latest_ver, bl);
+ assert(err == 0);
+ assert(bl.length() > 0);
+ dout(10) << __func__ << " read last committed monmap ver "
+ << latest_ver << dendl;
+ return 0;
+ }
+ }
+
+ if (store.exists("mon_sync", "in_sync")) {
+ dout(10) << __func__ << " detected aborted sync" << dendl;
+ if (store.exists("mon_sync", "latest_monmap")) {
+ int err = store.get("mon_sync", "latest_monmap", bl);
+ assert(err == 0);
+ assert(bl.length() > 0);
+ dout(10) << __func__ << " read backup monmap" << dendl;
+ return 0;
+ }
+ }
+
+ if (store.exists("mkfs", "monmap")) {
+ dout(10) << __func__ << " found mkfs monmap" << dendl;
+ int err = store.get("mkfs", "monmap", bl);
+ assert(err == 0);
+ assert(bl.length() > 0);
+ return 0;
+ }
+
+ derr << __func__ << " unable to find a monmap" << dendl;
+ return -ENOENT;
+}
+
+
void usage()
{
cerr << "usage: ceph-mon -i monid [--mon-data=pathtodata] [flags]" << std::endl;
@@ -301,30 +348,22 @@ int main(int argc, const char **argv)
exit(0);
}
-
// monmap?
MonMap monmap;
{
+ // note that even if we don't find a viable monmap, we should go ahead
+ // and try to build it up in the next if-else block.
bufferlist mapbl;
- bufferlist latest;
- store.get("monmap", "latest", latest);
- if (latest.length() > 0) {
- bufferlist::iterator p = latest.begin();
- version_t v;
- ::decode(v, p);
- ::decode(mapbl, p);
- } else {
- store.get("mkfs", "monmap", mapbl);
- if (mapbl.length() == 0) {
- cerr << "mon fs missing 'monmap/latest' and 'mkfs/monmap'" << std::endl;
- exit(1);
+ int err = obtain_monmap(store, mapbl);
+ if (err >= 0) {
+ try {
+ monmap.decode(mapbl);
+ } catch (const buffer::error& e) {
+ cerr << "can't decode monmap: " << e.what() << std::endl;
}
- }
- try {
- monmap.decode(mapbl);
- }
- catch (const buffer::error& e) {
- cerr << "can't decode monmap: " << e.what() << std::endl;
+ } else {
+ std::cerr << "unable to obtain a monmap: "
+ << cpp_strerror(err) << std::endl;
}
}