Skip to content

Commit

Permalink
Improve doc and code comments
Browse files Browse the repository at this point in the history
Co-authored-by: Christoph <[email protected]>
  • Loading branch information
koppor and Siedlerchr committed Oct 3, 2024
1 parent 35d6411 commit f4f40c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 13 additions & 2 deletions docs/code-howtos/remote-storage-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ For user documentation, see <https://docs.jabref.org/collaborative-work/sqldatab

## Handling large shared databases

Synchronization times may get long when working with a large database containing several thousand entries. Therefore, synchronization only happens if several conditions are fulfilled:
Synchronization times may get long when working with a large database containing several thousand entries.
Therefore, we use PostgreSQL's `LISTEN` and `NOTIFY` commands to inform the client about changes in the database on an entry level.

Background reading: <https://www.baeldung.com/spring-postgresql-message-broker>.

## Handling synchronization of "micro-edits"

It causes too much load both on the server and at all subscribed clients to synchronize every single letter change.
Therefore, synchronization only happens if several conditions are fulfilled:

* Edit to another field.
* Major changes have been made (pasting or deleting more than one character).

Class `org.jabref.logic.util.CoarseChangeFilter.java` checks both conditions.

Remaining changes that have not been synchronized yet are saved at closing the database rendering additional closing time. Saving is realized in `org.jabref.logic.shared.DBMSSynchronizer.java`. Following methods account for synchronization modes:
Remaining changes that have not been synchronized yet are saved at closing the database rendering additional closing time.
Saving is realized in `org.jabref.logic.shared.DBMSSynchronizer.java`.

Following methods account for synchronization modes:

* `pullChanges` synchronizes the database unconditionally.
* `pullLastEntryChanges` synchronizes only if there are remaining entry changes. It is invoked when closing the shared database (`closeSharedDatabase`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public PostgreSQLProcessor(DatabaseConnection connection) {
*/
@Override
public void setUp() throws SQLException {

if (CURRENT_VERSION_DB_STRUCT == 1 && checkTableAvailability("ENTRY", "FIELD", "METADATA")) {
// checkTableAvailability does not distinguish if same table name exists in different schemas
// VERSION_DB_STRUCT_DEFAULT must be forced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public PostgresSQLNotificationListener(DBMSSynchronizer dbmsSynchronizer, PGConn
public void run() {
stop = false;
try {
// noinspection InfiniteLoopStatement
while (!stop) {
PGNotification notifications[] = pgConnection.getNotifications();
while (!stop && !Thread.currentThread().isInterrupted()) {
PGNotification[] notifications = pgConnection.getNotifications();

if (notifications != null) {
for (PGNotification notification : notifications) {
if (!notification.getName().equals(DBMSProcessor.PROCESSOR_ID)) {
// Only process notifications that are not sent by this processor
dbmsSynchronizer.pullChanges();
}
}
Expand Down

0 comments on commit f4f40c6

Please sign in to comment.