[Fawkes Git] branch/fzwilling/robot-memory: robot-memory: fixed trigger-manager in non-replicated case

Frederik Zwilling zwilling at kbsg.rwth-aachen.de
Fri Nov 18 18:00:47 CET 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, fzwilling/robot-memory has been updated
        to  245423ecb8eb908f6586ff3a5658b7df08beaaa5 (commit)
      from  07f7e5cf910ae74eddc6ff63be9ce99d19c56a09 (commit)

http://git.fawkesrobotics.org/fawkes.git/fzwilling/robot-memory

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 245423ecb8eb908f6586ff3a5658b7df08beaaa5
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Fri Nov 18 16:30:19 2016 +0100
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Fri Nov 18 18:00:42 2016 +0100

    robot-memory: fixed trigger-manager in non-replicated case

http://git.fawkesrobotics.org/fawkes.git/commit/245423e
http://trac.fawkesrobotics.org/changeset/245423e

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


- *Summary* -----------------------------------------------------------
 src/plugins/robot-memory/event_trigger_manager.cpp |   28 +++++++++++++++-----
 src/plugins/robot-memory/event_trigger_manager.h   |    6 +++-
 2 files changed, 25 insertions(+), 9 deletions(-)


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

- *commit* 245423ecb8eb908f6586ff3a5658b7df08beaaa5 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Fri Nov 18 16:30:19 2016 +0100
Subject: robot-memory: fixed trigger-manager in non-replicated case

 src/plugins/robot-memory/event_trigger_manager.cpp |   28 +++++++++++++++-----
 src/plugins/robot-memory/event_trigger_manager.h   |    6 +++-
 2 files changed, 25 insertions(+), 9 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/event_trigger_manager.cpp b/src/plugins/robot-memory/event_trigger_manager.cpp
index 8262815..684ce51 100644
--- a/src/plugins/robot-memory/event_trigger_manager.cpp
+++ b/src/plugins/robot-memory/event_trigger_manager.cpp
@@ -31,6 +31,7 @@ EventTriggerManager::EventTriggerManager(Logger* logger, Configuration* config)
 {
   logger_ = logger;
   config_ = config;
+  distributed_ = config_->get_bool("plugins/robot-memory/setup/distributed");
 
   // create connections to running mongod instances because only there
   con_local_ = new mongo::DBClientConnection();
@@ -41,14 +42,16 @@ EventTriggerManager::EventTriggerManager(Logger* logger, Configuration* config)
     std::string err_msg = "Could not connect to mongod process: "+ errmsg;
     throw PluginLoadException("robot-memory", err_msg.c_str());
   }
-  repl_set = config_->get_string("plugins/robot-memory/setup/replicated/replica-set-name");
-  con_replica_ = new mongo::DBClientConnection();
-  if(!con_replica_->connect("localhost:" + std::to_string(config_->get_uint("plugins/robot-memory/setup/replicated/port")), errmsg))
+  if(distributed_)
   {
-    std::string err_msg = "Could not connect to replica set: "+ errmsg;
-    throw PluginLoadException("robot-memory", err_msg.c_str());
+    repl_set = config_->get_string("plugins/robot-memory/setup/replicated/replica-set-name");
+    con_replica_ = new mongo::DBClientConnection();
+    if(!con_replica_->connect("localhost:" + std::to_string(config_->get_uint("plugins/robot-memory/setup/replicated/port")), errmsg))
+    {
+      std::string err_msg = "Could not connect to replica set: "+ errmsg;
+      throw PluginLoadException("robot-memory", err_msg.c_str());
+    }
   }
-
   logger_->log_debug(name.c_str(), "Initialized");
 }
 
@@ -74,7 +77,18 @@ void EventTriggerManager::check_events()
     if(trigger->oplog_cursor->isDead())
     {
       logger_->log_debug(name.c_str(), "Tailable Cursor is dead, requerying");
-      trigger->oplog_cursor = create_oplog_cursor(con_replica_, "local.oplog.rs", trigger->oplog_query);
+      //check if collection is local or replicated
+      mongo::DBClientConnection* con;
+      if(trigger->oplog_collection.find(repl_set) == 0)
+      {
+        con = con_replica_;
+      }
+      else
+      {
+        con = con_local_;
+      }
+
+      trigger->oplog_cursor = create_oplog_cursor(con, "local.oplog.rs", trigger->oplog_query);
     }
   }
 }
diff --git a/src/plugins/robot-memory/event_trigger_manager.h b/src/plugins/robot-memory/event_trigger_manager.h
index 6b872c5..06362e8 100644
--- a/src/plugins/robot-memory/event_trigger_manager.h
+++ b/src/plugins/robot-memory/event_trigger_manager.h
@@ -71,15 +71,16 @@ class EventTriggerManager
       //check if collection is local or replicated
       mongo::DBClientConnection* con;
       std::string oplog;
+      oplog = "local.oplog.rs";
       if(collection.find(repl_set) == 0)
       {
         con = con_replica_;
-        oplog = "local.oplog.rs";
+        if(!distributed_)
+          logger_->log_error(name.c_str(), "Can not add trigger for %s, if the robot memory is not configured to be distributed", collection.c_str());
       }
       else
       {
         con = con_local_;
-        oplog = "local.oplog.rs";
       }
 
       EventTrigger *trigger = new EventTrigger(oplog_query, collection, boost::bind(callback, obj, _1));
@@ -103,6 +104,7 @@ class EventTriggerManager
     mongo::DBClientConnection* con_replica_;
 
     std::string repl_set, local_db;
+    bool distributed_;
 
     std::list<EventTrigger*> triggers;
 };




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list