Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

graceful shutdown on source db error

git-svn-id: http://kazuho.31tools.com/svn/incline/trunk@256 4d3e2a30-9d6d-0410-bc8c-dac56cff10b3
  • Loading branch information...
commit 4660891688f592a31ab7de6a0cf54934c4d062aa 1 parent 40439e9
kazuho authored
View
16 src/incline_fw.cc
@@ -4,7 +4,7 @@ extern "C" {
}
#include "incline_dbms.h"
#include "incline_def_async_qtable.h"
-#include "incline_driver.h"
+#include "incline_driver_async_qtable.h"
#include "incline_fw.h"
#include "incline_util.h"
@@ -27,6 +27,15 @@ incline_fw::manager::log_sql(const incline_dbms* dbms, const string& sql)
}
}
+bool
+incline_fw::manager::should_exit_loop() const
+{
+ if (! should_exit_loop_ && driver_->should_exit_loop()) {
+ const_cast<incline_fw::manager*>(this)->should_exit_loop_ = true;
+ }
+ return should_exit_loop_;
+}
+
incline_fw::incline_fw(manager* mgr, const incline_def_async_qtable* def,
incline_dbms* dbh)
: mgr_(mgr), def_(def), dbh_(dbh),
@@ -60,6 +69,7 @@ incline_fw::incline_fw(manager* mgr, const incline_def_async_qtable* def,
incline_fw::~incline_fw()
{
delete dbh_;
+ dbh_ = NULL;
}
void*
@@ -68,9 +78,9 @@ incline_fw::run()
try {
do_run();
} catch (domain_error& e) {
- delete this;
- throw;
+ cerr << e.what() << endl;
}
+ mgr_->should_exit_loop(true);
delete this;
return NULL;
}
View
5 src/incline_fw.h
@@ -16,12 +16,15 @@ class incline_fw {
const incline_driver_async_qtable* driver_;
int poll_interval_;
int log_fd_;
+ bool should_exit_loop_;
public:
- manager(const incline_driver_async_qtable* driver, int poll_interval, int log_fd) : driver_(driver), poll_interval_(poll_interval), log_fd_(log_fd) {}
+ manager(const incline_driver_async_qtable* driver, int poll_interval, int log_fd) : driver_(driver), poll_interval_(poll_interval), log_fd_(log_fd), should_exit_loop_(false) {}
virtual ~manager() {}
const incline_driver_async_qtable* driver() const { return driver_; }
int poll_interval() const { return poll_interval_; }
void log_sql(const incline_dbms* dbh, const std::string& sql);
+ bool should_exit_loop() const;
+ void should_exit_loop(bool f) { should_exit_loop_ = f; }
};
protected:
View
2  src/incline_fw_async_qtable.cc
@@ -21,7 +21,7 @@ incline_fw_async_qtable::do_run()
{
string extra_cond, last_id;
- while (! mgr_->driver()->should_exit_loop()) {
+ while (! mgr_->should_exit_loop()) {
try {
vector<string> iq_ids;
vector<vector<string> > delete_pks, insert_rows;
View
2  src/incline_fw_replicator.cc
@@ -48,7 +48,7 @@ incline_fw_replicator::do_run()
incline_dbms* dest_dbh = NULL;
string last_id;
- while (! mgr()->driver()->should_exit_loop()) {
+ while (! mgr()->should_exit_loop()) {
vector<string> iq_ids;
vector<vector<string> > delete_pks, insert_rows;
View
2  src/tmd.h
@@ -57,7 +57,9 @@ namespace tmd {
public:
error_t(const std::string& s, unsigned int mysql_errno = 0)
: std::domain_error(s), mysql_errno_(mysql_errno) {
+#ifdef TMD_PRINT_ERROR
fprintf(stderr, "%d:%s\n", mysql_errno, s.c_str());
+#endif
}
unsigned int mysql_errno() const { return mysql_errno_; }
};
Please sign in to comment.
Something went wrong with that request. Please try again.