QOwnNotes icon indicating copy to clipboard operation
QOwnNotes copied to clipboard

Metadata file 'notes.sqlite' causes sync conflict with multiple clients

Open brainchild0 opened this issue 7 years ago • 73 comments

Expected behaviour

Multiple instances of client connect to same remote endpoint without any synchronization conflicts, except when the same note has been modified on both sides.

Actual behaviour

File notes.sqlite is reported as synchronization conflict.

Steps to reproduce

Configure an instances of QOwnNotes on each of two systems, to connect to the same location in the same Nextcloud instance. Configure Nextcloud clients on each system also to synchronize those locations.

Suggestion

Store tag, trash, and related metadata in a separate configuration directory. Also possible to use a hidden file file, although Nextcloud clients can be configured to synchronize hidden files, thereby reintroducing the same problem.

Workaround

Per site, clients can be configured to exclude files based on name patterns.

brainchild0 avatar Jan 10 '19 08:01 brainchild0

Is there something that can be done in QOwnNotes? Seems like either a Nextcloud behavior or a problem with or a "maximum open file handler" problem where the operating system doesn't report that the file notes.sqlite or its folder was modified. QOwnNotes would reload the note folder if it was modified.

pbek avatar Jan 10 '19 08:01 pbek

Maybe it has something to do that the database file is opened by QOwnNotes (Qt Sqlite Engine). On Windows I have a settings where I attempt to close it after operations, but that was quite experimental. A lot of bad stuff can happen there...

https://github.com/pbek/QOwnNotes/blob/14948f105b26c50dd3f62b97edec47a016af3545/src/services/databaseservice.cpp#L323-L338

pbek avatar Jan 10 '19 09:01 pbek

Also see https://github.com/pbek/QOwnNotes/issues/926

pbek avatar Jan 10 '19 09:01 pbek

I think the central issue is that the file contains the metadata for all notes, not just one note. So for note contents, a conflict occurs only if the same note is modified in multiple locations, whereas the metadata file can conflict if any metadata is modified. Also, boundary cases can occur that users may not anticipate, creating a lower quality of experience. For example suppose a user configures a new QOwnNotes client and points it to an empty notes directory, 'then' configures the files synchronization cleint. If a metadata file is already created in the otherwise empty location, then it is a conflict. (I think that is what I observed, in my case. If you think I am mistaken then I can try to reproduce.)

brainchild0 avatar Jan 10 '19 09:01 brainchild0

Maybe you can start by posting the rest of the requirements of the issue template to see where you were testing. :wink:

pbek avatar Jan 10 '19 09:01 pbek

I could try to reproduce with the log pane open, but the fact is I never witnessed QOwnNotes misbehave or even complain. The only bad thing that happened was the Nextcloud client complaining of a conflict.

brainchild0 avatar Jan 10 '19 09:01 brainchild0

Still, seeing the content of your Debug settings would be nice to help you... :smile:

pbek avatar Jan 10 '19 09:01 pbek

I would like to provide further needed information, but I am not sure what to do. I consider the problem I describe is independent of whether QOwnNotes is even running. I don't know how to get QOwnNotes to report any problems, or why I would try.

Perhaps I did not adequately explain the problem.

If I configure the Nextcloud Desktop Client to synchronize a folder, and if both the client and server have files of the same name and location, but different data, from before the synchronization was configured, then the client reports a conflict. Such is the behavior of the client, and I do not consider this behavior incorrect, because it is the only way the client can avoid data loss in general.

Thus, if I have a server that is already synchronized against a client, and that client has created a database file, and then I install the application on a second client, and configure QOwnNotes before configuring the Nextcloud file synchronization, then QOwnNote will create a new database, and the server and the client will find conflicting files of the same name at the time of the first synchronization attempt. The client has a new database, and the server has preexisting one from the other client. As synchronization has never occurred before, Nextcloud client has no means to resolve which version is new and which out of date.

QOwnNotes may be smart enough to work with other copies of itself, but the user experience will be that Nextcloud reports an error.

If you feel this issue is not worth resolving, then I understand, but at least it is now reported.

brainchild0 avatar Jan 15 '19 04:01 brainchild0

