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

Avoid initial version pinning #1519

Merged
merged 38 commits into from
Oct 31, 2023
Merged

Conversation

clementetb
Copy link
Contributor

@clementetb clementetb commented Sep 13, 2023

During the Realm initialization, we pinned the initial version then it was never released because the VersionTracker was not cleaned up.

In this PR we only track in the user-facing Realm the initial snapshot, and we do so until the notifier or writer has a snapshot available. We keep the version tracker, but now is triggered on each notifier/writer update, to allow flushing of the initial realm snapshot.

@clementetb clementetb marked this pull request as ready for review September 13, 2023 16:05
@clementetb clementetb marked this pull request as draft September 14, 2023 09:54
CHANGELOG.md Show resolved Hide resolved
val writerVersion = writer.version

if (initialRealmReference != null) {
if (initialRealmReference.isClosed()) return initialRealmReference
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we even get here if the Realm is closed? I would assume we had other checks preventing this?

@clementetb clementetb marked this pull request as ready for review September 20, 2023 09:04
Copy link
Contributor

@rorbech rorbech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I feel that this is a bit convoluted. There are some pretty nice clean ups splitting the version tracker's track and clean and how to select the most recent of notifier and writer versions. But couldn't we just rely on existing signalling and these new addition to solve the use case? Happy to jump on a call and discuss.

/**
* Indicates whether the live realm has been initialized or not.
*/
val isInitialized: AtomicBoolean = atomic(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the realmInitializer not good enough for this? Seems to be serving the exact same purpose 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was runnning into some race conditions so I made it atomic, seems it is no longer an issue.

Copy link
Contributor

@rorbech rorbech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some issues with the implementation.

Also noted that the VersionTracker.versions are actually not printing the garbage collecting versions even though they have not been closed 🙈 We should probably change it so that it was distinct if the version was no longer reference and/or closed.

Copy link
Contributor

@rorbech rorbech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but had some minor comments.

public data class VersionInfo(val main: VersionData?, val notifier: VersionData?, val writer: VersionData?) {
val all: Set<VersionId> = setOf(main, notifier, writer).mapNotNull { it?.versions }.flatten().toSet()
val allTracked: Set<VersionId> = setOf(main, notifier, writer).mapNotNull { it?.active }.flatten().toSet()
public data class VersionInfo(val notifier: VersionData?, val writer: VersionData?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we track the initial version anymore? Isn't it as important to know if the initial version is released as it is with the versions tracked by the notifier and writer 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed because I was testing it now in a different test case: initialVersionDereferencedAfterFirstWrite. But it is true that it is better to keep it.

CHANGELOG.md Show resolved Hide resolved
@clementetb clementetb merged commit 161ea05 into releases Oct 31, 2023
2 checks passed
@clementetb clementetb deleted the ct/fix-initialversion-pinned branch October 31, 2023 08:56
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants