[Libreoffice-commits] online.git: 2 commits - loolwsd.xml.in wsd/Admin.cpp wsd/Admin.hpp

Michael Meeks michael.meeks at collabora.com
Fri May 18 17:33:28 UTC 2018


 loolwsd.xml.in |    1 -
 wsd/Admin.cpp  |   39 ++++++++++++++++++++++++++++++++++-----
 wsd/Admin.hpp  |   11 ++++++++++-
 3 files changed, 44 insertions(+), 7 deletions(-)

New commits:
commit 44e065d01852ac282ab2fdee35f095f3fa73ee26
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri May 18 18:32:33 2018 +0100

    Remove test monitor.
    
    Change-Id: I55f93ffec68745b194a778b541db1011962f735d

diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index 4937055a3..d4ca9b3ea 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -117,7 +117,6 @@
     </admin_console>
 
     <monitors desc="Addresses of servers we connect to on start for monitoring">
-	<monitor>ws://localhost:9042/foo</monitor>
     </monitors>
 
 </config>
commit 7475120c81a64c0dc7333b2e929b4832795fa1e8
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri May 18 17:35:19 2018 +0100

    If a monitor is dis-connected, try to re-connect it.
    
    Change-Id: I04f254acfe823f07e7fb11b277e661c09e146ebd

diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 0350c714d..723bb22f9 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -445,6 +445,17 @@ void Admin::pollingThread()
             lastNet = now;
         }
 
+        // (re)-connect (with sync. DNS - urk) to one monitor at a time
+        if (_pendingConnects.size())
+        {
+            MonitorConnectRecord rec = _pendingConnects[0];
+            if (rec._when < now)
+            {
+                _pendingConnects.erase(_pendingConnects.begin());
+                connectToMonitorSync(rec._uri);
+            }
+        }
+
         // Handle websockets & other work.
         const int timeout = capAndRoundInterval(std::min(std::min(cpuWait, memWait), netWait));
         LOG_TRC("Admin poll for " << timeout << "ms.");
@@ -627,11 +638,13 @@ void Admin::dumpState(std::ostream& os)
 class MonitorSocketHandler : public AdminSocketHandler
 {
     bool _connecting;
+    std::string _uri;
 public:
 
-    MonitorSocketHandler(Admin *admin) :
+    MonitorSocketHandler(Admin *admin, const std::string &uri) :
         AdminSocketHandler(admin),
-        _connecting(true)
+        _connecting(true),
+        _uri(uri)
     {
     }
     int getPollEvents(std::chrono::steady_clock::time_point now,
@@ -652,11 +665,27 @@ public:
         _connecting = false;
         return AdminSocketHandler::performWrites();
     }
+
+    void onDisconnect() override
+    {
+        LOG_WRN("Monitor " << _uri << " dis-connected, re-trying in 20 seconds");
+        Admin::instance().scheduleMonitorConnect(_uri, std::chrono::steady_clock::now() + std::chrono::seconds(20));
+    }
 };
 
-void Admin::connectToMonitor(const Poco::URI &uri)
+void Admin::connectToMonitorSync(const std::string &uri)
+{
+    insertNewWebSocketSync(Poco::URI(uri), std::make_shared<MonitorSocketHandler>(this, uri));
+}
+
+void Admin::scheduleMonitorConnect(const std::string &uri, std::chrono::steady_clock::time_point when)
 {
-    insertNewWebSocketSync(uri, std::make_shared<MonitorSocketHandler>(this));
+    assertCorrectThread();
+
+    MonitorConnectRecord todo;
+    todo._when = when;
+    todo._uri = uri;
+    _pendingConnects.push_back(todo);
 }
 
 void Admin::start()
@@ -675,7 +704,7 @@ void Admin::start()
             Poco::URI monitor(uri);
             if (monitor.getScheme() == "wss" || monitor.getScheme() == "ws")
             {
-                addCallback([=] { connectToMonitor(monitor); } );
+                addCallback([=] { scheduleMonitorConnect(uri, std::chrono::steady_clock::now()); });
                 haveMonitors = true;
             }
             else
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index fbd15f8ac..ed9ca55f8 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -116,6 +116,9 @@ public:
             notifyForkit();
     }
 
+    /// Attempt a synchronous connection to a monitor with @uri @when that future comes
+    void scheduleMonitorConnect(const std::string &uri, std::chrono::steady_clock::time_point when);
+
 private:
     /// Notify Forkit of changed settings.
     void notifyForkit();
@@ -133,7 +136,7 @@ private:
     }
 
     /// Synchronous connection setup to remote monitoring server
-    void connectToMonitor(const Poco::URI &uri);
+    void connectToMonitorSync(const std::string &uri);
 
 private:
     /// The model is accessed only during startup & in
@@ -148,6 +151,12 @@ private:
     size_t _totalSysMemKb;
     size_t _totalAvailMemKb;
 
+    struct MonitorConnectRecord {
+        std::chrono::steady_clock::time_point _when;
+        std::string _uri;
+    };
+    std::vector<MonitorConnectRecord> _pendingConnects;
+
     std::atomic<int> _cpuStatsTaskIntervalMs;
     std::atomic<int> _memStatsTaskIntervalMs;
     std::atomic<int> _netStatsTaskIntervalMs;


More information about the Libreoffice-commits mailing list