Commit Graph

64 Commits

Author SHA1 Message Date
Dimitri Papadopoulos 66bc911652
chore: fix typos found by codespell 2023-07-07 15:31:14 +02:00
Leander Beernaert 4352154b84 test: Force sync limits to minimum with env variable
Set `BRIDGE_SYNC_FORCE_MINIMUM_SPEC` as environment variable to force
all the sync limits to minimum spec.

This is enabled for windows builds.
2023-06-29 13:31:03 +02:00
Leander Beernaert b7a2371220 chore: Log failed message ids during sync 2023-06-22 11:05:36 +00:00
Leander Beernaert 12f9fb03c3 chore: Log errors on failed message Downloads 2023-06-07 16:38:57 +02:00
Leander Beernaert ade2fd9403 chore: Add error logs when messages fail to build during sync 2023-06-02 13:17:08 +02:00
Leander Beernaert 0417e495ae fix(GODT-2618): Crash when address does not have unlocked keyring 2023-05-09 08:31:28 +02:00
Leander Beernaert a0db1645f2 fix(GODT-2614): Handle failed update during sync
The sync process was getting stuck since we never handled the case where
the update to Gluon failed. This caused the flush stage to exist, but
the sync process would continue until it eventually gets stuck due to
lack of progress.
2023-05-05 16:09:23 +02:00
Xavier Michelon b51d85e768 chore: upgraded golangci-lint v1.52.2 and fixed all issues. 2023-05-05 07:57:22 +02:00
Jakub 7bb925b6d7 feat(GODT-2502): Improve logs. 2023-04-14 10:27:37 +02:00
Jakub 7330406752 fix(GODT-2500): Recover in deferred function. 2023-04-05 09:25:24 +02:00
Jakub de5fd07a22 feat(GODT-2500): Reorganise async methods. 2023-04-03 07:07:22 +02:00
Jakub ec92c918cd feat(GODT-2500): Add panic handlers everywhere. 2023-04-03 06:38:31 +02:00
Leander Beernaert 91ab77dce9 fix(GODT-2424): Sync Builder Message Split
Incorrect math was causing some messages to not be built and be missing
from Gluon.
2023-03-01 13:13:20 +01:00
James Houlahan da82d7a107 fix(GODT-2365): Use predictable remote ID for placeholder mailboxes 2023-02-15 10:42:47 +01:00
Xavier Michelon 0823d393ed
feat(GODT-1264): creation and visibility of the 'Scheduled' system label.
feat(GODT-1264): typo in error message
feat(GODT-1264): fix split mode broken by previous commit.
2023-02-10 15:24:31 +01:00
James Houlahan 34cd611a8b chore: Disable funlen linter 2023-02-06 14:29:13 +00:00
James Houlahan e2c1f38ed3 fix(GODT-2328): Ignore labels that aren't part of user label set 2023-02-02 15:39:33 +00:00
Leander Beernaert fbac5134ca fix(GODT-2224): Properly handle context cancellation during sync
There was an issue where new attachment download requests would hang
forever due to not checking whether the context was cancelled. At this
point there were no more workers to consume to channel messages.
2023-02-01 15:08:41 +01:00
Leander Beernaert 4577a40b1e fix(GODT-2224): Restore parallel attachment download
Feature was not restored in previous MR. Attachment are now download in
parallel. There is a pool of maxParallelDownloads attachment downloaders
shared with all message downloads.
2023-01-31 12:25:20 +01:00
Leander Beernaert c0aacb7d62 GODT-2224: Allow the user to specify max sync memory usage in Vault 2023-01-31 09:40:22 +01:00
Leander Beernaert e464e11ab9 GODT-2224: Refactor bridge sync to use less memory
Updates go-proton-api and Gluon to includes memory reduction changes and
modify the sync process to take into account how much memory is used
during the sync stage.

The sync process now has an extra stage which first download the message
metada to ensure that we only download up to `syncMaxDownloadRequesMem`
messages or 250 messages total. This allows for scaling the download
request automatically to accommodate many small or few very large
messages.

The IDs are then sent to a download go-routine which downloads the
message and its attachments. The result is then forwarded to another
go-routine which builds the actual message. This stage tries to ensure
that we don't use more than `syncMaxMessageBuildingMem` to build these
messages.

Finally the result is sent to a last go-routine which applies the
changes to Gluon and waits for them to be completed.

The new process is currently limited to 2GB. Dynamic scaling will be
implemented in a follow up. For systems with less than 2GB of memory we
limit the values to a set of values that is known to work.
2023-01-30 15:05:43 +01:00
Leander Beernaert 93c7552a41 GODT-2202: Report update errors from Gluon
For every update sent to gluon wait and check the error code to see if
an error occurred.

