Changes have been pushed for the repository "fawkesrobotics/fawkes".

Clone:  https://github.com/fawkesrobotics/fawkes.git
Gitweb: https://github.com/fawkesrobotics/fawkes

The branch, thofmann/mongocxx-v3 has been updated
        to  c0c8d0c10060c62ddf3c0602ba87ed2b57d66e58 (commit)
       via  ba2a9d45259455dbb550429d951977371ff76822 (commit)
      from  8275ea07cfbad845a86e9f714cde50e0938ff6c0 (commit)

https://github.com/fawkesrobotics/fawkes/tree/thofmann/mongocxx-v3

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit ba2a9d45259455dbb550429d951977371ff76822
Author:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
AuthorDate: Sat Apr 13 11:52:33 2019 +0200
Commit:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
CommitDate: Sat Apr 13 11:52:33 2019 +0200

    aspect: fix typo in aspect manager exception message

https://github.com/fawkesrobotics/fawkes/commit/ba2a9d452

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit c0c8d0c10060c62ddf3c0602ba87ed2b57d66e58
Author:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
AuthorDate: Sat Apr 13 14:15:05 2019 +0200
Commit:     Till Hofmann <hofm...@kbsg.rwth-aachen.de>
CommitDate: Sat Apr 13 14:20:11 2019 +0200

    mongodb: fix initialization of ReplicaSetConfigThread
    
    The ReplicaSetConfigThread was used by the MongoDBThread before it was
    fully initialized, resulting in segfaults, e.g., by logger being NULL.
    
    Fix the initialization in two ways: For one, move most of the
    ReplicaSetConfig initialization from the constructor into init().
    Second, do not call bootstrap from the mongodb thread, but instead call
    it at the end of init. This way, we can guarantee that the
    ReplicaSetConfigThread is fully initialized before operating on it.

https://github.com/fawkesrobotics/fawkes/commit/c0c8d0c10

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/libs/aspect/manager.cpp                       |  2 +-
 src/plugins/mongodb/mongodb_replicaset_config.cpp | 90 +++++++++++++----------
 src/plugins/mongodb/mongodb_replicaset_config.h   | 13 ++--
 src/plugins/mongodb/mongodb_thread.cpp            | 10 +--
 4 files changed, 61 insertions(+), 54 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* ba2a9d45259455dbb550429d951977371ff76822 - - - - - - - - - -
Author:  Till Hofmann <hofm...@kbsg.rwth-aachen.de>
Date:    Sat Apr 13 11:52:33 2019 +0200
Subject: aspect: fix typo in aspect manager exception message

 src/libs/aspect/manager.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

