2007-10-29 19:05:24 +00:00
|
|
|
// -*- 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 <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-02-22 16:38:45 +00:00
|
|
|
#include "common/config.h"
|
2012-01-23 14:18:53 +00:00
|
|
|
#include "include/ceph_features.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
|
|
|
#include "mon/MonMap.h"
|
|
|
|
#include "mon/Monitor.h"
|
2008-03-10 23:23:41 +00:00
|
|
|
#include "mon/MonitorStore.h"
|
2011-11-11 18:05:36 +00:00
|
|
|
#include "mon/MonClient.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2012-03-14 23:33:39 +00:00
|
|
|
#include "msg/Messenger.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2010-01-14 19:12:23 +00:00
|
|
|
#include "include/CompatSet.h"
|
2008-11-21 00:59:08 +00:00
|
|
|
|
2011-02-20 17:18:03 +00:00
|
|
|
#include "common/ceph_argparse.h"
|
2011-11-22 17:53:52 +00:00
|
|
|
#include "common/pick_address.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
#include "common/Timer.h"
|
2011-11-11 18:05:36 +00:00
|
|
|
#include "common/errno.h"
|
|
|
|
|
2011-06-17 03:15:24 +00:00
|
|
|
#include "global/global_init.h"
|
2012-02-12 00:38:06 +00:00
|
|
|
#include "global/signal_handler.h"
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2012-06-06 23:57:31 +00:00
|
|
|
#include "include/assert.h"
|
|
|
|
|
2012-03-27 17:41:12 +00:00
|
|
|
#define dout_subsys ceph_subsys_mon
|
|
|
|
|
2012-02-12 00:38:06 +00:00
|
|
|
Monitor *mon = NULL;
|
|
|
|
|
|
|
|
void handle_mon_signal(int signum)
|
|
|
|
{
|
|
|
|
if (mon)
|
|
|
|
mon->handle_signal(signum);
|
|
|
|
}
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2011-09-21 23:28:43 +00:00
|
|
|
cerr << "usage: ceph-mon -i monid [--mon-data=pathtodata] [flags]" << std::endl;
|
2009-03-10 22:22:52 +00:00
|
|
|
cerr << " --debug_mon n\n";
|
|
|
|
cerr << " debug monitor level (e.g. 10)\n";
|
2010-05-24 22:28:59 +00:00
|
|
|
cerr << " --mkfs\n";
|
|
|
|
cerr << " build fresh monitor fs\n";
|
2009-03-10 22:22:52 +00:00
|
|
|
generic_server_usage();
|
2008-03-10 23:23:41 +00:00
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2008-01-01 22:04:31 +00:00
|
|
|
int main(int argc, const char **argv)
|
2007-10-29 19:05:24 +00:00
|
|
|
{
|
2008-03-10 23:23:41 +00:00
|
|
|
int err;
|
2010-05-24 22:28:59 +00:00
|
|
|
|
|
|
|
bool mkfs = false;
|
2011-09-06 22:12:33 +00:00
|
|
|
std::string osdmapfn, inject_monmap;
|
2008-03-10 23:23:41 +00:00
|
|
|
|
2008-01-01 22:04:31 +00:00
|
|
|
vector<const char*> args;
|
2007-10-29 19:05:24 +00:00
|
|
|
argv_to_vec(argc, argv, args);
|
2008-11-05 22:54:13 +00:00
|
|
|
env_to_vec(args);
|
2010-07-01 15:55:52 +00:00
|
|
|
|
2012-03-12 20:15:50 +00:00
|
|
|
global_init(NULL, args, CEPH_ENTITY_TYPE_MON, CODE_ENVIRONMENT_DAEMON, 0);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2011-11-12 05:02:23 +00:00
|
|
|
uuid_d fsid;
|
2011-09-06 22:12:33 +00:00
|
|
|
std::string val;
|
|
|
|
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
|
|
|
|
if (ceph_argparse_double_dash(args, i)) {
|
|
|
|
break;
|
|
|
|
} else if (ceph_argparse_flag(args, i, "-h", "--help", (char*)NULL)) {
|
2010-05-24 22:28:59 +00:00
|
|
|
usage();
|
2011-09-06 22:12:33 +00:00
|
|
|
exit(0);
|
|
|
|
} else if (ceph_argparse_flag(args, i, "--mkfs", (char*)NULL)) {
|
|
|
|
mkfs = true;
|
|
|
|
} else if (ceph_argparse_witharg(args, i, &val, "--osdmap", (char*)NULL)) {
|
|
|
|
osdmapfn = val;
|
|
|
|
} else if (ceph_argparse_witharg(args, i, &val, "--inject_monmap", (char*)NULL)) {
|
|
|
|
inject_monmap = val;
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!args.empty()) {
|
2011-11-22 17:53:52 +00:00
|
|
|
cerr << "too many arguments: " << args << std::endl;
|
2011-09-06 22:12:33 +00:00
|
|
|
usage();
|
2010-05-24 22:28:59 +00:00
|
|
|
}
|
|
|
|
|
2011-06-07 17:38:54 +00:00
|
|
|
if (g_conf->mon_data.empty()) {
|
2009-03-11 21:58:58 +00:00
|
|
|
cerr << "must specify '--mon-data=foo' data path" << std::endl;
|
2008-03-10 23:23:41 +00:00
|
|
|
usage();
|
2009-03-11 21:58:58 +00:00
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2012-08-20 20:12:26 +00:00
|
|
|
if (g_conf->name.get_id().empty()) {
|
|
|
|
cerr << "must specify id (--id <id> or --name mon.<id>)" << std::endl;
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2010-05-24 22:28:59 +00:00
|
|
|
// -- mkfs --
|
|
|
|
if (mkfs) {
|
2011-11-23 00:28:42 +00:00
|
|
|
// resolve public_network -> public_addr
|
|
|
|
pick_addresses(g_ceph_context);
|
|
|
|
|
2011-06-21 19:28:16 +00:00
|
|
|
common_init_finish(g_ceph_context);
|
2010-05-24 22:28:59 +00:00
|
|
|
|
|
|
|
bufferlist monmapbl, osdmapbl;
|
2011-06-10 21:30:17 +00:00
|
|
|
std::string error;
|
2011-11-08 04:52:50 +00:00
|
|
|
MonMap monmap;
|
2011-11-11 18:05:36 +00:00
|
|
|
|
|
|
|
// load or generate monmap
|
|
|
|
if (g_conf->monmap.length()) {
|
|
|
|
int err = monmapbl.read_file(g_conf->monmap.c_str(), &error);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << argv[0] << ": error reading " << g_conf->monmap << ": " << error << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
monmap.decode(monmapbl);
|
2012-05-18 16:38:52 +00:00
|
|
|
|
|
|
|
// always mark seed/mkfs monmap as epoch 0
|
|
|
|
monmap.set_epoch(0);
|
2011-11-11 18:05:36 +00:00
|
|
|
}
|
|
|
|
catch (const buffer::error& e) {
|
|
|
|
cerr << argv[0] << ": error decoding monmap " << g_conf->monmap << ": " << e.what() << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
2012-05-18 17:38:26 +00:00
|
|
|
int err = monmap.build_initial(g_ceph_context, cerr);
|
2011-11-11 18:05:36 +00:00
|
|
|
if (err < 0) {
|
2012-05-21 22:07:42 +00:00
|
|
|
cerr << argv[0] << ": warning: no initial monitors; must use admin socket to feed hints" << std::endl;
|
2011-11-11 18:05:36 +00:00
|
|
|
}
|
2011-11-28 00:10:46 +00:00
|
|
|
|
2011-11-22 22:53:45 +00:00
|
|
|
// am i part of the initial quorum?
|
|
|
|
if (monmap.contains(g_conf->name.get_id())) {
|
|
|
|
// hmm, make sure the ip listed exists on the current host?
|
|
|
|
// maybe later.
|
|
|
|
} else if (!g_conf->public_addr.is_blank_ip()) {
|
2011-11-23 00:22:07 +00:00
|
|
|
entity_addr_t a = g_conf->public_addr;
|
|
|
|
if (a.get_port() == 0)
|
|
|
|
a.set_port(CEPH_MON_PORT);
|
|
|
|
if (monmap.contains(a)) {
|
2011-11-22 22:53:45 +00:00
|
|
|
string name;
|
2011-11-23 00:22:07 +00:00
|
|
|
monmap.get_addr_name(a, name);
|
2011-11-22 22:53:45 +00:00
|
|
|
monmap.rename(name, g_conf->name.get_id());
|
2011-11-23 00:22:07 +00:00
|
|
|
cout << argv[0] << ": renaming mon." << name << " " << a
|
|
|
|
<< " to mon." << g_conf->name.get_id() << std::endl;
|
2011-11-22 22:53:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// is a local address listed without a name? if so, name myself.
|
2011-11-28 00:10:46 +00:00
|
|
|
list<entity_addr_t> ls;
|
|
|
|
monmap.list_addrs(ls);
|
|
|
|
entity_addr_t local;
|
2011-11-22 22:53:45 +00:00
|
|
|
|
2011-11-28 00:10:46 +00:00
|
|
|
if (have_local_addr(g_ceph_context, ls, &local)) {
|
|
|
|
string name;
|
|
|
|
monmap.get_addr_name(local, name);
|
|
|
|
|
|
|
|
if (name.find("noname-") == 0) {
|
|
|
|
cout << argv[0] << ": mon." << name << " " << local
|
|
|
|
<< " is local, renaming to mon." << g_conf->name.get_id() << std::endl;
|
|
|
|
monmap.rename(name, g_conf->name.get_id());
|
|
|
|
} else {
|
|
|
|
cout << argv[0] << ": mon." << name << " " << local
|
|
|
|
<< " is local, but not 'noname-' + something; not assuming it's me" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2011-11-22 22:53:45 +00:00
|
|
|
}
|
2011-11-11 18:05:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 05:29:08 +00:00
|
|
|
if (!g_conf->fsid.is_zero()) {
|
|
|
|
monmap.fsid = g_conf->fsid;
|
|
|
|
cout << argv[0] << ": set fsid to " << g_conf->fsid << std::endl;
|
2011-11-12 05:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (monmap.fsid.is_zero()) {
|
2011-11-12 21:41:59 +00:00
|
|
|
cerr << argv[0] << ": generated monmap has no fsid; use '--fsid <uuid>'" << std::endl;
|
2011-11-12 05:02:23 +00:00
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
2011-11-22 22:53:45 +00:00
|
|
|
//monmap.print(cout);
|
|
|
|
|
2011-11-11 18:05:36 +00:00
|
|
|
// osdmap
|
2011-11-12 21:41:59 +00:00
|
|
|
if (osdmapfn.length()) {
|
|
|
|
err = osdmapbl.read_file(osdmapfn.c_str(), &error);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << argv[0] << ": error reading " << osdmapfn << ": "
|
|
|
|
<< error << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-06-10 21:30:17 +00:00
|
|
|
}
|
2010-05-24 22:28:59 +00:00
|
|
|
|
|
|
|
// go
|
2011-06-07 17:38:54 +00:00
|
|
|
MonitorStore store(g_conf->mon_data);
|
2011-06-21 19:28:16 +00:00
|
|
|
Monitor mon(g_ceph_context, g_conf->name.get_id(), &store, 0, &monmap);
|
2012-02-11 17:49:42 +00:00
|
|
|
int r = mon.mkfs(osdmapbl);
|
|
|
|
if (r < 0) {
|
|
|
|
cerr << argv[0] << ": error creating monfs: " << cpp_strerror(r) << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-06-07 17:38:54 +00:00
|
|
|
cout << argv[0] << ": created monfs at " << g_conf->mon_data
|
|
|
|
<< " for " << g_conf->name << std::endl;
|
2010-05-24 22:28:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-07 17:38:54 +00:00
|
|
|
MonitorStore store(g_conf->mon_data);
|
2008-03-10 23:23:41 +00:00
|
|
|
err = store.mount();
|
|
|
|
if (err < 0) {
|
2011-11-11 18:05:36 +00:00
|
|
|
cerr << "problem opening monitor store in " << g_conf->mon_data << ": " << cpp_strerror(err) << std::endl;
|
2008-03-10 23:23:41 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-11-21 00:59:08 +00:00
|
|
|
bufferlist magicbl;
|
2010-08-25 21:41:29 +00:00
|
|
|
err = store.get_bl_ss(magicbl, "magic", 0);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << "unable to read magic from mon data.. did you run mkcephfs?" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-28 20:45:55 +00:00
|
|
|
string magic(magicbl.c_str(), magicbl.length()-1); // ignore trailing \n
|
2008-11-21 00:59:08 +00:00
|
|
|
if (strcmp(magic.c_str(), CEPH_MON_ONDISK_MAGIC)) {
|
|
|
|
cerr << "mon fs magic '" << magic << "' != current '" << CEPH_MON_ONDISK_MAGIC << "'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-09-12 23:05:53 +00:00
|
|
|
err = Monitor::check_features(&store);
|
|
|
|
if (err < 0) {
|
|
|
|
cerr << "error checking features: " << cpp_strerror(err) << std::endl;
|
2010-01-14 19:12:23 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-29 18:58:13 +00:00
|
|
|
// inject new monmap?
|
2011-09-06 22:12:33 +00:00
|
|
|
if (!inject_monmap.empty()) {
|
2011-03-29 18:58:13 +00:00
|
|
|
bufferlist bl;
|
2011-06-10 21:30:17 +00:00
|
|
|
std::string error;
|
2011-09-06 22:12:33 +00:00
|
|
|
int r = bl.read_file(inject_monmap.c_str(), &error);
|
2011-03-29 18:58:13 +00:00
|
|
|
if (r) {
|
2011-06-10 21:30:17 +00:00
|
|
|
cerr << "unable to read monmap from " << inject_monmap << ": "
|
|
|
|
<< error << std::endl;
|
2011-03-29 18:58:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get next version
|
|
|
|
version_t v = store.get_int("monmap", "last_committed");
|
|
|
|
cout << "last committed monmap epoch is " << v << ", injected map will be " << (v+1) << std::endl;
|
|
|
|
v++;
|
|
|
|
|
|
|
|
// set the version
|
2011-11-08 04:52:50 +00:00
|
|
|
MonMap tmp;
|
2011-03-29 18:58:13 +00:00
|
|
|
tmp.decode(bl);
|
|
|
|
if (tmp.get_epoch() != v) {
|
|
|
|
cout << "changing monmap epoch from " << tmp.get_epoch() << " to " << v << std::endl;
|
|
|
|
tmp.set_epoch(v);
|
|
|
|
}
|
|
|
|
bufferlist mapbl;
|
2012-05-16 23:04:19 +00:00
|
|
|
tmp.encode(mapbl, CEPH_FEATURES_ALL);
|
2011-03-29 18:58:13 +00:00
|
|
|
bufferlist final;
|
|
|
|
::encode(v, final);
|
|
|
|
::encode(mapbl, final);
|
|
|
|
|
|
|
|
// save it
|
|
|
|
store.put_bl_sn(mapbl, "monmap", v);
|
|
|
|
store.put_bl_ss(final, "monmap", "latest");
|
|
|
|
store.put_int(v, "monmap", "last_committed");
|
|
|
|
|
|
|
|
cout << "done." << std::endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
// monmap?
|
2011-11-08 04:52:50 +00:00
|
|
|
MonMap monmap;
|
2009-10-11 04:26:53 +00:00
|
|
|
{
|
2011-11-11 18:15:23 +00:00
|
|
|
bufferlist mapbl;
|
2009-10-11 04:26:53 +00:00
|
|
|
bufferlist latest;
|
2011-11-11 18:15:23 +00:00
|
|
|
store.get_bl_ss(latest, "monmap", "latest");
|
|
|
|
if (latest.length() > 0) {
|
|
|
|
bufferlist::iterator p = latest.begin();
|
|
|
|
version_t v;
|
|
|
|
::decode(v, p);
|
|
|
|
::decode(mapbl, p);
|
|
|
|
} else {
|
|
|
|
store.get_bl_ss(mapbl, "mkfs", "monmap");
|
|
|
|
if (mapbl.length() == 0) {
|
|
|
|
cerr << "mon fs missing 'monmap/latest' and 'mkfs/monmap'" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
monmap.decode(mapbl);
|
|
|
|
}
|
|
|
|
catch (const buffer::error& e) {
|
|
|
|
cerr << "can't decode monmap: " << e.what() << std::endl;
|
2009-10-11 04:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2011-11-22 17:53:52 +00:00
|
|
|
// this is what i will bind to
|
|
|
|
entity_addr_t ipaddr;
|
|
|
|
|
|
|
|
if (monmap.contains(g_conf->name.get_id())) {
|
|
|
|
ipaddr = monmap.get_addr(g_conf->name.get_id());
|
|
|
|
|
|
|
|
// print helpful warning if the conf file doesn't match
|
|
|
|
entity_addr_t conf_addr;
|
|
|
|
std::vector <std::string> my_sections;
|
|
|
|
g_conf->get_my_sections(my_sections);
|
|
|
|
std::string mon_addr_str;
|
|
|
|
if (g_conf->get_val_from_conf_file(my_sections, "mon addr",
|
|
|
|
mon_addr_str, true) == 0) {
|
|
|
|
if (conf_addr.parse(mon_addr_str.c_str()) && (ipaddr != conf_addr)) {
|
|
|
|
cerr << "WARNING: 'mon addr' config option " << conf_addr
|
|
|
|
<< " does not match monmap file" << std::endl
|
|
|
|
<< " continuing with monmap configuration" << std::endl;
|
|
|
|
}
|
2011-03-29 23:05:12 +00:00
|
|
|
}
|
2011-11-22 17:53:52 +00:00
|
|
|
} else {
|
|
|
|
dout(0) << g_conf->name << " does not exist in monmap, will attempt to join an existing cluster" << dendl;
|
|
|
|
|
|
|
|
pick_addresses(g_ceph_context);
|
2011-12-19 16:03:59 +00:00
|
|
|
if (!g_conf->public_addr.is_blank_ip()) {
|
|
|
|
ipaddr = g_conf->public_addr;
|
|
|
|
} else {
|
|
|
|
MonMap tmpmap;
|
2012-05-18 17:38:26 +00:00
|
|
|
int err = tmpmap.build_initial(g_ceph_context, cerr);
|
2011-12-19 16:03:59 +00:00
|
|
|
if (err < 0) {
|
|
|
|
cerr << argv[0] << ": error generating initial monmap: " << cpp_strerror(err) << std::endl;
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (tmpmap.contains(g_conf->name.get_id())) {
|
|
|
|
ipaddr = tmpmap.get_addr(g_conf->name.get_id());
|
|
|
|
} else {
|
|
|
|
derr << "no public_addr or public_network specified, and " << g_conf->name
|
|
|
|
<< " not present in monmap or ceph.conf" << dendl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-11-22 22:53:45 +00:00
|
|
|
}
|
2011-03-29 20:42:26 +00:00
|
|
|
}
|
2009-03-24 23:44:07 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
// bind
|
2011-06-07 17:38:54 +00:00
|
|
|
int rank = monmap.get_rank(g_conf->name.get_id());
|
2012-03-14 23:33:39 +00:00
|
|
|
Messenger *messenger = Messenger::create(g_ceph_context,
|
|
|
|
entity_name_t::MON(rank),
|
2012-04-30 23:31:21 +00:00
|
|
|
"mon",
|
2012-03-14 23:33:39 +00:00
|
|
|
0);
|
2012-03-01 23:14:52 +00:00
|
|
|
messenger->set_cluster_protocol(CEPH_MON_PROTOCOL);
|
2012-03-02 02:31:49 +00:00
|
|
|
messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
|
|
|
|
|
|
|
|
uint64_t supported =
|
|
|
|
CEPH_FEATURE_UID |
|
|
|
|
CEPH_FEATURE_NOSRCADDR |
|
|
|
|
CEPH_FEATURE_MONCLOCKCHECK |
|
|
|
|
CEPH_FEATURE_PGID64;
|
|
|
|
messenger->set_default_policy(Messenger::Policy::stateless_server(supported, 0));
|
|
|
|
messenger->set_policy(entity_name_t::TYPE_MON,
|
msg/Pipe: conditionally detect session reset
Lossless peers (osd<->osd, mds<->mds, mon<->mon) never reset sessions
to each other. In the osd and mds cases, there is no need to check for
session resets. More significantly, these checks can trigger with an
unfortunately sequence of socket failures. In particular,
- A sends connect request to B
- B accepts, increments connect_seq, then has a socket failure
before telling A
- A reconnects, stil with connect_seq == 0
- B sees connect_seq == 0 and thinks there was a reset
This warrants a closer look in the fs client <-> mds case, but for now,
in the cluster-internal communications, it is moot, since reset
detection is unnecessary.
In the monitor case: we do need to check with resets because the peers
reuse the same entity_addr_t's (nonce==0), which means that a daemon
restart is effectively a reset. In that case, use a different policy
that continues to check for resets.
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
2012-08-23 20:26:32 +00:00
|
|
|
Messenger::Policy::lossless_peer_reuse(supported,
|
|
|
|
CEPH_FEATURE_UID |
|
|
|
|
CEPH_FEATURE_PGID64));
|
2012-03-02 02:31:49 +00:00
|
|
|
messenger->set_policy(entity_name_t::TYPE_OSD,
|
|
|
|
Messenger::Policy::stateless_server(supported,
|
|
|
|
CEPH_FEATURE_PGID64 |
|
|
|
|
CEPH_FEATURE_OSDENC));
|
2012-06-07 02:19:59 +00:00
|
|
|
messenger->set_policy(entity_name_t::TYPE_CLIENT,
|
|
|
|
Messenger::Policy::stateless_server(supported, 0));
|
|
|
|
messenger->set_policy(entity_name_t::TYPE_MDS,
|
|
|
|
Messenger::Policy::stateless_server(supported, 0));
|
|
|
|
|
2010-06-08 22:17:08 +00:00
|
|
|
|
2012-06-01 16:44:09 +00:00
|
|
|
// throttle client traffic
|
|
|
|
Throttle client_throttler(g_ceph_context, "mon_client_bytes",
|
|
|
|
g_conf->mon_client_bytes);
|
|
|
|
messenger->set_policy_throttler(entity_name_t::TYPE_CLIENT, &client_throttler);
|
2012-08-14 22:07:06 +00:00
|
|
|
|
|
|
|
// throttle daemon traffic
|
|
|
|
// NOTE: actual usage on the leader may multiply by the number of
|
|
|
|
// monitors if they forward large update messages from daemons.
|
|
|
|
Throttle daemon_throttler(g_ceph_context, "mon_daemon_bytes",
|
|
|
|
g_conf->mon_daemon_bytes);
|
|
|
|
messenger->set_policy_throttler(entity_name_t::TYPE_OSD, &daemon_throttler);
|
|
|
|
messenger->set_policy_throttler(entity_name_t::TYPE_MDS, &daemon_throttler);
|
2012-06-01 16:44:09 +00:00
|
|
|
|
2011-06-07 17:38:54 +00:00
|
|
|
cout << "starting " << g_conf->name << " rank " << rank
|
2011-11-22 17:53:52 +00:00
|
|
|
<< " at " << ipaddr
|
2011-06-07 17:38:54 +00:00
|
|
|
<< " mon_data " << g_conf->mon_data
|
2009-03-12 17:56:37 +00:00
|
|
|
<< " fsid " << monmap.get_fsid()
|
|
|
|
<< std::endl;
|
2011-11-22 17:53:52 +00:00
|
|
|
|
2012-03-02 01:19:22 +00:00
|
|
|
err = messenger->bind(ipaddr);
|
2008-03-10 23:23:41 +00:00
|
|
|
if (err < 0)
|
|
|
|
return 1;
|
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
// start monitor
|
2012-02-12 00:38:06 +00:00
|
|
|
mon = new Monitor(g_ceph_context, g_conf->name.get_id(), &store, messenger, &monmap);
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2011-06-21 19:28:16 +00:00
|
|
|
global_init_daemonize(g_ceph_context, 0);
|
|
|
|
common_init_finish(g_ceph_context);
|
|
|
|
global_init_chdir(g_ceph_context);
|
2011-04-29 18:29:42 +00:00
|
|
|
messenger->start();
|
2008-04-09 17:42:46 +00:00
|
|
|
|
2012-02-12 00:38:06 +00:00
|
|
|
// set up signal handlers, now that we've daemonized/forked.
|
|
|
|
init_async_signal_handler();
|
|
|
|
register_async_signal_handler(SIGHUP, sighup_handler);
|
2012-02-12 22:43:13 +00:00
|
|
|
register_async_signal_handler_oneshot(SIGINT, handle_mon_signal);
|
|
|
|
register_async_signal_handler_oneshot(SIGTERM, handle_mon_signal);
|
2012-02-12 00:38:06 +00:00
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
mon->init();
|
2010-01-08 00:53:51 +00:00
|
|
|
messenger->wait();
|
2007-10-29 19:05:24 +00:00
|
|
|
|
2012-02-29 17:46:06 +00:00
|
|
|
unregister_async_signal_handler(SIGHUP, sighup_handler);
|
|
|
|
unregister_async_signal_handler(SIGINT, handle_mon_signal);
|
|
|
|
unregister_async_signal_handler(SIGTERM, handle_mon_signal);
|
|
|
|
|
2008-03-10 23:23:41 +00:00
|
|
|
store.umount();
|
2007-10-29 19:05:24 +00:00
|
|
|
delete mon;
|
2012-03-02 19:08:51 +00:00
|
|
|
delete messenger;
|
2008-11-04 22:50:21 +00:00
|
|
|
|
|
|
|
// cd on exit, so that gmon.out (if any) goes into a separate directory for each node.
|
|
|
|
char s[20];
|
2010-01-15 00:07:39 +00:00
|
|
|
snprintf(s, sizeof(s), "gmon/%d", getpid());
|
2011-02-04 14:08:41 +00:00
|
|
|
if ((mkdir(s, 0755) == 0) && (chdir(s) == 0)) {
|
2011-09-21 23:28:43 +00:00
|
|
|
dout(0) << "ceph-mon: gmon.out should be in " << s << dendl;
|
2011-02-04 14:08:41 +00:00
|
|
|
}
|
2008-11-04 22:50:21 +00:00
|
|
|
|
2007-10-29 19:05:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|