Still, seeing the content of your Debug settings would be nice to help you... smile

Open the settings, click on Debug

pbek avatar Jan 15 '19 10:01 pbek

I reproduced, and created a log recording the events surrounding the point when the Nextcloud client reports the conflict. I hope it is helpful to you.

qon.log

brainchild0 avatar Jan 16 '19 01:01 brainchild0

Thank you, but nothing very unusual is happening there. And I still don't know anything about your operating system and configuration.

pbek avatar Jan 16 '19 05:01 pbek

I agree, nothing unusual is happening. My OS is Linux Mint. I don't know what features of my configuration interest you, but your emphasizing those details suggests to me that we are not communicating effectively.

The effects I have described are design features of Nextcloud. They are not OS-dependent. It is clear that if the user creates a synchronization folder on the client, and the folders on the client and desktop at that time have different versions of the same file, then the client reports a conflict.

This behavior is correct, but if conflicts with design of QOwnNotes.

brainchild0 avatar Jan 16 '19 06:01 brainchild0

I don't have this issue on KDE Neon or Manjaro with the Nextcloud sync client.

pbek avatar Jan 16 '19 06:01 pbek

Once the synchronization is configured and active, then the issue would not occur. It is a special case at the time of configuring a new instance, and even then only when QOwnNotes is configured before the Nextcloud client is configured.

Have you tried the steps in this sequence, then reviewed the Nextcloud client log?

brainchild0 avatar Jan 16 '19 06:01 brainchild0

There can only be tho things happening.

  • a lock on the sqlite database file because Qt keeps it open (see #926)
  • too many files open by inotify

Both are hard to get around.

pbek avatar Jan 16 '19 06:01 pbek

I don't understand why you say there can only be two things happening. How did you conclude that, especially when I explained exactly what is happening, and why it's happening, without invoking either of these cases?

Try an experiment. Create a folder on your Nextcloud server, populate it with a file called test.txt, and write "Hello" in the body of the file. Then create a folder on your desktop, add a file called test.txt (same name as on server), and write "Goodbye" in the body of the file. Now configure your Nextcloud client to synchronize the two folders.

Does the client report a conflict before finishing the synchronization? It should. Otherwise, which is correct? "Hello"? "Goodbye"? The client can't know.

I did this experiment earlier. It took only a few minutes.

brainchild0 avatar Jan 16 '19 07:01 brainchild0

I did this experiment earlier. It took only a few minutes.

I can, if you can tell me what it has to do with QOwnNotes. :laughing:

pbek avatar Jan 16 '19 14:01 pbek

It is a lower quality of user experience if QOwnNotes is generating results that cause Nextcloud to complain.

If you change the above experiment by substituting test.txt with notes.sqlite, substituting "Hello" with a user's pre-existing database, and substituting "Goodbye" with the new database from the newly-configured client instance, then I think you understand how the issue is related to QOwnNotes.

You may feel that the boundary case is too insignificant to merit changing the design, but I still wanted to report the behavior to make it a known issue/limitation.

brainchild0 avatar Jan 17 '19 04:01 brainchild0

I'm sorry, I cannot change the design of how Qt works with sqlite databases and even bad things happened when I tried to close the database after queries (see #926).

pbek avatar Jan 17 '19 05:01 pbek

The behavior occurs whether or not QOwnNotes is actively running. It is not a question of whether a database connection or file handle is open. It is a question of whether a version of the database is introduced into a shared folder that is not recognized by the client as a derivative of the one previously on the server.

Consider the following steps:

  1. Create an empty directory called <notesdir>.
  2. Create a clean installation of QOwnNotes.
  3. Open the application and configure the notes location to <notesdir>. (The application immediately creates <notesdir>/notes.sqlite.)
  4. Close the application.
  5. Configure a share with the Nextcloud client to synchronize <notesdir> with an existing notes repository on the server.
  6. Synchronize the share. (Nextcloud client complains about the conflicting versions of <notesdir>/notes.sqlite).

QOwnNotes is not running, but it has placed data on the file system in such a way that Nextcloud is unhappy.

brainchild0 avatar Jan 17 '19 05:01 brainchild0