_Diff for modified files_:
diff --git a/src/libs/aspect/manager.cpp b/src/libs/aspect/manager.cpp
index 8943fd6f2..6edeb8743 100644
--- a/src/libs/aspect/manager.cpp
+++ b/src/libs/aspect/manager.cpp
@@ -125,7 +125,7 @@ AspectManager::init(Thread *thread)
                        for (i = aspects.begin(); i != aspects.end(); ++i) {
                                if (inifins_.find(*i) == inifins_.end()) {
                                        throw 
CannotInitializeThreadException("Thread '%s' has the %s, "
-                                                                             
"but no initiliazer is known.",
+                                                                             
"but no initializer is known.",
                                                                              
thread->name(),
                                                                              
*i);
                                }

- *commit* c0c8d0c10060c62ddf3c0602ba87ed2b57d66e58 - - - - - - - - - -
Author:  Till Hofmann <hofm...@kbsg.rwth-aachen.de>
Date:    Sat Apr 13 14:15:05 2019 +0200
Subject: mongodb: fix initialization of ReplicaSetConfigThread

 src/plugins/mongodb/mongodb_replicaset_config.cpp | 90 +++++++++++++----------
 src/plugins/mongodb/mongodb_replicaset_config.h   | 13 ++--
 src/plugins/mongodb/mongodb_thread.cpp            | 10 +--
 3 files changed, 60 insertions(+), 53 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/mongodb/mongodb_replicaset_config.cpp 
b/src/plugins/mongodb/mongodb_replicaset_config.cpp
index 13ffa3ae3..0e4b42a46 100644
--- a/src/plugins/mongodb/mongodb_replicaset_config.cpp
+++ b/src/plugins/mongodb/mongodb_replicaset_config.cpp
@@ -48,47 +48,79 @@ using namespace bsoncxx::builder;
 
 /** Constructor.
  * This will read the given configuration.
- * @param config configuration to query
  * @param cfgname configuration name
  * @param prefix configuration path prefix
- * @param bootstrap_database database to hold leader election data
+ * @param bootstrap_prefix configuration path prefix for bootstrap 
configuration
  */
-MongoDBReplicaSetConfig::MongoDBReplicaSetConfig(Configuration *config,
-                                                 std::string    cfgname,
-                                                 std::string    prefix,
-                                                 std::string    
bootstrap_database)
+MongoDBReplicaSetConfig::MongoDBReplicaSetConfig(std::string cfgname,
+                                                 std::string prefix,
+                                                 std::string bootstrap_prefix)
 : Thread("MongoDBReplicaSet", Thread::OPMODE_CONTINUOUS),
   leader_elec_query_(bsoncxx::builder::basic::document()),
   leader_elec_query_force_(bsoncxx::builder::basic::document()),
   leader_elec_update_(bsoncxx::builder::basic::document())
 {
        set_name("MongoDBReplicaSet|%s", cfgname.c_str());
-       config_name_ = cfgname;
-       is_leader_   = false;
+       config_name_      = cfgname;
+       prefix_           = prefix;
+       bootstrap_prefix_ = bootstrap_prefix;
+       is_leader_        = false;
        last_status_ =
          ReplicaSetStatus{.member_status  = 
MongoDBManagedReplicaSetInterface::ERROR,
                           .primary_status = 
MongoDBManagedReplicaSetInterface::PRIMARY_UNKNOWN};
 
        enabled_ = false;
+}
+
+void
+MongoDBReplicaSetConfig::init()
+{
        try {
-               enabled_ = config->get_bool(prefix + "enabled");
+               enabled_ = config->get_bool(prefix_ + "enabled");
        } catch (Exception &e) {
        }
+       if (!enabled_) {
+               throw Exception("Replica set manager '%s' cannot be started 
while disabled", name());
+       }
+
+       logger->log_debug(name(),
+                         "Bootstrap Query:  %s",
+                         bsoncxx::to_json(leader_elec_query_.view()).c_str());
+       logger->log_debug(name(),
+                         "Bootstrap Update: %s",
+                         bsoncxx::to_json(leader_elec_update_.view()).c_str());
+
+       rs_status_if_ =
+         
blackboard->open_for_writing<MongoDBManagedReplicaSetInterface>(config_name_.c_str());
+
+       timewait_ = new TimeWait(clock, (int)(loop_interval_ * 1000000.));
 
        if (enabled_) {
-               bootstrap_database_ = bootstrap_database;
-               bootstrap_ns_       = bootstrap_database + "." + config_name_;
+               bootstrap_database_                      = 
config->get_string(bootstrap_prefix_ + "database");
+               std::string         bootstrap_client_cfg = 
config->get_string(bootstrap_prefix_ + "client");
+               MongoDBClientConfig bootstrap_client_config(config,
+                                                           logger,
+                                                           
bootstrap_client_cfg,
+                                                           
"/plugins/mongodb/clients/" + bootstrap_client_cfg
+                                                             + "/");
+               if (!bootstrap_client_config.is_enabled()) {
+                       throw Exception("%s: bootstrap client configuration 
'%s' disabled",
+                                       name(),
+                                       bootstrap_client_cfg.c_str());
+               }
+               
bootstrap_client_.reset(bootstrap_client_config.create_client());
+               bootstrap_ns_ = bootstrap_database_ + "." + config_name_;
 
-               local_client_cfg_ = config->get_string(prefix + "local-client");
+               local_client_cfg_ = config->get_string(prefix_ + 
"local-client");
                loop_interval_    = 5.0;
                try {
-                       loop_interval_ = config->get_float(prefix + 
"loop-interval");
+                       loop_interval_ = config->get_float(prefix_ + 
"loop-interval");
                } catch (Exception &e) {
                } // ignored, use default
 
                leader_expiration_ = 10;
                try {
-                       leader_expiration_ = config->get_int(prefix + 
"leader-expiration");
+                       leader_expiration_ = config->get_int(prefix_ + 
"leader-expiration");
                } catch (Exception &e) {
                } // ignored, use default
 
@@ -107,7 +139,7 @@ 
MongoDBReplicaSetConfig::MongoDBReplicaSetConfig(Configuration *config,
                                        local_client_cfg_.c_str());
                }
                local_hostport_                = client_config.hostport();
-               std::vector<std::string> hostv = config->get_strings(prefix + 
"hosts");
+               std::vector<std::string> hostv = config->get_strings(prefix_ + 
"hosts");
                std::copy(hostv.begin(), hostv.end(), std::inserter(hosts_, 
hosts_.end()));
 
                if (std::find(hosts_.begin(), hosts_.end(), local_hostport_) == 
hosts_.end()) {
@@ -137,19 +169,19 @@ 
MongoDBReplicaSetConfig::MongoDBReplicaSetConfig(Configuration *config,
 
                local_client_.reset(client_config.create_client());
        }
+       bootstrap();
 }
 
 /** Setup replicaset bootstrap client.
  * @param bootstrap_client MongoDB client to access bootstrap database
  */
 void
-MongoDBReplicaSetConfig::bootstrap(std::shared_ptr<mongocxx::client> 
bootstrap_client)
+MongoDBReplicaSetConfig::bootstrap()
 {
        if (enabled_) {
                try {
-                       bootstrap_client_ = bootstrap_client;
-                       auto database     = 
bootstrap_client_->database(bootstrap_database_);
-                       auto collection   = 
database.create_collection(bootstrap_ns_);
+                       auto database   = 
bootstrap_client_->database(bootstrap_database_);
+                       auto collection = 
database.create_collection(bootstrap_ns_);
 
                        
collection.create_index(basic::make_document(basic::kvp("host", 1)));
                        
collection.create_index(basic::make_document(basic::kvp("master", 1)),
@@ -213,26 +245,6 @@ MongoDBReplicaSetConfig::leader_resign()
 }
 
 void
-MongoDBReplicaSetConfig::init()
-{
-       if (!enabled_) {
-               throw Exception("Replica set manager '%s' cannot be started 
while disabled", name());
-       }
-
-       logger->log_debug(name(),
-                         "Bootstrap Query:  %s",
-                         bsoncxx::to_json(leader_elec_query_.view()).c_str());
-       logger->log_debug(name(),
-                         "Bootstrap Update: %s",
-                         bsoncxx::to_json(leader_elec_update_.view()).c_str());
-
-       rs_status_if_ =
-         
blackboard->open_for_writing<MongoDBManagedReplicaSetInterface>(config_name_.c_str());
-
-       timewait_ = new TimeWait(clock, (int)(loop_interval_ * 1000000.));
-}
-
-void
 MongoDBReplicaSetConfig::finalize()
 {
        leader_resign();
diff --git a/src/plugins/mongodb/mongodb_replicaset_config.h 
b/src/plugins/mongodb/mongodb_replicaset_config.h
index 93ea00adb..d9925f3f1 100644
--- a/src/plugins/mongodb/mongodb_replicaset_config.h
+++ b/src/plugins/mongodb/mongodb_replicaset_config.h
@@ -24,6 +24,7 @@
 
 #include <aspect/blackboard.h>
 #include <aspect/clock.h>
+#include <aspect/configurable.h>
 #include <aspect/logging.h>
 #include <core/threading/thread.h>
 #include <interfaces/MongoDBManagedReplicaSetInterface.h>
@@ -36,7 +37,6 @@
 #include <vector>
 
 namespace fawkes {
-class Configuration;
 class TimeWait;
 } // namespace fawkes
 
@@ -46,15 +46,12 @@ class DBClientBase;
 
 class MongoDBReplicaSetConfig : public fawkes::Thread,
                                 public fawkes::LoggingAspect,
+                                public fawkes::ConfigurableAspect,
                                 public fawkes::ClockAspect,
                                 public fawkes::BlackBoardAspect
 {
 public:
-       MongoDBReplicaSetConfig(fawkes::Configuration *config,
-                               std::string            cfgname,
-                               std::string            prefix,
-                               std::string            bootstrap_database);
-       void bootstrap(std::shared_ptr<mongocxx::client> bootstrap_client);
+       MongoDBReplicaSetConfig(std::string cfgname, std::string prefix, 
std::string bootstrap_prefix);
 
        /** Check if configuration is enabled.
         * @return true if configuration is enabled, false otherwise
@@ -70,6 +67,7 @@ public:
        virtual void finalize();
 
 private:
+       void bootstrap();
        bool leader_elect(bool force = false);
        void leader_resign();
 
@@ -111,8 +109,9 @@ private:
        bsoncxx::document::value          leader_elec_query_;
        bsoncxx::document::value          leader_elec_query_force_;
        bsoncxx::document::value          leader_elec_update_;
+       std::string                       prefix_;
+       std::string                       bootstrap_prefix_;
        std::string                       bootstrap_database_;
-       std::string                       bootstrap_collection_;
        std::string                       bootstrap_ns_;
 
        std::string                       local_client_cfg_;
diff --git a/src/plugins/mongodb/mongodb_thread.cpp 
b/src/plugins/mongodb/mongodb_thread.cpp
index c5e070d27..c52488896 100644
--- a/src/plugins/mongodb/mongodb_thread.cpp
+++ b/src/plugins/mongodb/mongodb_thread.cpp
@@ -174,13 +174,9 @@ MongoDBThread::init_replicaset_configs()
                        std::string cfg_prefix = prefix + cfg_name + "/";
 
                        try {
-                               auto conf = 
std::make_shared<MongoDBReplicaSetConfig>(config,
-                                                                               
      cfg_name,
-                                                                               
      cfg_prefix,
-                                                                               
      bootstrap_database);
-                               if (conf->is_enabled()) {
-                                       std::shared_ptr<mongocxx::client> 
bootstrap_client(create_client(bootstrap_client_cfg));
-                                       conf->bootstrap(bootstrap_client);
+                               if (config->get_bool(cfg_prefix + "enabled")) {
+                                       auto conf =
+                                         
std::make_shared<MongoDBReplicaSetConfig>(cfg_name, cfg_prefix, 
bootstrap_prefix);
                                        replicaset_configs_[cfg_name] = conf;
                                        logger->log_info(name(), "Added MongoDB 
replica set configuration %s", cfg_name.c_str());
                                } else {



_______________________________________________
fawkes-commits mailing list
fawkes-commits@lists.kbsg.rwth-aachen.de
https://lists.kbsg.rwth-aachen.de/listinfo/fawkes-commits

Reply via email to