[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Mar 14 03:06:31 UTC 2016
loolwsd/LOOLWSD.cpp | 37 ++++++++++++++---------------------
loolwsd/MasterProcessSession.cpp | 41 +++++++++++++++++++++++----------------
loolwsd/MasterProcessSession.hpp | 12 +++++------
3 files changed, 46 insertions(+), 44 deletions(-)
New commits:
commit 64d2ff98b8e8329a8f0a2b57dbdc490733ecb28a
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Mar 12 09:07:33 2016 -0500
loolwsd: document saving and restructuring
Change-Id: Ia4c644d07a16ba5284e9cdfaf7b838134fbf640b
Reviewed-on: https://gerrit.libreoffice.org/23212
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 162dae7..1e833d9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -508,29 +508,13 @@ private:
const auto uri = DocumentStoreManager::getUri(request.getURI());
const auto docKey = uri.getPath();
- // This lock could become a bottleneck.
- // In that case, we can use a pool and index by publicPath.
- std::unique_lock<std::mutex> lock(LOOLWSD::SessionsMutex);
-
- // Lookup this document.
- auto it = LOOLWSD::Sessions.find(docKey);
- std::shared_ptr<DocumentStoreManager> document;
- if (it != LOOLWSD::Sessions.end())
- {
- // Get the DocumentStoreManager from the first session.
- auto sessionsMap = it->second;
- assert(!sessionsMap.empty());
- document = sessionsMap.begin()->second->getDocumentStoreManager();
- }
- else
- {
- // Set up the document and its storage.
- const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, id);
- document = DocumentStoreManager::create(uri, jailRoot.toString(), id);
- }
+ // Request a kit process for this doc.
+ const std::string aMessage = "request " + id + " " + docKey + "\r\n";
+ Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 2));
+ Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
auto ws = std::make_shared<WebSocket>(request, response);
- auto session = std::make_shared<MasterProcessSession>(id, LOOLSession::Kind::ToClient, ws, document);
+ auto session = std::make_shared<MasterProcessSession>(id, LOOLSession::Kind::ToClient, ws, nullptr);
// For ToClient sessions, we store incoming messages in a queue and have a separate
// thread that handles them. This is so that we can empty the queue when we get a
@@ -646,7 +630,16 @@ public:
Log::debug("Thread [" + thread_name + "] started.");
auto ws = std::make_shared<WebSocket>(request, response);
- auto session = std::make_shared<MasterProcessSession>(id, LOOLSession::Kind::ToPrisoner, ws, nullptr);
+ auto session = std::make_shared<MasterProcessSession>(sessionId, LOOLSession::Kind::ToPrisoner, ws, nullptr);
+
+ std::unique_lock<std::mutex> lock(MasterProcessSession::AvailableChildSessionMutex);
+ MasterProcessSession::AvailableChildSessions.emplace(sessionId, session);
+
+ Log::info() << " mapped " << session << " jailId=" << jailId << ", id=" << sessionId
+ << " into _availableChildSessions, size=" << MasterProcessSession::AvailableChildSessions.size() << Log::end;
+
+ lock.unlock();
+ MasterProcessSession::AvailableChildSessionCV.notify_one();
SocketProcessor(ws, response, [&session](const char* data, const int size, bool)
{
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 46174c9..5e1e33b 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -117,7 +117,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
// Note that this handles both forwarding requests from the client to the child process, and
// forwarding replies from the child process to the client. Or does it?
- // Snoop at some messages and manipulate tile cache information as needed
+ // Snoop at some messages and manipulate tile cache information as needed
auto peer = _peer.lock();
if (_kind == Kind::ToPrisoner)
@@ -128,6 +128,27 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
return false;
}
+ if (tokens[0] == "unocommandresult:")
+ {
+ const std::string stringMsg(buffer, length);
+ Log::info(getName() +"Command: " + stringMsg);
+ const auto index = stringMsg.find_first_of("{");
+ if (index != std::string::npos)
+ {
+ const std::string stringJSON = stringMsg.substr(index);
+ Poco::JSON::Parser parser;
+ const auto result = parser.parse(stringJSON);
+ const auto object = result.extract<Poco::JSON::Object::Ptr>();
+ if (object->get("commandName").toString() == ".uno:Save" &&
+ object->get("success").toString() == "true")
+ {
+ Log::info() << getName() << " " << _docStoreManager << Log::end;
+ _docStoreManager->save();
+ return true;
+ }
+ }
+ }
+
if (tokens[0] == "error:")
{
std::string errorCommand;
@@ -282,14 +303,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
setId(tokens[1]);
_childId = tokens[2];
- std::unique_lock<std::mutex> lock(AvailableChildSessionMutex);
- AvailableChildSessions.emplace(getId(), shared_from_this());
-
- Log::info() << getName() << " mapped " << this << " jailId=" << _childId << ", id=" << getId()
- << " into _availableChildSessions, size=" << AvailableChildSessions.size() << Log::end;
-
- lock.unlock();
- AvailableChildSessionCV.notify_one();
+ Log::info() << getName() << " Child jailId=" << _childId << ", sessionId=" << getId() << Log::end;
}
else if (_kind == Kind::ToPrisoner)
{
@@ -396,7 +410,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
if ((tokens.count() > 1 && tokens[0] == "uno" && tokens[1] == ".uno:Save"))
{
- _docStoreManager->save();
_tileCache->documentSaved();
}
else if (tokens[0] == "disconnect")
@@ -454,12 +467,6 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/,
std::string timestamp;
parseDocOptions(tokens, _loadPart, timestamp);
- // Request a kit process for this doc.
- Poco::URI uri(_docURL);
- const std::string aMessage = "request " + getId() + " " + uri.getPath() + "\r\n";
- Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
- Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
-
_tileCache.reset(new TileCache(_docURL, timestamp));
// Finally, wait for the Child to connect to Master,
@@ -804,8 +811,10 @@ void MasterProcessSession::dispatchChild()
const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, childSession->_childId);
auto document = DocumentStoreManager::create(_docURL, jailRoot.toString(), childSession->_childId);
+ _docStoreManager = document;
_peer = childSession;
childSession->_peer = shared_from_this();
+ childSession->_docStoreManager = document;
std::ostringstream oss;
oss << "load";
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 1168651..5d2d7ca 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -44,6 +44,12 @@ public:
std::shared_ptr<DocumentStoreManager> getDocumentStoreManager() const { return _docStoreManager; }
+ // Sessions to pre-spawned child processes that have connected but are not yet assigned a
+ // document to work on.
+ static std::map<std::string, std::shared_ptr<MasterProcessSession>> AvailableChildSessions;
+ static std::mutex AvailableChildSessionMutex;
+ static std::condition_variable AvailableChildSessionCV;
+
protected:
bool invalidateTiles(const char *buffer, int length, Poco::StringTokenizer& tokens);
@@ -67,12 +73,6 @@ public:
// per document being edited (i.e., per child process).
std::weak_ptr<MasterProcessSession> _peer;
- // Sessions to pre-spawned child processes that have connected but are not yet assigned a
- // document to work on.
- static std::map<std::string, std::shared_ptr<MasterProcessSession>> AvailableChildSessions;
- static std::mutex AvailableChildSessionMutex;
- static std::condition_variable AvailableChildSessionCV;
-
std::unique_ptr<TileCache> _tileCache;
private:
More information about the Libreoffice-commits
mailing list