Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

shutdown quit daemons, data layer state dumped

Signed-off-by: Pawel Loj <pawel.loj@gmail.com>
  • Loading branch information...
commit 9eed18f7c62ef4edf399fc7405d348906a840e06 1 parent b668113
@limaoscarjuliet limaoscarjuliet authored
View
4 hyperdaemon/daemon.cc
@@ -271,11 +271,11 @@ hyperdaemon :: daemon(const char* progname,
repl.cleanup(cl.config(), comm.inst());
data.cleanup(cl.config(), comm.inst());
comm.cleanup(cl.config(), comm.inst());
+
cl.acknowledge();
}
- uint64_t now;
-
+ uint64_t now = -1;
switch (cl.loop(1, -1))
{
case hyperdex::coordinatorlink::SHUTDOWN:
View
65 hyperdaemon/datalayer.cc
@@ -54,6 +54,9 @@
// e
#include <e/timer.h>
+// util
+#include <util/atomicfile.h>
+
// HyperDex
#include "hyperdex/hyperdex/configuration.h"
#include "hyperdex/hyperdex/coordinatorlink.h"
@@ -71,6 +74,9 @@ using hyperdex::coordinatorlink;
typedef e::intrusive_ptr<hyperdisk::disk> disk_ptr;
typedef std::map<hyperdex::regionid, disk_ptr> disk_map_t;
+const char* hyperdaemon :: datalayer :: STATE_FILE_NAME = "datalayer_state.hd";
+const int hyperdaemon :: datalayer :: STATE_FILE_VER = 1;
+
hyperdaemon :: datalayer :: datalayer(coordinatorlink* cl, const po6::pathname& base)
: m_cl(cl)
, m_shutdown(false)
@@ -95,6 +101,10 @@ hyperdaemon :: datalayer :: datalayer(coordinatorlink* cl, const po6::pathname&
t->start();
m_flush_threads.push_back(t);
}
+
+ // Load state from shutdown.
+ // XXX check results - should not be in constructor probably
+ load_state();
}
hyperdaemon :: datalayer :: ~datalayer() throw ()
@@ -112,6 +122,42 @@ hyperdaemon :: datalayer :: ~datalayer() throw ()
}
}
+bool
+hyperdaemon :: datalayer :: dump_state(const configuration& config, const instance& us)
+{
+ // Dump state information.
+ std::ostringstream s;
+ s << "version " << STATE_FILE_VER << std::endl;
+
+ s << "instance_us";
+ s << " " << us.address;
+ s << " " << us.inbound_port;
+ s << " " << us.inbound_version;
+ s << " " << us.outbound_port;
+ s << " " << us.outbound_version;
+ s << std::endl;
+
+ s << "quiesced_config" << std::endl;
+ s << config.config_text();
+
+ // Rewrite the state file atomically.
+ if (!util::atomicfile::rewrite(m_base.get(), STATE_FILE_NAME, s.str().c_str()))
+ {
+ PLOG(ERROR) << "Could not write config to a file " << STATE_FILE_NAME;
+ return false;
+ }
+
+ return true;
+}
+
+bool
+hyperdaemon :: datalayer :: load_state()
+{
+
+
+ return true;
+}
+
void
hyperdaemon :: datalayer :: prepare(const configuration& newconfig, const instance& us)
{
@@ -137,7 +183,7 @@ hyperdaemon :: datalayer :: prepare(const configuration& newconfig, const instan
}
void
-hyperdaemon :: datalayer :: reconfigure(const configuration& newconfig, const instance&)
+hyperdaemon :: datalayer :: reconfigure(const configuration& newconfig, const instance& us)
{
// Quiesce (will quiesce multiple times if requested so).
if (newconfig.quiesce())
@@ -148,17 +194,28 @@ hyperdaemon :: datalayer :: reconfigure(const configuration& newconfig, const in
// Quiesce the disks.
for (disk_map_t::iterator d = m_disks.begin(); d != m_disks.end(); d.next())
{
+ bool res = false;
try
{
- // XXX fail this region.
- d.value()->quiesce(m_quiesce_state_id);
+ res = d.value()->quiesce(m_quiesce_state_id);
}
catch (po6::error& e)
{
+ res = false;
+ }
+
+ if (!res)
+ {
+ // XXX fail this region
PLOG(ERROR) << "Could not quiesce disk " << d.key();
- return;
}
}
+
+ if (!dump_state(newconfig, us))
+ {
+ // XXX fail entire host?
+ PLOG(ERROR) << "Could not save datalayer state.";
+ }
}
}
View
7 hyperdaemon/datalayer.h
@@ -127,8 +127,15 @@ class datalayer
std::list<hyperdex::regionid> m_optimistic_rr;
uint64_t m_last_dose_of_optimism;
volatile bool m_flushed_recently;
+
+ private:
+ // Shutdown and restart.
+ static const char* STATE_FILE_NAME;
+ static const int STATE_FILE_VER;
bool m_quiesce;
std::string m_quiesce_state_id;
+ bool dump_state(const hyperdex::configuration& config, const hyperdex::instance& us);
+ bool load_state();
};
} // namespace hyperdaemon
View
11 hyperdex/configuration.cc
@@ -46,7 +46,8 @@ const uint32_t hyperdex::configuration::CLIENTSPACE = UINT32_MAX;
const uint32_t hyperdex::configuration::TRANSFERSPACE = UINT32_MAX - 1;
hyperdex :: configuration :: configuration()
- : m_version(0)
+ : m_config_text("")
+ , m_version(0)
, m_hosts()
, m_space_assignment()
, m_spaces()
@@ -62,7 +63,8 @@ hyperdex :: configuration :: configuration()
{
}
-hyperdex :: configuration :: configuration(uint64_t ver,
+hyperdex :: configuration :: configuration(const std::string& config_text,
+ uint64_t ver,
const std::vector<instance>& hosts,
const std::map<std::string, spaceid>& space_assignment,
const std::map<spaceid, std::vector<attribute> >& spaces,
@@ -71,9 +73,10 @@ hyperdex :: configuration :: configuration(uint64_t ver,
const std::map<subspaceid, hyperspacehashing::prefix::hasher>& repl_hashers,
const std::map<subspaceid, hyperspacehashing::mask::hasher>& disk_hashers,
const std::map<std::pair<instance, uint16_t>, hyperdex::regionid>& transfers,
- bool quiesce, const std::string quiesce_state_id,
+ bool quiesce, const std::string& quiesce_state_id,
bool shutdown)
- : m_version(ver)
+ : m_config_text(config_text)
+ , m_version(ver)
, m_hosts(hosts)
, m_space_assignment(space_assignment)
, m_spaces(spaces)
View
6 hyperdex/configuration_parser.cc
@@ -31,7 +31,8 @@
#include "hyperdex/hyperdex/configuration_parser.h"
hyperdex :: configuration_parser :: configuration_parser()
- : m_version(0)
+ : m_config_text("")
+ , m_version(0)
, m_hosts()
, m_space_assignment()
, m_spaces()
@@ -88,7 +89,7 @@ hyperdex :: configuration_parser :: generate()
disk_hashers.insert(std::make_pair(di->first, h));
}
- return configuration(m_version, hosts, m_space_assignment, m_spaces, space_sizes,
+ return configuration(m_config_text, m_version, hosts, m_space_assignment, m_spaces, space_sizes,
m_entities, repl_hashers, disk_hashers, m_transfers,
m_quiesce, m_quiesce_state_id, m_shutdown);
}
@@ -108,6 +109,7 @@ hyperdex::configuration_parser::error
hyperdex :: configuration_parser :: parse(const std::string& config)
{
*this = configuration_parser();
+ m_config_text = config;
std::vector<char> v;
v.resize(config.size() + 1);
memmove(&v.front(), config.c_str(), config.size() + 1);
View
10 hyperdex/coordinatorlink.cc 100644 → 100755
@@ -247,7 +247,15 @@ hyperdex :: coordinatorlink :: loop(size_t iterations, int timeout)
{
m_acknowledged = false;
m_config = cp.generate();
- return SUCCESS;
+ if (!m_config.shutdown())
+ {
+ return SUCCESS;
+ }
+ else
+ {
+ // This config will not be processed, we go straight to shutdown.
+ return SHUTDOWN;
+ }
}
else
{
View
10 hyperdex/hyperdex/configuration.h
@@ -57,7 +57,8 @@ class configuration
public:
configuration();
- configuration(uint64_t version,
+ configuration(const std::string& config_text,
+ uint64_t version,
const std::vector<instance>& hosts,
const std::map<std::string, spaceid>& space_assignment,
const std::map<spaceid, std::vector<attribute> >& spaces,
@@ -66,10 +67,14 @@ class configuration
const std::map<subspaceid, hyperspacehashing::prefix::hasher>& repl_hashers,
const std::map<subspaceid, hyperspacehashing::mask::hasher>& disk_hashers,
const std::map<std::pair<instance, uint16_t>, hyperdex::regionid>& transfers,
- bool quiesce, const std::string quiesce_state_id,
+ bool quiesce, const std::string& quiesce_state_id,
bool shutdown);
~configuration() throw ();
+ // The original config text
+ public:
+ std::string config_text() const { return m_config_text; }
+
// The version of this config
public:
uint64_t version() const { return m_version; }
@@ -142,6 +147,7 @@ class configuration
const hyperspacehashing::search& s) const;
private:
+ std::string m_config_text;
uint64_t m_version;
std::vector<instance> m_hosts;
std::map<std::string, spaceid> m_space_assignment;
View
1  hyperdex/hyperdex/configuration_parser.h
@@ -125,6 +125,7 @@ class configuration_parser
const std::vector<bool>& attrs);
private:
+ std::string m_config_text;
uint64_t m_version;
std::map<uint64_t, instance> m_hosts;
std::map<std::string, spaceid> m_space_assignment;
View
1  util/atomicfile.h
@@ -31,6 +31,7 @@
// POSIX
#include <errno.h>
#include <limits.h>
+#include <stdio.h>
// C++
#include <iostream>
Please sign in to comment.
Something went wrong with that request. Please try again.