From 6586c2a43ebf5ce440784a586a807305c9f3ebab Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Fri, 11 Mar 2022 09:47:08 +0800 Subject: [PATCH] add doc to debug --- README.md | 4 + docs/how_to_debug/README.md | 11 +++ docs/how_to_debug/check_console_output.md | 17 ++++ docs/how_to_debug/export_sync_plans.md | 95 +++++++++++++++++++++++ docs/sync_algorithm_v2.md | 2 + 5 files changed, 129 insertions(+) create mode 100644 docs/how_to_debug/README.md create mode 100644 docs/how_to_debug/check_console_output.md create mode 100644 docs/how_to_debug/export_sync_plans.md diff --git a/README.md b/README.md index ce26241..2f252fb 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,10 @@ Additionally, the plugin author may occasionally visit Obsidian official forum a - In auto sync mode, if any error occurs, the plugin would **fail silently**. - Auto sync only works when Obsidian is being opened. It's **technically impossible** to auto sync while Obsidian is in background, because the plugin just works in the browser environment provided by Obsidian. +## How To Debug + +See [here](./docs/how_to_debug/README.md) for more details. + ## Bonus: Import And Export Not-Oauth2 Plugin Settings By QR Code See [here](./docs/import_export_some_settings.md) for more details. diff --git a/docs/how_to_debug/README.md b/docs/how_to_debug/README.md new file mode 100644 index 0000000..a41d390 --- /dev/null +++ b/docs/how_to_debug/README.md @@ -0,0 +1,11 @@ +# How To Debug + +Ideally, users do not need to debug anything. But if something bad happened, we have to dig into details. + +## Easy: Export Sync Plans + +See [here](./export_sync_plans.md). + +## Advanced: Check Console Output + +See [here](./check_console_output.md). diff --git a/docs/how_to_debug/check_console_output.md b/docs/how_to_debug/check_console_output.md new file mode 100644 index 0000000..28b5ff0 --- /dev/null +++ b/docs/how_to_debug/check_console_output.md @@ -0,0 +1,17 @@ +# Check Console Output + +If you are using Obsidian on desktop, you can check the Obsidian console. + +## Disable Auto Sync Firstly + +You should disable auto sync to avoid any unexpected running. + +## Set The Output Level To Debug + +Go to the plugin settings, scroll down to the section "Debug" -> "alter console log level", and change it from "info" to "debug". + +## Check The Output + +Then, press the keyboard shortcut "ctrl+shift+i" if you are on Windows or Linux, or press "cmd+shift+i" if you are on macOS. You should be able to see the console of Obsidian. + +Trigger the sync manually (by clicking the icon on the ribbon sidebar). Something (hopefully) helpful should show up in the console. You could understand what happened and what goes wrong more explictly by checking the output. diff --git a/docs/how_to_debug/export_sync_plans.md b/docs/how_to_debug/export_sync_plans.md new file mode 100644 index 0000000..894e697 --- /dev/null +++ b/docs/how_to_debug/export_sync_plans.md @@ -0,0 +1,95 @@ +# Export Sync Plans + +## What's this? + +Everytime the plugin starts a sync, it gathers all required information together, generates a "sync plan" of every operations to every files and folders, and assign the corresponding actual operations. + +Thus, if something goes wrong, we should check the sync plan firstly. + +## How To Export The Plans? + +Please read through the following instructions. + +### Disable Auto Sync Firstly + +You should disable auto sync to avoid any unexpected running. + +### Manual Sync If Not Yet + +You should at least sync once, so that at least one sync plan is generated and saved. If you have synced the vualt before, there should be some sync plans already saved. + +### Export To The File + +Go to the plugin settings, scroll down to the section "Debug" -> "export sync plans", and click the button "Export". \*\*It would generate a new folder `_debug_remotely_save/` in your vault, and generate a file `sync_plans_hist_exported_on_{a_timestamp},md.` inside that folder. + +## How To Read The Plans + +Open the genrated `sync_plans_hist_exported_on_{a_timestamp},md.`. You should see a json, or multiple jsons. Every json represents a sync plan. + +A sync plan looks like this: + +```json +{ + "ts": 1646960867560, + "remoteType": "onedrive", + "mixedStates": { + "abc.md": { + "key": "abc.md", + "existRemote": true, + "mtimeRemote": 1646566632000, + "sizeRemote": 56797, + "remoteEncryptedKey": "abc.md", + "changeMtimeUsingMapping": true, + "existLocal": true, + "mtimeLocal": 1646566632000, + "sizeLocal": 56797, + "decision": "skipUploading", + "decisionBranch": 1 + }, + "New folder/": { + "key": "New folder/", + "deltimeRemote": 1646925354372, + "existLocal": false, + "existRemote": false, + "decision": "keepRemoteDelHistFolder", + "decisionBranch": 9 + } + } +} +``` + +We usually care about the `mixedStates` property. As you may guess, every item in `mixedStates` represent a file or a folder. + +We should find out the file/folder we are interested in (or we believe something goes wrong), then checkout the following properties: + +``` +decision + What decision is made. + +decisionBranch + It's a mark of the actual logic in the sync code. Useful to debug. + +existRemote + Does the file/folder exist on the remote service? + +mtimeRemote + The "last modeified time" on the remote service. + +deltimeRemote + The "deletion time" on the remote record. + +existLocal + Does the file/folder exist locally? + +mtimeLocal + The max of "last modeified time" and "creation time" locally. + +deltimeLocal + The "deletion time" locally. +``` + +The `decision` SHOULD be determined by the modified times and deletion times, by the logic described in [the doc of sync alogorithm](../sync_algorithm_v2.md). In short, we collect four timestamps (`mtimeRemote`, `deltimeRemote`, `mtimeLocal`, `deltimeLocal`), and respect the max timestamp and its corresponding operation. + +## Common Issues + +Some users report that their "last modeified time"s or "creation time"s are not set correctly by the operating system. In this case, the plugin cannot do anything because it determines the sync plan by comparing the timestamps. It's suggested to check the settings of the operating system or check whether other programs are doing something to the files. diff --git a/docs/sync_algorithm_v2.md b/docs/sync_algorithm_v2.md index 4b8405f..a8acbc9 100644 --- a/docs/sync_algorithm_v2.md +++ b/docs/sync_algorithm_v2.md @@ -17,6 +17,8 @@ We list all combinations mutually exclusive and collectively exhaustive. ### Files +In short, we collect four timestamps, and respect the max timestamp and its corresponding operation. + | t1 | t2 | t3 | t4 | local file to do | remote file to do | local del history to do | remote del history to do | equal to sync v2 branch | | -------------- | -------------- | -------------- | -------------- | ---------------- | ----------------- | ----------------------- | ------------------------ | ----------------------- | | mtime_remote | mtime_local | deltime_remote | deltime_local | del_if_exists | del_if_exists | clean | upload_local_del_history | |