[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp

2018-02-15 Thread Pranav Kant
 wsd/DocumentBroker.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit ff5fd0ebdac600b3e1a869338b8d55e50bbedd5a
Author: Pranav Kant 
Date:   Thu Feb 1 23:58:43 2018 +0530

wsd: Don't save if document ends up being unmodified

Change-Id: Ie027f5b49c37e7df3f36499e0fef3eca78173969
Reviewed-on: https://gerrit.libreoffice.org/49749
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 4be7a88c..7f04412b 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -896,7 +896,7 @@ bool DocumentBroker::autoSave(const bool force)
 {
 LOG_TRC("Sending forced save command for [" << _docKey << "].");
 // Don't terminate editing as this can be invoked by the admin OOM, 
but otherwise force saving anyway.
-sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/ true, 
/*dontSaveIfUnmodified=*/ false, /*isAutosave=*/ false);
+sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/ true, 
/*dontSaveIfUnmodified=*/ true, /*isAutosave=*/ false);
 }
 else if (_isModified)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp

2018-02-15 Thread Pranav Kant
 wsd/DocumentBroker.cpp |   11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

New commits:
commit 61ffc7c0a15107db7ac7304584cf42b89946f3d6
Author: Pranav Kant 
Date:   Thu Feb 1 22:43:47 2018 +0530

wsd: DocumentBroker: Don't initiate the document close

Just broadcast the message and let clients deal with it. This is similar
to how we do it when we find the document conflict via CheckFileInfo

Change-Id: I52855fcb96a359b3915afe71d481321f79b4554b
Reviewed-on: https://gerrit.libreoffice.org/49748
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c0d33348..4be7a88c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -837,14 +837,11 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 {
 LOG_ERR("PutFile says that Document changed in storage");
 _documentChangedInStorage = true;
+std::string message = "close: documentconflict";
 if (_isModified)
-{
-broadcastMessage("error: cmd=storage kind=documentconflict");
-}
-else
-{
-closeDocument("documentconflict");
-}
+message = "error: cmd=storage kind=documentconflict";
+
+broadcastMessage(message);
 }
 
 return false;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2018-01-22 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   36 
 wsd/DocumentBroker.hpp |5 +
 2 files changed, 29 insertions(+), 12 deletions(-)

New commits:
commit 0825872b0f4089675f4e3aa904b1f5e07595a341
Author: Ashod Nakashian 
Date:   Mon Jan 15 00:49:14 2018 -0500

wsd: save before stopping

We don't force saving unconditionally now. Only
when the doc is reasonably expected to be modified
do we force saving (to circumvent the minimum duration
between auto-saves).

We invoke auto-saving before stopping the DocBroker
polling loop, whether due to idleness or server recycling.

Change-Id: I257d55f190d3df6a3ba82f2666c7602da0581d0c
Reviewed-on: https://gerrit.libreoffice.org/47887
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 
(cherry picked from commit f7fc3f494ca824253a2af6ad604622bcd1340b81)
Reviewed-on: https://gerrit.libreoffice.org/48344
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 03d0676b..bba4b8bb 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -275,8 +275,12 @@ void DocumentBroker::pollThread()
 
 if (ShutdownRequestFlag)
 {
-autoSave(true);
-stop("recycling");
+LOG_INF("Autosaving DocumentBroker for docKey [" << getDocKey() << 
"] to recycle server.");
+if (!autoSave(isPossiblyModified()))
+{
+LOG_INF("Terminating DocumentBroker for docKey [" << 
getDocKey() << "] to recycle server.");
+stop("recycling");
+}
 }
 else if (AutoSaveEnabled && !_stop &&
  std::chrono::duration_cast(now - 
last30SecCheckTime).count() >= 30)
@@ -287,14 +291,22 @@ void DocumentBroker::pollThread()
 }
 
 // Remove idle documents after 1 hour.
