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

Refactor client reset #1003

Merged
merged 6 commits into from
Nov 3, 2022
Merged

Refactor client reset #1003

merged 6 commits into from
Nov 3, 2022

Conversation

blagoev
Copy link
Contributor

@blagoev blagoev commented Nov 2, 2022

refactor client reset

@cla-bot cla-bot bot added the cla: yes label Nov 2, 2022
@blagoev blagoev changed the base branch from master to ds/resync_mode November 2, 2022 23:55
@blagoev blagoev added the no-changelog Used to skip the changelog check label Nov 2, 2022
@blagoev blagoev requested review from desistefanova, nirinchev and nielsenko and removed request for desistefanova, nirinchev and nielsenko November 2, 2022 23:55
@blagoev blagoev changed the title Blagoev/resync mode Refactor client reset Nov 2, 2022
Copy link
Contributor

@nielsenko nielsenko left a comment

Choose a reason for hiding this comment

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

Have a few suggestions in the c++ part, but otherwise fine with me

src/realm_dart_sync.cpp Outdated Show resolved Hide resolved
src/realm_dart_sync.cpp Outdated Show resolved Hide resolved
lib/src/configuration.dart Show resolved Hide resolved
blagoev and others added 2 commits November 3, 2022 10:04
Co-authored-by: Kasper Overgård Nielsen <kasper.nielsen@mongodb.com>
Co-authored-by: Kasper Overgård Nielsen <kasper.nielsen@mongodb.com>
@desistefanova desistefanova mentioned this pull request Nov 3, 2022
lib/src/native/realm_core.dart Show resolved Hide resolved
Comment on lines +90 to +94
RLM_API void realm_dart_invoke_unlock_callback(bool success, void* unlockFunc)
{
auto castFunc = (reinterpret_cast<realm::util::UniqueFunction<void(bool)>*>(unlockFunc));
(*castFunc)(success);
}
Copy link
Member

Choose a reason for hiding this comment

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

I dislike that this is now so specific. There's nothing in the function implementation that indicates that this is somehow related to locking. It's just invoking a function that takes a boolean. The fact that in the client reset flow it'll unlock a lock is an implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exactly a specific function to unlock and the argument is called unlockFunc, hence the otherway around was weird. This makes it more clear what it does and when it should be used.

Copy link
Contributor

@desistefanova desistefanova Nov 3, 2022

Choose a reason for hiding this comment

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

I think we can renamed only the argument name. It has left unchanged after I refactored the function to be general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I very strongly disagree. We don't need and we are not trying to write a generic function that can invoke arbitrary functions that take a boolean in native code. We don't have such use case at hand. We are trying to provide a specific mechanism that when needed, can call Dart and wait for a result synchronously and needs an unlock function to continue. This unlock can be used for any generic case where we need a result from dart through the Scheduler.

Copy link
Member

Choose a reason for hiding this comment

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

I also think we should rename the argument - it's a void* which is then cast to function(bool). Nothing about it deals with unlocking anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikola This function is named after what it does and not how it is used. It invokes a unlock function callback which was passed to a Dart function which accepts a unlock callback argument. This ties the whole concept together. So later when someone needs to do the same it is obvious what needs to be done. create a static dart function which should return a result using that function and continue the operation

Copy link
Member

@nirinchev nirinchev Nov 3, 2022

Choose a reason for hiding this comment

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

Again, the function being passed as an argument is not an unlock function. It's a function(bool).

The fact it's an unlock function is controlled from the outside. So you're naming this function after how it's being consumed.

Copy link
Member

Choose a reason for hiding this comment

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

Consider this extreme example:

void bark(Object dog) {
  final animal = dog as Animal;
  animal.produceSound();
}

final dog = Dog();
dog.bark();

Do you think the bark function is named correctly here? Because this is what is essentially happening with this C function. We accept a generic void* pointer, we cast it to a function(bool), then invoke that function. And we call the argument unlockFunc because we expect that consumers are going to invoke us with a function that unlocks something.

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 don't think we are getting anywhere here. I would like to move away from bike shading the function name. The function is called invoke_unlock_callback and it does what it says and expect a specific argument to be passed in and be used in a specific case. Lets move the discussion to another place where we can gain more value.
The other feedback for deadlocks is more important in this PR. I am trying to handle it.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with moving the discussion elsewhere, but I disagree with changing the function name here. Since both Desi and I believe the old name is better and the name change is not fixing an actual bug, let's keep the original name and we can rename it once we've completed bikeshedding.

Copy link
Member

@nirinchev nirinchev 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 once we revert the function name change :)

lib/src/native/realm_core.dart Outdated Show resolved Hide resolved
lib/src/native/realm_core.dart Outdated Show resolved Hide resolved
@blagoev blagoev merged commit e0ced95 into ds/resync_mode Nov 3, 2022
@blagoev blagoev deleted the blagoev/resync_mode branch November 3, 2022 17:57
@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
cla: yes no-changelog Used to skip the changelog check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants