Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After initiating Compact the db.realm.tmp_compaction_space temp file is not removed #4526

Closed
GitMurf opened this issue Apr 27, 2022 · 6 comments
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. Needs-Attention Reporter has responded. Review comment. O-Community T-Bug

Comments

@GitMurf
Copy link

GitMurf commented Apr 27, 2022

How frequently does the bug occur?

All the time

Description

When I run either a RealmDB.compact() OR do shouldCompactOnLaunch the Realm DB file compacts fine but it leaves behind the db.realm.tmp_compaction_space temporary file that was copied during the compaction process. The problem then is that the database size is always taking up twice as much space (as it is duplicated to the new realm db file).

Should this be being deleted automatically? Is there a setting or something I need to configure to have it deleted? Do I have to delete it myself?

image

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

As the description above says, simply initiate RealmDB.compact() OR shouldCompactOnLaunch. It leaves behind the copied temp database file.

Version

Current

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Windows 11 and Mac

Build environment

No response

Cocoapods version

No response

@fronck
Copy link

fronck commented Apr 27, 2022

@GitMurf Thanks for reporting this.

Just to clarify, have you observed this behavior on both Win and Mac, or do they behave differently?

@fronck fronck added More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Apr 27, 2022
@GitMurf
Copy link
Author

GitMurf commented May 10, 2022

@fronck sorry for the slow response. I tried to get my hands on a Mac to test with but wasn't able to. At this time I can only confirm this happens on Windows. Do you need me to try and find someone with a Mac to test this on or can you look into this with just the repro of Windows? Thanks much!

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels May 10, 2022
@kneth
Copy link
Contributor

kneth commented May 11, 2022

@GitMurf Thanks for the update. We can try to reproduce on a Mac.

@kneth
Copy link
Contributor

kneth commented May 19, 2022

@GitMurf I have not been able to reproduce it on a Mac.

First I have generated a Realm file with the following script:

const Realm = require("realm");

const KeyValueSchema = {
    name: "KeyValue",
    primaryKey: "key",
    properties: {
        key: "string",
        value: "int",
    },
};

const config = {
    schema: [KeyValueSchema],
};

let realm = new Realm(config);
for(let i = 0; i < 100; i++) {
    realm.write(() => {
        realm.create(KeyValueSchema.name, { key: `__ ${i} __`, value: i });
    });
}

for(let i = 0; i < 25; i++) {
    realm.write(() => {
        realm.delete(realm.objectForPrimaryKey(KeyValueSchema.name, `__ ${i} __`));
    });
}
realm.close();

The deletions are added to the script to generate some unused free space for the compaction to remove.

The compaction is done by the script:

const Realm = require("realm");

const KeyValueSchema = {
    name: "KeyValue",
    primaryKey: "key",
    properties: {
        key: "string",
        value: "int",
    },
};

const config = {
    schema: [KeyValueSchema],
    shouldCompactOnLaunch: () => true,
};

let realm = new Realm(config);
realm.close();

As the following screenshot demonstrates, the initial file is larger than the compacted line but no extra files are produced:

Screenshot 2022-05-19 at 16 53 51

During compaction, aux. files are created. On Windows, deleting a file is not atomic. Your observation can be explained if your app was terminated while cleaning up after compaction.

@kneth
Copy link
Contributor

kneth commented May 19, 2022

@GitMurf See also realm/realm-core#4111

@kneth
Copy link
Contributor

kneth commented Nov 18, 2022

@GitMurf It will be solved in #5121

@kneth kneth closed this as completed Nov 18, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. Needs-Attention Reporter has responded. Review comment. O-Community T-Bug
Projects
None yet
Development

No branches or pull requests

3 participants