-const bool idle = (getIdleTimeSecs() >= IdleDocTimeoutSecs);
-
-// If all sessions have been removed, no reason to linger.
-if ((isLoaded() || _markToDestroy) && (_sessions.empty() || idle))
+const bool idle = (isLoaded() && getIdleTimeSecs() >= 
IdleDocTimeoutSecs);
+if (idle)
+{
+// Stop if there is nothing to save.
+LOG_INF("Autosaving idle DocumentBroker for docKey [" << 
getDocKey() << "] to kill.");
+if (!autoSave(isPossiblyModified()))
+{
+LOG_INF("Terminating idle DocumentBroker for docKey [" << 
getDocKey() << "].");
+stop("idle");
+}
+}
+else if (_sessions.empty() && (isLoaded() || _markToDestroy))
 {
-LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
-" DocumentBroker for docKey [" << getDocKey() << "].");
-stop(idle ? "idle" : "dead");
+// If all sessions have been removed, no reason to linger.
+LOG_INF("Terminating dead DocumentBroker for docKey [" << 
getDocKey() << "].");
+stop("dead");
 }
 }
 
@@ -864,8 +876,8 @@ bool DocumentBroker::autoSave(const bool force)
 std::string savingSessionId;
 for (auto& sessionIt : _sessions)
 {
-// Save the document using first session available ...
-if (savingSessionId.empty())
+// Save the document using an editable session, or first ...
+if (savingSessionId.empty() || !sessionIt.second->isReadOnly())
 {
 savingSessionId = sessionIt.second->getId();
 }
@@ -1058,7 +1070,7 @@ size_t DocumentBroker::removeSession(const std::string& 
id)
 ", LastEditableSession: " << lastEditableSession);
 
 // If last editable, save and don't remove until after uploading to 
storage.
-if (!lastEditableSession || !autoSave(true))
+if (!lastEditableSession || !autoSave(isPossiblyModified()))
 removeSessionInternal(id);
 }
 catch (const std::exception& ex)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 1e8e0746..1571e426 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -367,6 +367,11 @@ private:
 /// True iff a save is in progress (requested but not completed).
 bool isSaving() const { return _lastSaveResponseTime < 
_lastSaveRequestTime; }
 
+/// True if we know the doc is modified or
+/// if there has been activity from a client after we last *requested* 
saving,
+/// since there are race conditions vis-a-vis user activity while saving.
+bool isPossiblyModified() const { return _isModified || 
(_lastSaveRequestTime < _lastActivityTime); }
+
 /// True iff there is at least one non-readonly session other than the 
given.
 /// Since only editable sessions can save, we need to use the last to
 /// save modified 

[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.hpp

2018-01-22 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   13 +
 wsd/DocumentBroker.hpp |   10 +-
 wsd/Storage.hpp|2 +-
 3 files changed, 19 insertions(+), 6 deletions(-)

New commits:
commit f4dc93f55c74f28ab45cb1bf0edf7c2ee2a4ef6e
Author: Ashod Nakashian 
Date:   Sun Jan 14 18:59:11 2018 -0500

wsd: separate lastSaveTime from lastSaveResponseTime

Previously we assumed we are saving based on
lastSaveTime, which is incorrect because it
is set only upon successful saving and storing,
which might fail.

Now lastSaveResponseTime is used to track whether
there are saving requests in flight. And lastSaveTime
is only used when we do store the document in storage.

Change-Id: I73e5c04432981d0cca11b8cf854414738bd894de
Reviewed-on: https://gerrit.libreoffice.org/47884
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 
(cherry picked from commit 8ad29ee05006899a256016ed2ba00720dfc9b79f)
Reviewed-on: https://gerrit.libreoffice.org/48342
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 67c406b4..a9b62924 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -258,7 +258,7 @@ void DocumentBroker::pollThread()
 adminRecv = recv;
 }
 