Note: Updates can't be inspect on the call site as it can lead to
deadlocks.
2023-01-13 15:54:31 +01:00
Leander Beernaert 6d0a128111 Other: Update copyright year 2023-01-02 11:09:11 +01:00
James Houlahan 75c88eaa55 GODT-2187: Handle unbuildable messages in event loop 2022-12-06 19:27:55 +01:00
James Houlahan bd6ae2ac2b GODT-2187: Placeholder for unbuildable messages 2022-12-06 16:35:32 +01:00
James Houlahan 58d04f9693 GODT-2187: Skip messages during sync that fail to build/parse 2022-12-06 14:07:13 +00:00
Leander Beernaert 2cd7735468 Other: Do not list \Deleted flag for All Mail 2022-12-02 14:59:52 +01:00
James Houlahan b7be599769 GODT-2151: Sync backwards to please product people 2022-11-24 13:04:00 +01:00
James Houlahan e601245f01 Other(chore): Bump major version to v3 2022-11-23 16:08:27 +01:00
James Houlahan ad1fb47b0d Other: Switch from liteapi to go-proton-api 2022-11-23 15:17:56 +01:00
James Houlahan f2db2b9b1d GODT-2085: Use time.Since, structured logging 2022-11-22 16:14:25 +01:00
Leander Beernaert 4b6d0d035e GODT-2085: Ensure minimum sync worker count
Make sure that we are at least using 16 workers for sync, otherwise
multiply the current sync worker count by 2.

Finally, this patch also logs the duration of the time it takes to
transfer all the messages from the server.
2022-11-22 15:02:52 +00:00
Leander Beernaert 0df4f41269 Other: Remove unused SyncBuffers setting 2022-11-22 13:59:06 +01:00
Leander Beernaert a2ab5df7ce GODT-2085: Revise sync algorithm
Revise syncing work distribution. Sync time can be reduced by up to 50%.

Rework the sync so that it pipelines better with bigger batch counts at
each stage. We now use 3 separate stages: Download, Updates and Sync.

The Download stage downloads messages in maxBatchSize intervals using
1.5x syncWorkers. Once the current batch has finished downloading it's
forwarded to the Updates stage and we proceed to download the next
batch.

The Update stage converts everything into gluon updates and prepares a
collection of noops that the sync stage can wait on for termination.

Finally the sync stage waits until the updates have been applied in
Gluon so that the vault information can be updated. We allow up to 4
pending wait operations to be queued currently to not block the
pipeline.
2022-11-22 12:32:47 +00:00
James Houlahan eb62056755 GODT-2119: Only show supported label IDs to clients 2022-11-21 17:15:51 +00:00
James Houlahan a240c4531a Other: Bump max update and batch size to 256 MiB / 256 respectively 2022-11-19 16:06:25 +01:00
James Houlahan 1e48ab4b9c GODT-2047: Clear last event ID when clearing sync status 2022-11-17 13:18:47 +00:00
James Houlahan 48cf89b1a6 Other: Use cached labels for label sync rather than refetch 2022-11-16 13:48:31 +01:00
James Houlahan 739fe826b3 GODT-2048: Add missing special use attributes 2022-11-16 13:48:30 +01:00
James Houlahan c548ba85fe Other: Add more extensive logging 2022-11-16 13:48:30 +01:00
James Houlahan bc7912e8fb GODT-2022: Fix change between address modes 2022-11-16 13:48:30 +01:00
James Houlahan 99745ac067 Other: Switch to faster message IDs route
The new API route lets us query exactly which message IDs a user has,
allowing us to begin syncing much faster than before.
2022-11-16 13:48:30 +01:00
James Houlahan 3c4e8730ac Other: Read sync workers setting from vault 2022-11-16 13:48:30 +01:00
James Houlahan d4da325e57 Other(refactor): Sort safe.Mutex types before locking to prevent deadlocks
This change implements safe.Mutex and safe.RWMutex, which wrap the
sync.Mutex and sync.RWMutex types and are assigned a globally unique
integer ID. The safe.Lock and safe.RLock methods sort the mutexes
by this integer ID before locking to ensure that locks for a given
set of mutexes are always performed in the same order, avoiding
deadlocks.
2022-11-16 13:48:30 +01:00
James Houlahan fd80848fcd Other(refactor): Use normal value + mutex for user.updateCh 2022-11-16 13:48:30 +01:00
James Houlahan 0bc99dbd4f Other(refactor): Use normal value + mutex for user.apiAddrs 2022-11-16 13:48:30 +01:00
James Houlahan 828385b049 Other: Fix user sync leaks/race conditions
This fixes various race conditions and leaks related to the user's sync
and API event stream. It was possible for a sync/stream to begin after a
user was already closed; this change prevents that by managing the
goroutines related to sync/stream within cancellable groups.
2022-11-16 13:48:30 +01:00
James Houlahan 81f4ef609b Other: Mitigate double-unlock of user keyring
We need to unlock the user keyring anyway to unlock the address keyring,
so we should just return it instead of re-unlocking the user keyring
when sending a message.
2022-11-16 13:48:30 +01:00
James Houlahan 1729c085c7 Other: Fix user logout hangs due to sync 2022-11-16 12:26:09 +01:00
James Houlahan bf29090ffa Other: Fix log message, rename test fixture 2022-11-16 12:26:09 +01:00