From 9cf6d1eab6a18e5ea733a0cf7b76d23a94b12808 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 21 Dec 2023 17:01:34 +0000 Subject: [PATCH] refactor: change default sync mode to `LOCKSTEP` --- .../william278/husksync/config/Settings.java | 4 +-- .../william278/husksync/sync/DataSyncer.java | 4 +-- docs/Config-File.md | 4 +-- docs/Sync-Modes.md | 32 +++++++++---------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/net/william278/husksync/config/Settings.java b/common/src/main/java/net/william278/husksync/config/Settings.java index 4fb01a1b..b9dcb5dd 100644 --- a/common/src/main/java/net/william278/husksync/config/Settings.java +++ b/common/src/main/java/net/william278/husksync/config/Settings.java @@ -147,10 +147,10 @@ public class Settings { // Synchronization settings - @YamlComment("The mode of data synchronization to use (DELAY or LOCKSTEP). DELAY should be fine for most networks." + @YamlComment("The data synchronization mode to use (LOCKSTEP or DELAY). LOCKSTEP is recommended for most networks." + " Docs: https://william278.net/docs/husksync/sync-modes") @YamlKey("synchronization.mode") - private DataSyncer.Mode syncMode = DataSyncer.Mode.DELAY; + private DataSyncer.Mode syncMode = DataSyncer.Mode.LOCKSTEP; @YamlComment("The number of data snapshot backups that should be kept at once per user") @YamlKey("synchronization.max_user_data_snapshots") diff --git a/common/src/main/java/net/william278/husksync/sync/DataSyncer.java b/common/src/main/java/net/william278/husksync/sync/DataSyncer.java index 900b8b5c..d202f8f3 100644 --- a/common/src/main/java/net/william278/husksync/sync/DataSyncer.java +++ b/common/src/main/java/net/william278/husksync/sync/DataSyncer.java @@ -134,8 +134,8 @@ public abstract class DataSyncer { * @since 3.1 */ public enum Mode { - DELAY(DelayDataSyncer::new), - LOCKSTEP(LockstepDataSyncer::new); + LOCKSTEP(LockstepDataSyncer::new), + DELAY(DelayDataSyncer::new); private final Function supplier; diff --git a/docs/Config-File.md b/docs/Config-File.md index a168fe49..0ad91fad 100644 --- a/docs/Config-File.md +++ b/docs/Config-File.md @@ -60,8 +60,8 @@ redis: password: '' use_ssl: false synchronization: - # The mode of data synchronization to use (DELAY or LOCKSTEP). DELAY should be fine for most networks. Docs: https://william278.net/docs/husksync/sync-modes - mode: DELAY + # The data synchronization mode to use (LOCKSTEP or DELAY). LOCKSTEP is recommended for most networks. Docs: https://william278.net/docs/husksync/sync-modes + mode: LOCKSTEP # The number of data snapshot backups that should be kept at once per user max_user_data_snapshots: 16 # Number of hours between new snapshots being saved as backups (Use "0" to backup all snapshots) diff --git a/docs/Sync-Modes.md b/docs/Sync-Modes.md index 281c48e9..4cfd9ea7 100644 --- a/docs/Sync-Modes.md +++ b/docs/Sync-Modes.md @@ -3,8 +3,8 @@ HuskSync offers two built-in **synchronization modes** that utilise Redis and My ![Overall architecture of the synchronisation systems](https://raw.githubusercontent.com/WiIIiam278/HuskSync/master/images/system-diagram.png) ## Available Modes -* The `DELAY` sync mode is the default sync mode, that use the `network_latency_miliseconds` value to apply a delay before listening to Redis data -* The `LOCKSTEP` sync mode uses a data checkout system to ensure that all servers are in sync regardless of network latency or tick rate fluctuations. This mode was introduced in HuskSync v3.1 +* The `LOCKSTEP` sync mode is the default sync mode. It uses a data checkout system to ensure that all servers are in sync regardless of network latency or tick rate fluctuations. This mode was introduced in HuskSync v3.1 +* The `DELAY` sync mode uses the `network_latency_miliseconds` value to apply a delay before listening to Redis data You can change which sync mode you are using by editing the `sync_mode` setting under `synchronization` in `config.yml`. @@ -15,11 +15,22 @@ You can change which sync mode you are using by editing the `sync_mode` setting ```yaml synchronization: - # The mode of data synchronization to use (DELAY or LOCKSTEP). DELAY should be fine for most networks. Docs: https://william278.net/docs/husksync/sync-modes - mode: DELAY + # The data synchronization mode to use (LOCKSTEP or DELAY). LOCKSTEP is recommended for most networks. Docs: https://william278.net/docs/husksync/sync-modes + mode: LOCKSTEP ``` +## Lockstep +The `LOCKSTEP` sync mode works as described below: +* When a user connects to a server, the server will continuously asynchronously check if a `DATA_CHECKOUT` key is present. + * If, or when, the key is not present, the plugin will set a new `DATA_CHECKOUT` key. +* After this, the plugin will check Redis for the presence of a `DATA_UPDATE` key. + * If a `DATA_UPDATE` key is present, the user's data will be set from the snapshot deserialized from Redis contained within that key. + * Otherwise, their data will be pulled from the database. +* When a user disconnects from a server, their data is serialized and set to Redis with a `DATA_UPDATE` key. After this key has been set, the user's current `DATA_CHECKOUT` key will be removed from Redis. + +Additionally, note that `DATA_CHECKOUT` keys are set with the server ID of the server which "checked out" the data (taken from the `server.yml` config file). On both shutdown and startup, the plugin will clear all `DATA_CHECKOUT` keys for the current server ID (to prevent stale keys in the event of a server crash for instance) + ## Delay The `DELAY` sync mode works as described below: * When a user disconnects from a server, a `SERVER_SWITCH` key is immediately set on Redis, followed by a `DATA_UPDATE` key which contains the user's packed and serialized Data Snapshot. @@ -31,15 +42,4 @@ The `DELAY` sync mode works as described below: `DELAY` has been the default sync mode since HuskSync v2.0. In HuskSync v3.1, `LOCKSTEP` was introduced. Since the delay mode has been tested and deployed for the longest, it is still the default, though note this may change in the future. -However, if your network has a fluctuating tick rate or significant latency (especially if you have servers on different hardware/locations), you may wish to use `LOCKSTEP` instead for a more reliable sync system. - -## Lockstep -The `LOCKSTEP` sync mode works as described below: -* When a user connects to a server, the server will continuously asynchronously check if a `DATA_CHECKOUT` key is present. - * If, or when, the key is not present, the plugin will set a new `DATA_CHECKOUT` key. -* After this, the plugin will check Redis for the presence of a `DATA_UPDATE` key. - * If a `DATA_UPDATE` key is present, the user's data will be set from the snapshot deserialized from Redis contained within that key. - * Otherwise, their data will be pulled from the database. -* When a user disconnects from a server, their data is serialized and set to Redis with a `DATA_UPDATE` key. After this key has been set, the user's current `DATA_CHECKOUT` key will be removed from Redis. - -Additionally, note that `DATA_CHECKOUT` keys are set with the server ID of the server which "checked out" the data (taken from the `server.yml` config file). On both shutdown and startup, the plugin will clear all `DATA_CHECKOUT` keys for the current server ID (to prevent stale keys in the event of a server crash for instance) \ No newline at end of file +However, if your network has a fluctuating tick rate or significant latency (especially if you have servers on different hardware/locations), you may wish to use `LOCKSTEP` instead for a more reliable sync system. \ No newline at end of file