-if (_lastSaveTime < _lastSaveRequestTime &&
+if (isSaving() &&
 std::chrono::duration_cast
 (now - _lastSaveRequestTime).count() <= COMMAND_TIMEOUT_MS)
 {
@@ -693,6 +693,9 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 {
 assertCorrectThread();
 
+// Record that we got a response to avoid timeing out on saving.
+_lastSaveResponseTime = std::chrono::steady_clock::now();
+
 const bool isSaveAs = !saveAsPath.empty();
 
 // If save requested, but core didn't save because document was unmodified
@@ -732,7 +735,6 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 // Nothing to do.
 LOG_DBG("Skipping unnecessary saving to URI [" << uri << "] with 
docKey [" << _docKey <<
 "]. File last modified " << _lastFileModifiedTime.elapsed() / 
100 << " seconds ago.");
-_lastSaveTime = std::chrono::steady_clock::now();
 _poll->wakeup();
 return true;
 }
@@ -745,13 +747,13 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 {
 if (!isSaveAs)
 {
+// Saved and stored; update flags.
 setModified(false);
 _lastFileModifiedTime = newFileModifiedTime;
 _tileCache->saveLastModified(_lastFileModifiedTime);
 _lastSaveTime = std::chrono::steady_clock::now();
-_poll->wakeup();
 
-// So set _documentLastModifiedTime then
+// Save the storage timestamp.
 _documentLastModifiedTime = _storage->getFileInfo()._modifiedTime;
 
 // After a successful save, we are sure that document in the 
storage is same as ours
@@ -760,6 +762,9 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 Log::debug() << "Saved docKey [" << _docKey << "] to URI [" << uri
  << "] and updated tile cache. Document modified 
timestamp: "
  << _documentLastModifiedTime << Log::end;
+
+// Resume polling.
+_poll->wakeup();
 }
 else
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 18c6e624..0b8153ad 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -364,6 +364,9 @@ private:
 /// Saves the doc to the storage.
 bool saveToStorageInternal(const std::string& sesionId, bool success, 
const std::string& result = "", const std::string& saveAsPath = std::string(), 
const std::string& saveAsFilename = std::string());
 
+/// True iff a save is in progress (requested but not completed).
+bool isSaving() const { return _lastSaveResponseTime < 
_lastSaveRequestTime; }
+
 /// True iff there is at least one non-readonly session other than the 
given.
 /// Since only editable sessions can save, we need to use the last to
 /// save modified documents, otherwise we'll potentially have to save on
@@ -408,14 +411,19 @@ private:
 /// document was modified and saved or not.
 std::chrono::steady_clock::time_point _lastSaveTime;
 
-/// The last time we sent a save request.
+/// The last time we sent a save request to lokit.
 std::chrono::steady_clock::time_point _lastSaveRequestTime;
 
+/// The last time we received a response for a save request from lokit.
+std::chrono::steady_clock::time_point _lastSaveResponseTime;
+
 /// The document's last-modified time on storage.
 

[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2018-01-22 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |2 +-
 wsd/DocumentBroker.hpp |1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

New commits:
commit a96f4f60e43c9c94cd4fa98b794d338b223d769b
Author: Ashod Nakashian 
Date:   Wed Jan 3 23:15:44 2018 -0500

wsd: set modified flag on the storage when set on the DocumentBroker

Change-Id: Ieb4eb02f68f2d02ad88d6f59ad61de8f1e309670
Reviewed-on: https://gerrit.libreoffice.org/47365
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 
(cherry picked from commit 040a211d60c6eab8695cad4bee78b22f38428b77)
Reviewed-on: https://gerrit.libreoffice.org/48339
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6c6da1f5..91c17862 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1408,7 +1408,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 
 void DocumentBroker::setModified(const bool value)
 {
-if(_isModified != value)
+if (_isModified != value)
 {
 _isModified = value;
 Admin::instance().modificationAlert(_docKey, getPid(), value);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index a56d3332..0e278150 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -248,6 +248,7 @@ public:
 
 bool isModified() const { return _isModified; }
 void setModified(const bool value);
+
 /// Save the document if the document is modified.
 /// @param force when true, will force saving if there
 /// has been any recent activity after the last save.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - wsd/DocumentBroker.cpp

2018-01-15 Thread Michael Meeks
 wsd/DocumentBroker.cpp |7 +++
 1 file changed, 7 insertions(+)

New commits:
commit 0da449bbd9968fb580b90fbeb0672437b7f5f832
Author: Michael Meeks 
Date:   Fri Jan 12 16:16:56 2018 +

Warn if we exit with a modified document around.

Change-Id: Ie38ab49c66358f674e14820a6ffa993c25aa9e92
Reviewed-on: https://gerrit.libreoffice.org/47822
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f149f36c..6c6da1f5 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -297,6 +297,13 @@ void DocumentBroker::pollThread()
 _poll->continuePolling() << ", ShutdownRequestFlag: " << 
ShutdownRequestFlag <<
 ", TerminationFlag: " << TerminationFlag << ".");
 
+if (_isModified)
+{
+std::stringstream state;
+dumpState(state);
+LOG_ERR("DocumentBroker stopping although modified " << state.str());
+}
+
 // Flush socket data first.
 const int flushTimeoutMs = POLL_TIMEOUT_MS * 2; // ~1000ms
 const auto flushStartTime = std::chrono::steady_clock::now();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits