Page MenuHomePhabricator

Prepare for new connection handling
ClosedPublic

Authored by marcin on Jan 18 2024, 9:09 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 4:53 PM
Unknown Object (File)
Wed, Nov 6, 5:52 PM
Unknown Object (File)
Mon, Nov 4, 7:42 AM
Unknown Object (File)
Oct 15 2024, 1:04 PM
Unknown Object (File)
Oct 15 2024, 1:03 PM
Unknown Object (File)
Oct 15 2024, 1:03 PM
Unknown Object (File)
Oct 13 2024, 8:03 AM
Unknown Object (File)
Oct 12 2024, 8:41 PM
Subscribers

Details

Summary

This differential implements methods to create and close connection to SQLite database. It also disables WAL mode on web to prevent issues described here: https://linear.app/comm/issue/ENG-6413/error-while-processing-replace-thread-operation-disk-io-error#comment-b6ef8d83

Test Plan

Future differentials will heavily use connection handling so testing it directly is redundant. To test WAL disabling we must actually use the whole stack:

  1. Build WASM and run web app without this stack.
  2. Apply this stack, re-build WASM and run web app again. Ensure not to clear site data or not to run tests in incognito mode! Otherwise you will only test WAL disabling upon fresh db creation but not the migration.
  3. Ensure refreshing doesn't cause log-out/loss of data.

Execute test plan for native app as well since WAL is also disabled there.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

marcin edited the test plan for this revision. (Show Details)
kamil requested changes to this revision.Jan 19 2024, 6:47 AM
kamil added inline comments.
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
869–874 ↗(On Diff #35793)

not happy to see more #ifndefs... but probably there isn't anything better right now

Also, I don't think this is enough, you're planning to land this stack without any migration or logging out users?

set_up_database is called when db_version == 0 so when creating DB from scratch, for users already using DB with created schema when you land this stack probably persistence will stop working as described here, because WAL mode is persistent ( point 3.3 in docs). We probably need some sort of migration for the web to disable this.

1060 ↗(On Diff #35793)

maybe reverse this condition and early return to reduce indentation?

native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
23 ↗(On Diff #35793)

While having some constants like sqliteFilePath or sqlcipherEncryptionKeySize static makes some sense, I have the impression that having a connection itself as static seems not natural. Given that this class is only used with thread_local I think it should be safe to just have a normal field.

Not saying it is wrong, just wondering about the reasoning here

This revision now requires changes to proceed.Jan 19 2024, 6:47 AM
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
23 ↗(On Diff #35793)

In fact this differential we are not introducing static connection. We have always had static connection. If you take a look at getStorage function in creates storage_t object as static. This object keeps connection to the database internally. If you feel strongly about making connection non-static I am open to that but we should have some sort of analysis since static connection proved to be working correctly (ORM ws working correctly) so we need to be sure that we won't introduce a regression.

ashoat added inline comments.
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
869–874 ↗(On Diff #35793)

We could potentially just remove WAL mode as @atul suggested

native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
869–874 ↗(On Diff #35793)

@ashoat are you talking specifically about web or removing WAL in general?

  1. Reduce indentation in getConnection method.
  2. Implement web-specific migration to disable WAL journalling.
  3. Disable WAL journalling after succesfull restore.
marcin added inline comments.
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
1060 ↗(On Diff #35793)

I updated this diff to disable WAL on web. If you @ashoat or @atul meant to disable WAL across all platforms just let me know and I will change the behaviour.

I updated this diff to disable WAL on web. If you @ashoat or @atul meant to disable WAL across all platforms just let me know and I will change the behaviour.

I'm not sure if @atul's suggestion in this comment was meant to be web-only or across the whole codebase.

Personally, I don't feel strongly. Are there any risks in having a different approach on web vs. native?

Personally, I don't feel strongly. Are there any risks in having a different approach on web vs. native?

I don't think there are. In D10709 I ensured that WAL is disabled after restoring from native compaction.

I updated this diff to disable WAL on web. If you @ashoat or @atul meant to disable WAL across all platforms just let me know and I will change the behaviour.

I'm not sure if @atul's suggestion in this comment was meant to be web-only or across the whole codebase.

Personally, I don't feel strongly. Are there any risks in having a different approach on web vs. native?

I don’t think there’s much advantage on any platform to using WAL given our use of SQLite. I think ROLLBACK mode is perfectly fine and it would be good to keep things consistent throughout.

(typed this out earlier, but looks like I didn’t submit)

Disable WAL on native as well

kamil added inline comments.
native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
480 ↗(On Diff #36375)

it feels more like enable_ rollback_journal_mode but not feel strongly - and not sure why we need _web suffix

This revision is now accepted and ready to land.Feb 2 2024, 3:24 AM

Rename disable WAL to enable_rollback_journal_mode.

This revision was automatically updated to reflect the committed changes.