-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Sometimes
Description
I have a database with a very limited amount of used bytes, although the overall file size is well over 50 MB. I expected this database to compacted on launch by using RealmConfiguration.Builder(....).compactOnLaunch(), but that didn't happen.
Checking the documentation of DEFAULT_COMPACT_ON_LAUNCH_CALLBACK, I see this comment:
> The default implementation for determining if a file should be compacted or not. This implementation will only trigger if the file is above 50 MB and 50% or more of the space can be reclaimed.
But it seems that the current implementation is checking if less than 50% can be reclaimed, so the other way around than described in the comment.
Adding the last assertion to the unit test confirms this:
@Test fun `doCompact test`() = runTest { assertEquals(false, LocalStorageInitializer.doCompact(50 * 1024 * 1024, 40 * 1024 *1024)) // not > 50MB and < 50% reclaimable -> should be false assertEquals(false, LocalStorageInitializer.doCompact(50 * 1024 * 1024 + 8, 25 * 1024 * 1024)) // > 50MB and > 50% reclaimable -> should be true assertEquals(false, LocalStorageInitializer.doCompact(50 * 1024 * 1024 + 8, 25 * 1024 * 1024 + 3)) // > 50MB and > 50% reclaimable -> should be true assertEquals(true, LocalStorageInitializer.doCompact(50 * 1024 * 1024 + 8, 25 * 1024 * 1024 + 4)) // > 50MB and >= 50% reclaimable -> should be true assertEquals(true, LocalStorageInitializer.doCompact(50 * 1024 * 1024 + 8, 25 * 1024 * 1024 + 5)) // > 50MB and < 50% reclaimable -> should be false // adding the following test, more than 50MB filesize and 25 bytes used, should be compacted assertEquals(true, LocalStorageInitializer.doCompact(50 * 1024 * 1024 + 8, 25)) // > 50MB and > 50% reclaimable -> should be true }
Stacktrace & log output
N/A
Can you reproduce the bug?
Always
Reproduction Steps
Use the unit test doCompact test, that currently exists in the codebase.
Version
all versions since https://github.com/realm/realm-kotlin/commit/10acd38d4c3a8dae6c3ed9ba27aeb709df4965bd
What Atlas App Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
Android 10+
Build environment
Android Studio version: 2022.2.1
Android Build Tools version: 33.0.2
Gradle version: 7.6.1